Skip to content

Commit c2b8b92

Browse files
committed
Added an install mode.
1 parent cee5de2 commit c2b8b92

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

.github/actions/resolve-api-meta/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ outputs:
1515
API_VERSION:
1616
description: Resolved API version
1717
value: ${{ steps.resolve.outputs.API_VERSION }}
18+
RESOLVED:
19+
description: Whether a commit SHA was resolved (true/false)
20+
value: ${{ steps.resolve.outputs.RESOLVED }}
1821
runs:
1922
using: composite
2023
steps:
@@ -28,6 +31,7 @@ runs:
2831
set -euo pipefail
2932
COMMIT_SHA=""
3033
API_VERSION=""
34+
RESOLVED="false"
3135
if [[ -n "${API_REFRESH_TOKEN:-}" ]]; then
3236
echo "Resolving API commit from https://${API_BASE_URL}/v1/metadata ..."
3337
REPLY_JSON=$(curl --fail --silent --show-error --location "https://${API_BASE_URL}/v1/tokens" \
@@ -49,11 +53,14 @@ runs:
4953
echo "Metadata reply: ${META_JSON}" >&2
5054
exit 1
5155
fi
56+
RESOLVED="true"
5257
echo "Resolved API version: ${API_VERSION} (commit ${COMMIT_SHA})"
5358
else
5459
echo "No token provided; skipping API metadata resolution."
5560
fi
5661
echo "COMMIT_SHA=${COMMIT_SHA}"
5762
echo "API_VERSION=${API_VERSION}"
63+
echo "RESOLVED=${RESOLVED}"
5864
echo "COMMIT_SHA=${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
5965
echo "API_VERSION=${API_VERSION}" >> "$GITHUB_OUTPUT"
66+
echo "RESOLVED=${RESOLVED}" >> "$GITHUB_OUTPUT"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ on:
1616
required: false
1717
default: false
1818
type: boolean
19+
INSTALL_MODE:
20+
description: Which API version to install when run manually. "installed" = install the currently deployed API version; "latest" = install latest from main.
21+
required: false
22+
default: latest
23+
type: string
1924
jobs:
2025
update:
2126
uses: ./.github/workflows/db-update.yml
@@ -27,6 +32,7 @@ jobs:
2732
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
2833
API_BASE_URL: api-dev.mobilitydatabase.org
2934
DRY_RUN: ${{ inputs.DRY_RUN }}
35+
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
3036
secrets:
3137
DB_USER_PASSWORD: ${{ secrets.DEV_POSTGRE_USER_PASSWORD }}
3238
DB_USER_NAME: ${{ secrets.DEV_POSTGRE_USER_NAME }}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
name: Database Update - PROD
33
on:
44
workflow_dispatch:
5+
inputs:
6+
INSTALL_MODE:
7+
description: Which API version to install when run manually. "installed" = install the currently deployed API version; "latest" = install latest from main.
8+
required: false
9+
default: installed
10+
type: string
511
workflow_call:
12+
inputs:
13+
INSTALL_MODE:
14+
description: Which API version to install when called as a reusable workflow (defaults to latest)
15+
required: false
16+
default: latest
17+
type: string
618
repository_dispatch: # Update on mobility-database-catalog repo dispatch
719
types: [ catalog-sources-updated, gbfs-systems-updated ]
820
jobs:
@@ -15,6 +27,7 @@ jobs:
1527
ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
1628
DB_ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
1729
API_BASE_URL: api.mobilitydatabase.org
30+
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
1831
secrets:
1932
DB_USER_PASSWORD: ${{ secrets.PROD_POSTGRE_USER_PASSWORD }}
2033
DB_USER_NAME: ${{ secrets.PROD_POSTGRE_USER_NAME }}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ on:
88
required: false
99
default: false
1010
type: boolean
11+
INSTALL_MODE:
12+
description: Which API version to install when run manually. "installed" = install the currently deployed API version; "latest" = install latest from main.
13+
required: false
14+
default: installed
15+
type: string
1116
workflow_call:
17+
inputs:
18+
INSTALL_MODE:
19+
description: Which API version to install when called as a reusable workflow (defaults to latest)
20+
required: false
21+
default: latest
22+
type: string
1223

1324
repository_dispatch: # Update on mobility-database-catalog repo dispatch
1425
types: [ catalog-sources-updated, gbfs-systems-updated ]
@@ -24,6 +35,7 @@ jobs:
2435
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
2536
API_BASE_URL: api-qa.mobilitydatabase.org
2637
DRY_RUN: ${{ inputs.DRY_RUN }}
38+
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
2739
secrets:
2840
DB_USER_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
2941
DB_USER_NAME: ${{ secrets.QA_POSTGRE_USER_NAME }}

.github/workflows/db-update.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ on:
7575
required: false
7676
default: api.mobilitydatabase.org
7777
type: string
78+
INSTALL_MODE:
79+
description: Which API version to install when run manually. "installed" = install the currently deployed API version; "latest" = install latest from main.
80+
required: false
81+
default: latest
82+
type: string
7883
DRY_RUN:
7984
description: Skip applying schema and content updates
8085
required: false
@@ -89,10 +94,12 @@ jobs:
8994
resolve-api-meta:
9095
name: 'Resolve API commit/version'
9196
runs-on: ubuntu-latest
92-
if: ${{ contains('repository_dispatch,workflow_dispatch', github.event_name) && inputs.API_BASE_URL != '' }}
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.
9399
outputs:
94100
COMMIT_SHA: ${{ steps.resolve.outputs.COMMIT_SHA }}
95101
API_VERSION: ${{ steps.resolve.outputs.API_VERSION }}
102+
CHECKOUT_REF: ${{ steps.decide_ref.outputs.CHECKOUT_REF }}
96103
steps:
97104
- name: Checkout repo (for scripts and local action)
98105
uses: actions/checkout@v4
@@ -103,6 +110,34 @@ jobs:
103110
with:
104111
api_base_url: ${{ inputs.API_BASE_URL }}
105112
api_refresh_token: ${{ secrets.API_TEST_REFRESH_TOKEN }}
113+
- name: Determine install target ref
114+
id: decide_ref
115+
run: |
116+
set -euo pipefail
117+
EVENT='${{ github.event_name }}'
118+
INSTALL_MODE='${{ inputs.INSTALL_MODE }}'
119+
RESOLVED='${{ steps.resolve.outputs.RESOLVED }}'
120+
COMMIT_SHA='${{ steps.resolve.outputs.COMMIT_SHA }}'
121+
echo "event=$EVENT, install_mode=$INSTALL_MODE, resolved=$RESOLVED, commit=$COMMIT_SHA"
122+
if [ "$EVENT" = "repository_dispatch" ]; then
123+
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
124+
echo "ERROR: repository_dispatch requires a resolved API commit but none was found" >&2
125+
exit 1
126+
fi
127+
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
128+
elif [ "$EVENT" = "workflow_dispatch" ]; then
129+
if [ "$INSTALL_MODE" = "installed" ]; then
130+
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
131+
echo "ERROR: manual install requested 'installed' but no resolved commit available" >&2
132+
exit 1
133+
fi
134+
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
135+
else
136+
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
137+
fi
138+
else
139+
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
140+
fi
106141
107142
db-schema-update:
108143
name: 'Database Schema Update'
@@ -111,17 +146,12 @@ jobs:
111146
needs: [resolve-api-meta]
112147
if: ${{ always() }}
113148
steps:
114-
- name: Checkout code at API commit
115-
if: ${{ needs.resolve-api-meta.result == 'success' && needs.resolve-api-meta.outputs.COMMIT_SHA != '' }}
149+
- name: Checkout repo (shallow)
116150
uses: actions/checkout@v4
117151
with:
118-
ref: ${{ needs.resolve-api-meta.outputs.COMMIT_SHA }}
152+
ref: ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
119153
fetch-depth: 0
120154

121-
- name: Checkout code (default)
122-
if: ${{ needs.resolve-api-meta.result != 'success' || needs.resolve-api-meta.outputs.COMMIT_SHA == '' }}
123-
uses: actions/checkout@v4
124-
125155
- name: Authenticate to Google Cloud QA/PROD
126156
uses: google-github-actions/auth@v2
127157
with:
@@ -184,17 +214,12 @@ jobs:
184214
needs: [resolve-api-meta, db-schema-update]
185215
if: ${{ always() && contains('repository_dispatch,workflow_dispatch', github.event_name) }}
186216
steps:
187-
- name: Checkout code at API commit
188-
if: ${{ needs.resolve-api-meta.result == 'success' && needs.resolve-api-meta.outputs.COMMIT_SHA != '' }}
217+
- name: Checkout repo (shallow)
189218
uses: actions/checkout@v4
190219
with:
191-
ref: ${{ needs.resolve-api-meta.outputs.COMMIT_SHA }}
220+
ref: ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
192221
fetch-depth: 0
193222

194-
- name: Checkout code (default)
195-
if: ${{ needs.resolve-api-meta.result != 'success' || needs.resolve-api-meta.outputs.COMMIT_SHA == '' }}
196-
uses: actions/checkout@v4
197-
198223
- name: Setup python
199224
uses: actions/setup-python@v5
200225
with:

0 commit comments

Comments
 (0)