-
Notifications
You must be signed in to change notification settings - Fork 10
183 lines (180 loc) · 6.77 KB
/
push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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"