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
7078
7179env :
7280 python_version : ' 3.11'
7381 liquibase_version : ' 4.33.0'
7482
7583jobs :
84+ resolve-api-meta :
85+ name : ' Resolve API commit/version'
86+ runs-on : ubuntu-latest
87+ if : ${{ github.event_name == 'repository_dispatch' && inputs.API_BASE_URL != '' && secrets.API_TEST_REFRESH_TOKEN != '' }}
88+ outputs :
89+ COMMIT_SHA : ${{ steps.resolve.outputs.COMMIT_SHA }}
90+ API_VERSION : ${{ steps.resolve.outputs.API_VERSION }}
91+ steps :
92+ - name : Checkout repo (for scripts)
93+ uses : actions/checkout@v4
94+ with :
95+ fetch-depth : 1
96+ sparse-checkout : |
97+ scripts
98+ sparse-checkout-cone : true
99+ - name : Resolve API commit/version
100+ 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
107+
76108 db-schema-update :
77109 name : ' Database Schema Update'
78110 permissions : write-all
79111 runs-on : ubuntu-latest
112+ needs : [resolve-api-meta]
113+ if : ${{ always() }}
80114 steps :
81- - name : Checkout code
115+ - name : Checkout code at API commit
116+ if : ${{ needs.resolve-api-meta.result == 'success' && needs.resolve-api-meta.outputs.COMMIT_SHA != '' }}
117+ uses : actions/checkout@v4
118+ with :
119+ ref : ${{ needs.resolve-api-meta.outputs.COMMIT_SHA }}
120+ fetch-depth : 0
121+
122+ - name : Checkout code (default)
123+ if : ${{ needs.resolve-api-meta.result != 'success' || needs.resolve-api-meta.outputs.COMMIT_SHA == '' }}
82124 uses : actions/checkout@v4
83125
84126 - name : Authenticate to Google Cloud QA/PROD
@@ -139,10 +181,18 @@ jobs:
139181 name : ' Database Content Update'
140182 permissions : write-all
141183 runs-on : ubuntu-latest
142- needs : db-schema-update
143- if : ${{ github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' }}
184+ needs : [resolve-api-meta, db-schema-update]
185+ if : ${{ always() && ( github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch') }}
144186 steps :
145- - name : Checkout code
187+ - name : Checkout code at API commit
188+ if : ${{ needs.resolve-api-meta.result == 'success' && needs.resolve-api-meta.outputs.COMMIT_SHA != '' }}
189+ uses : actions/checkout@v4
190+ with :
191+ ref : ${{ needs.resolve-api-meta.outputs.COMMIT_SHA }}
192+ fetch-depth : 0
193+
194+ - name : Checkout code (default)
195+ if : ${{ needs.resolve-api-meta.result != 'success' || needs.resolve-api-meta.outputs.COMMIT_SHA == '' }}
146196 uses : actions/checkout@v4
147197
148198 - name : Setup python
@@ -159,6 +209,8 @@ jobs:
159209 uses : google-github-actions/setup-gcloud@v2
160210
161211 - name : Update .env file
212+ env :
213+ API_VERSION : ${{ needs.resolve-api-meta.outputs.API_VERSION }}
162214 run : |
163215 echo "PGUSER=${{ secrets.DB_USER_NAME }}" > config/.env.local
164216 echo "POSTGRES_USER=${{ secrets.DB_USER_NAME }}" >> config/.env.local
@@ -168,6 +220,7 @@ jobs:
168220 echo "POSTGRES_PORT=5432" >> config/.env.local
169221 echo "POSTGRES_HOST=localhost" >> config/.env.local
170222 echo "ENV=${{ inputs.ENVIRONMENT }}" >> config/.env.local
223+ if [[ -n "${API_VERSION}" ]]; then echo "API_VERSION=${API_VERSION}" >> config/.env.local; fi
171224 cat config/.env.local
172225
173226 - name : Load secrets from 1Password
@@ -283,6 +336,3 @@ jobs:
283336 echo "Secret $SECRET_NAME does not exist in project $PROJECT_ID, creating..."
284337 echo -n "$SECRET_VALUE" | gcloud secrets create $SECRET_NAME --data-file=- --replication-policy="automatic" --project=$PROJECT_ID
285338 fi
286-
287-
288-
0 commit comments