4646 POSTGRE_SQL_INSTANCE_NAME :
4747 description : PostgreSQL Instance Name
4848 required : true
49+ API_TEST_REFRESH_TOKEN :
50+ description : API refresh token used to resolve deployed API commit (used on repository_dispatch)
51+ required : false
4952 inputs :
5053 PROJECT_ID :
5154 description : GCP Project ID
6770 description : GCP region
6871 required : true
6972 type : string
73+ API_BASE_URL :
74+ description : Base URL host for the API used to resolve version/commit (e.g. api-dev.mobilitydatabase.org)
75+ required : false
76+ default : api.mobilitydatabase.org
77+ type : string
78+ INSTALL_LATEST :
79+ description : Install the latest (main) API version when true; when false keep the currently deployed version.
80+ required : false
81+ default : false
82+ type : boolean
83+ DRY_RUN :
84+ description : Skip applying schema and content updates
85+ required : false
86+ default : false
87+ type : boolean
7088
7189env :
7290 python_version : ' 3.11'
7391 liquibase_version : ' 4.33.0'
7492
7593jobs :
94+ resolve-api-meta :
95+ name : ' Resolve API commit/version'
96+ runs-on : ubuntu-latest
97+ # Run this job for all triggers; the action itself will skip resolution when API_BASE_URL or token is not provided.
98+ # Keeping it unconditional ensures CHECKOUT_REF is always set (defaults to 'main') for downstream jobs.
99+ outputs :
100+ # Use resolved commit when available; otherwise default to 'main'.
101+ CHECKOUT_REF : ${{ steps.resolve.outputs.COMMIT_SHA != '' && steps.resolve.outputs.COMMIT_SHA || 'main' }}
102+ steps :
103+ - name : Checkout repo (for scripts and local action)
104+ uses : actions/checkout@v4
105+ - name : Resolve API commit/version
106+ id : resolve
107+ if : ${{ inputs.INSTALL_LATEST == false }}
108+ uses : ./.github/actions/resolve-api-meta
109+ with :
110+ api_base_url : ${{ inputs.API_BASE_URL }}
111+ api_refresh_token : ${{ secrets.API_TEST_REFRESH_TOKEN }}
112+
76113 db-schema-update :
77114 name : ' Database Schema Update'
78115 permissions : write-all
79116 runs-on : ubuntu-latest
117+ needs : [resolve-api-meta]
118+ # Run the schema update when the resolved checkout target is 'main' (install latest/main).
119+ # This covers both explicit INSTALL_LATEST runs and cases where resolution failed and CHECKOUT_REF fell back to 'main'.
120+ if : ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF == 'main' }}
80121 steps :
81- - name : Checkout code
122+ - name : Checkout repo
82123 uses : actions/checkout@v4
124+ with :
125+ # Use the job-level CHECKOUT_REF (already resolves to COMMIT_SHA or 'main')
126+ ref : ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
127+ fetch-depth : 0
83128
84129 - name : Authenticate to Google Cloud QA/PROD
85130 uses : google-github-actions/auth@v2
@@ -126,6 +171,7 @@ jobs:
126171 liquibase --version
127172
128173 - name : Run Liquibase
174+ if : ${{ !inputs.DRY_RUN }}
129175 working-directory : ${{ github.workspace }}/liquibase
130176 run : |
131177 export LIQUIBASE_COMMAND_CHANGELOG_FILE="changelog.xml"
@@ -139,11 +185,15 @@ jobs:
139185 name : ' Database Content Update'
140186 permissions : write-all
141187 runs-on : ubuntu-latest
142- needs : db-schema-update
143- if : ${{ github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' }}
188+ needs : [resolve-api-meta, db-schema-update]
189+ if : ${{ always() }}
144190 steps :
145- - name : Checkout code
191+ - name : Checkout repo
146192 uses : actions/checkout@v4
193+ with :
194+ # Use the job-level CHECKOUT_REF (already resolves to COMMIT_SHA or 'main')
195+ ref : ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
196+ fetch-depth : 0
147197
148198 - name : Setup python
149199 uses : actions/setup-python@v5
@@ -212,11 +262,11 @@ jobs:
212262 run : echo "PATH=$(realpath sources.csv)" >> $GITHUB_OUTPUT
213263
214264 - name : GTFS - Update Database Content
215- if : ${{ env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual' }}
265+ if : ${{ !inputs.DRY_RUN && ( env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
216266 run : scripts/populate-db.sh ${{ steps.getpath.outputs.PATH }} > populate.log
217267
218268 - name : GTFS - Upload log file for verification
219- if : ${{ always() && (env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
269+ if : ${{ always() && !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gtfs' || env.UPDATE_TYPE == 'manual') }}
220270 uses : actions/upload-artifact@v4
221271 with :
222272 name : populate-${{ inputs.ENVIRONMENT }}.log
@@ -232,11 +282,11 @@ jobs:
232282 run : echo "PATH=$(realpath systems.csv)" >> $GITHUB_OUTPUT
233283
234284 - name : GBFS - Update Database Content
235- if : ${{ env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual' }}
285+ if : ${{ !inputs.DRY_RUN && ( env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
236286 run : scripts/populate-db.sh ${{ steps.getsyspath.outputs.PATH }} gbfs >> populate-gbfs.log
237287
238288 - name : GBFS - Upload log file for verification
239- if : ${{ always() && (env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
289+ if : ${{ always() && !inputs.DRY_RUN && (env.UPDATE_TYPE == 'gbfs' || env.UPDATE_TYPE == 'manual') }}
240290 uses : actions/upload-artifact@v4
241291 with :
242292 name : populate-gbfs-${{ inputs.ENVIRONMENT }}.log
@@ -245,7 +295,7 @@ jobs:
245295
246296 update-gcp-secret :
247297 name : Update GCP Secrets
248- if : ${{ github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' }}
298+ if : ${{ contains( 'repository_dispatch,workflow_dispatch', github.event_name) && !inputs.DRY_RUN }}
249299 runs-on : ubuntu-latest
250300 steps :
251301 - name : Authenticate to Google Cloud
@@ -283,6 +333,3 @@ jobs:
283333 echo "Secret $SECRET_NAME does not exist in project $PROJECT_ID, creating..."
284334 echo -n "$SECRET_VALUE" | gcloud secrets create $SECRET_NAME --data-file=- --replication-policy="automatic" --project=$PROJECT_ID
285335 fi
286-
287-
288-
0 commit comments