Merge pull request #135 from lahirulakruwan/main #361
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests and GraphQL Client Generation | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: avinyafoundation/global-data-db | |
DOCKERFILE_FOLDER: ./db | |
on: | |
push: | |
branches: | |
- "*" | |
- "!gh-pages" | |
jobs: | |
push-db-container: | |
name: Database Setup | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
if: ${{ !env.act }} # Only run on GitHub Actions | |
- name: Log in to the Container registry | |
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 | |
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 | |
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 | |
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/avinyafoundation/global-data-db:${{ github.ref_name }} | |
env: | |
MYSQL_ROOT_PASSWORD: test | |
ports: | |
- 3306:3306 | |
steps: | |
# - name: Checkout repository | |
# if: ${{ !env.act }} # Only run on GitHub Actions | |
# uses: actions/checkout@v3 | |
# - name: Wait for database container to start | |
# run: sleep 30s | |
# shell: bash | |
# - name: Get service container logs | |
# run: docker logs -n 100 "${{ job.services.mysql.id }}" | |
# - name: Verify tables exist | |
# if: ${{ !env.ACT }} | |
# run: echo "USE avinya_db; SHOW TABLES;" | mysql --host=$HOST --port=$PORT --user=$USER | |
# env: | |
# HOST: mysql | |
# PORT: 3306 | |
# USER: root | |
# - name: Run schema on database | |
# if: ${{ !env.act }} # Only run on GitHub Actions | |
# run: cat ./schema/*.sql | mysql --host=$HOST --port=$PORT --user=$USER | |
# env: | |
# HOST: mysql | |
# PORT: 3306 | |
# USER: root | |
# 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 | |
# env: | |
# HOST: mysql | |
# PORT: 3306 | |
# USER: root | |
# working-directory: db | |
- name: Disable Test | |
run: | | |
echo "This is currently disabled due to a bug. See: #18" | |
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/avinyafoundation/global-data-db:${{ github.ref_name }} . | |
source api/Config.toml | |
docker run -d -e MYSQL_ROOT_PASSWORD=$PASSWORD -p 3306:3306 ghcr.io/avinyafoundation/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 | |
needs: push-db-container | |
services: | |
mysql: | |
image: ghcr.io/avinyafoundation/global-data-db:${{ github.ref_name }} | |
env: | |
MYSQL_ROOT_PASSWORD: test | |
ports: | |
- 3306:3306 | |
steps: | |
- 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 | |
if: ${{ env.ACT }} | |
run: | | |
docker build -f ${{ env.DOCKERFILE_FOLDER }}/Dockerfile -t ghcr.io/avinyafoundation/global-data-db:${{ github.ref_name }} . | |
source api/Config.toml | |
docker run -d -e MYSQL_ROOT_PASSWORD=$PASSWORD -p 3306:3306 ghcr.io/avinyafoundation/global-data-db:${{ github.ref_name }} | |
- name: (Local Only) Test ballerina project | |
if: ${{ env.ACT }} | |
uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4 | |
with: | |
args: test | |
env: | |
WORKING_DIR: api | |
- name: Test ballerina project | |
if: ${{ !env.ACT }} | |
uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4 | |
with: | |
args: test | |
env: | |
WORKING_DIR: api | |
generate-graphql-client: | |
name: Generate GraphQL Client | |
needs: api-test | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Generate GraphQL Client | |
uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4 | |
with: | |
args: graphql -i graphql.config.yaml -o ../../client/ | |
env: | |
WORKING_DIR: api/schema | |
- name: Display changes in generated client | |
run: | | |
git add . --force | |
git diff HEAD | |
- name: Commit sample artifacts to Pull Request | |
uses: EndBug/add-and-commit@v9 # See: https://github.com/marketplace/actions/add-commit | |
with: | |
add: "client --force" | |
default_author: github_actions | |
message: "Commit generated GraphQL client" |