Skip to content

Commit

Permalink
Add database idempotence test
Browse files Browse the repository at this point in the history
- Add workflow to build gh-pages
  • Loading branch information
rukmal committed Sep 28, 2022
1 parent 3678180 commit 1e6283c
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 17 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Simple workflow for deploying static content to GitHub Pages
name: Build and publish GitHub Pages branch

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
build-gh-pages:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
if: ${{ !env.ACT }}
uses: actions/checkout@v3
with:
ref: main
- name: Build API documentation with Ballerina
if: ${{ !env.ACT }}
uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4
with:
args: doc -o ../docs
env:
WORKING_DIR: api
- name: Create GitHub Pages branch and add API documentation
if: ${{ !env.ACT }}
run: |
git checkout -b gh-pages
mkdir api_doc/
sudo mv $(find . -name index.html -exec dirname {} \;)/* ./api_doc/
sudo rm -r api client db
# See: https://github.com/pages-themes/cayman#usage
printf "remote_theme: pages-themes/cayman@v0.2.0\nplugins:\n - jekyll-remote-theme # add this line to the plugins list if you already have one\n" > _config.yml
- name: Commit to repo
if: ${{ !env.ACT }}
uses: EndBug/add-and-commit@v9 # See: https://github.com/marketplace/actions/add-commit
with:
add: ". --force"
default_author: github_actions
message: "[GitHub Actions] Commit generated pages artifacts"
push: origin gh-pages --force
86 changes: 76 additions & 10 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ env:
IMAGE_NAME: avinya-foundation/global-data-db
DOCKERFILE_FOLDER: ./db

on: push
on:
push:
branches:
- "*"
- "!gh-pages"

jobs:
push-db-container:
Expand All @@ -16,40 +20,104 @@ jobs:
packages: write
steps:
- name: Checkout repository
if: ${{ !env.ACT }} # Only run on GitHub Actions
uses: actions/checkout@v3
if: ${{ !env.act }} # Only run on GitHub Actions
- name: Log in to the Container registry
if: ${{ !env.ACT }} # Only run on GitHub Actions
id: docker-registry-login
if: ${{ !env.act }} # Only run on GitHub Actions
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
if: ${{ !env.ACT }} # Only run on GitHub Actions
id: meta
if: ${{ !env.act }} # Only run on GitHub Actions
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Setting up Docker Buildx with docker-container driver is required
# at the moment to be able to use a subdirectory with Git context
- name: Set up Docker Buildx
if: ${{ !env.ACT }} # Only run on GitHub Actions
id: buildx
if: ${{ !env.act }} # Only run on GitHub Actions
uses: docker/setup-buildx-action@v2
with:
install: true # See: https://github.com/docker/setup-buildx-action#install-by-default
- name: Build and push Docker image to GitHub container registry
if: ${{ !env.ACT }} # Only run on GitHub Actions
if: ${{ !env.act }} # Only run on GitHub Actions
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ${{ env.DOCKERFILE_FOLDER }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

db-idempotence-test:
name: Database Idempotence Test
runs-on: ubuntu-22.04
needs: push-db-container
services:
mysql:
image: ghcr.io/avinya-foundation/global-data-db:${{ github.ref_name }}
env:
MYSQL_ROOT_PASSWORD: test
ports:
- 4306:3306
steps:
- name: Checkout repository
if: ${{ !env.act }} # Only run on GitHub Actions
uses: actions/checkout@v3
- name: Verify tables exist
if: ${{ !env.ACT }}
run: echo "USE avinya_db; SHOW TABLES;" | mysql --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD
env:
HOST: "mysql"
PORT: 4306
USER: root
PASSWORD: test
- name: Run schema on database
if: ${{ !env.act }} # Only run on GitHub Actions
run: cat ./schema/*.sql | mysql --host=$HOST --port=$PORT --user=$USER --password=$TEST
env:
HOST: "mysql"
PORT: 4306
USER: root
PASSWORD: test
working-directory: db
- name: Run schema on database again
if: ${{ !env.act }} # Only run on GitHub Actions
run: cat ./schema/*.sql | mysql --host=$HOST --port=$PORT --user=$USER --password=$TEST
env:
HOST: "mysql"
PORT: 4306
USER: root
PASSWORD: test
working-directory: db
db-idempotence-local-test:
name: (Local Only) Database Idempotence Test
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
if: ${{ env.ACT }}
uses: actions/checkout@v3
- name: (Local Only) Start database in Docker container
if: ${{ env.ACT }}
run: |
docker build -f ${{ env.DOCKERFILE_FOLDER }}/Dockerfile -t ghcr.io/avinya-foundation/global-data-db:${{ github.ref_name }} .
source api/Config.toml
docker run -d -e MYSQL_ROOT_PASSWORD=$PASSWORD -p 3306:3306 ghcr.io/avinya-foundation/global-data-db:${{ github.ref_name }}
- name: (Local Only) Database idempotence test
if: ${{ env.ACT }}
run: |
apt update
apt -y install libssl-dev unixodbc-dev libmysqlclient-dev mariadb-client
cat ./schema/*.sql | mysql --host=localhost --port=3306 --user=root --password=test
cat ./schema/*.sql | mysql --host=localhost --port=3306 --user=root --password=test
working-directory: db
- name: (Local Only) Verify tables exist
if: ${{ env.ACT }}
run: echo "USE avinya_db; SHOW TABLES;" | mysql --host=localhost --port=3306 --user=root --password=test
api-test:
name: GraphQL API Tests
runs-on: ubuntu-22.04
Expand All @@ -62,7 +130,7 @@ jobs:
ports:
- 3306:3306
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v3
# Install local deps if this action is being run locally with act
- name: (Local Only) Start database in Docker container
Expand Down Expand Up @@ -91,10 +159,8 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
if: ${{ !env.ACT }} # Only run on GitHub Actions
uses: actions/checkout@v3
- name: Generate GraphQL Client
if: ${{ !env.ACT }}
uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4
with:
args: graphql -i graphql.config.yaml -o ../../client/
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Local Development
## Avinya Foundation Global Data Service

The Avinya Foundation's Global Data Service underlies the Avinya Foundation technology stack, and provides a universal interface to data across all applications in the organization.

## Component Documentation

- [GraphQL API Documentation](https://avinya-foundation.github.io/global-data/api_doc/)

### Notes for Running Tests

Expand Down
5 changes: 5 additions & 0 deletions api/Module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Global Data Service GraphQL API

Ballerina Documentation for the Avinya Foundation's Global Data Service GraphQL API.

To return to the main documentation page, [click here](https://avinya-foundation.github.io/global-data/).
5 changes: 0 additions & 5 deletions db/schema/3-avinya_types.sql → db/schema/2-avinya_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ CREATE TABLE IF NOT EXISTS avinya_type (
),
level INT
);

ALTER TABLE organization
ADD COLUMN organization.avinya_type INT NOT NULL;
ALTER TABLE organization
ADD FOREIGN KEY (organization.avinya_type) REFERENCES avinya_db.avinya_type(id);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ CREATE TABLE IF NOT EXISTS organization (
name_si VARCHAR(255),
phone INT,
address_id INT NOT NULL,
FOREIGN KEY (address_id) REFERENCES address(id)
avinya_type INT NOT NULL,
FOREIGN KEY (address_id) REFERENCES address(id),
FOREIGN KEY (avinya_type) REFERENCES avinya_type(id)
);

-- Parent/Child Organization relationship
Expand Down

0 comments on commit 1e6283c

Please sign in to comment.