Skip to content

Commit f62dc88

Browse files
committed
Added a DRY_RUN parameter to db-update.yml to help with testing.
1 parent 843f782 commit f62dc88

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

.github/workflows/db-update-qa.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
name: Database Update - QA
33
on:
44
workflow_dispatch:
5+
inputs:
6+
DRY_RUN:
7+
description: Skip applying schema and content updates
8+
required: false
9+
default: false
10+
type: boolean
511
workflow_call:
12+
613
repository_dispatch: # Update on mobility-database-catalog repo dispatch
714
types: [ catalog-sources-updated, gbfs-systems-updated ]
815

@@ -16,6 +23,7 @@ jobs:
1623
ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
1724
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
1825
API_BASE_URL: api-qa.mobilitydatabase.org
26+
DRY_RUN: ${{ inputs.DRY_RUN }}
1927
secrets:
2028
DB_USER_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
2129
DB_USER_NAME: ${{ secrets.QA_POSTGRE_USER_NAME }}

.github/workflows/db-update.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,35 +75,35 @@ on:
7575
required: false
7676
default: api.mobilitydatabase.org
7777
type: string
78+
DRY_RUN:
79+
description: Skip applying schema and content updates
80+
required: false
81+
default: false
82+
type: boolean
7883

7984
env:
8085
python_version: '3.11'
8186
liquibase_version: '4.33.0'
87+
# True when this run was triggered by a repository_dispatch or a manual workflow_dispatch
88+
IS_DISPATCH: ${{ github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' }}
8289

8390
jobs:
8491
resolve-api-meta:
8592
name: 'Resolve API commit/version'
8693
runs-on: ubuntu-latest
87-
if: ${{ github.event_name == 'repository_dispatch' && inputs.API_BASE_URL != '' && secrets.API_TEST_REFRESH_TOKEN != '' }}
94+
if: ${{ env.IS_DISPATCH == 'true' && inputs.API_BASE_URL != '' && secrets.API_TEST_REFRESH_TOKEN != '' }}
8895
outputs:
8996
COMMIT_SHA: ${{ steps.resolve.outputs.COMMIT_SHA }}
9097
API_VERSION: ${{ steps.resolve.outputs.API_VERSION }}
9198
steps:
92-
- name: Checkout repo (for scripts)
99+
- name: Checkout repo (for scripts and local action)
93100
uses: actions/checkout@v4
94-
with:
95-
fetch-depth: 1
96-
sparse-checkout: |
97-
scripts
98-
sparse-checkout-cone: true
99101
- name: Resolve API commit/version
100102
id: resolve
101-
env:
102-
API_BASE_URL: ${{ inputs.API_BASE_URL }}
103-
API_REFRESH_TOKEN: ${{ secrets.API_TEST_REFRESH_TOKEN }}
104-
EVENT: ${{ github.event_name }}
105-
run: |
106-
bash scripts/resolve_api_meta.sh
103+
uses: ./.github/actions/resolve-api-meta
104+
with:
105+
api_base_url: ${{ inputs.API_BASE_URL }}
106+
api_refresh_token: ${{ secrets.API_TEST_REFRESH_TOKEN }}
107107

108108
db-schema-update:
109109
name: 'Database Schema Update'
@@ -168,6 +168,7 @@ jobs:
168168
liquibase --version
169169
170170
- name: Run Liquibase
171+
if: ${{ !inputs.DRY_RUN }}
171172
working-directory: ${{ github.workspace }}/liquibase
172173
run: |
173174
export LIQUIBASE_COMMAND_CHANGELOG_FILE="changelog.xml"
@@ -182,7 +183,7 @@ jobs:
182183
permissions: write-all
183184
runs-on: ubuntu-latest
184185
needs: [resolve-api-meta, db-schema-update]
185-
if: ${{ always() && (github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch') }}
186+
if: ${{ always() && env.IS_DISPATCH == 'true' }}
186187
steps:
187188
- name: Checkout code at API commit
188189
if: ${{ needs.resolve-api-meta.result == 'success' && needs.resolve-api-meta.outputs.COMMIT_SHA != '' }}
@@ -265,11 +266,11 @@ jobs:
265266
run: echo "PATH=$(realpath sources.csv)" >> $GITHUB_OUTPUT
266267

267268
- name: GTFS - Update Database Content
268-
if: ${{ env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual' }}
269+
if: ${{ !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
269270
run: scripts/populate-db.sh ${{ steps.getpath.outputs.PATH }} > populate.log
270271

271272
- name: GTFS - Upload log file for verification
272-
if: ${{ always() && (env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
273+
if: ${{ always() && !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
273274
uses: actions/upload-artifact@v4
274275
with:
275276
name: populate-${{ inputs.ENVIRONMENT }}.log
@@ -285,11 +286,11 @@ jobs:
285286
run: echo "PATH=$(realpath systems.csv)" >> $GITHUB_OUTPUT
286287

287288
- name: GBFS - Update Database Content
288-
if: ${{ env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual' }}
289+
if: ${{ !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
289290
run: scripts/populate-db.sh ${{ steps.getsyspath.outputs.PATH }} gbfs >> populate-gbfs.log
290291

291292
- name: GBFS - Upload log file for verification
292-
if: ${{ always() && (env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
293+
if: ${{ always() && !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
293294
uses: actions/upload-artifact@v4
294295
with:
295296
name: populate-gbfs-${{ inputs.ENVIRONMENT }}.log
@@ -298,7 +299,7 @@ jobs:
298299

299300
update-gcp-secret:
300301
name: Update GCP Secrets
301-
if: ${{ github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' }}
302+
if: ${{ env.IS_DISPATCH == 'true' && !inputs.DRY_RUN }}
302303
runs-on: ubuntu-latest
303304
steps:
304305
- name: Authenticate to Google Cloud
@@ -336,3 +337,4 @@ jobs:
336337
echo "Secret $SECRET_NAME does not exist in project $PROJECT_ID, creating..."
337338
echo -n "$SECRET_VALUE" | gcloud secrets create $SECRET_NAME --data-file=- --replication-policy="automatic" --project=$PROJECT_ID
338339
fi
340+

0 commit comments

Comments
 (0)