Skip to content

Commit 364cf7c

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

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +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.
19+
INSTALL_CURRENT:
20+
description: Install the currently deployed API version when true; when false install main (latest).
2121
required: false
22-
default: latest
23-
type: string
22+
default: true
23+
type: boolean
2424
jobs:
2525
update:
2626
uses: ./.github/workflows/db-update.yml
@@ -31,8 +31,8 @@ jobs:
3131
ENVIRONMENT: ${{ vars.DEV_MOBILITY_FEEDS_ENVIRONMENT }}
3232
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
3333
API_BASE_URL: api-dev.mobilitydatabase.org
34-
DRY_RUN: ${{ inputs.DRY_RUN }}
35-
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
34+
DRY_RUN: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.DRY_RUN || 'false') || inputs.DRY_RUN || 'false' }}
35+
INSTALL_CURRENT: ${{ github.event_name == 'repository_dispatch' && 'true' || inputs.INSTALL_CURRENT || 'true' }}
3636
secrets:
3737
DB_USER_PASSWORD: ${{ secrets.DEV_POSTGRE_USER_PASSWORD }}
3838
DB_USER_NAME: ${{ secrets.DEV_POSTGRE_USER_NAME }}

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# Update the Mobility Database Schema
22
name: Database Update - PROD
33
on:
4-
workflow_dispatch:
4+
workflow_dispatch: # Manual trigger
55
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.
6+
DRY_RUN:
7+
description: Skip applying schema and content updates
88
required: false
9-
default: installed
10-
type: string
11-
workflow_call:
12-
inputs:
13-
INSTALL_MODE:
14-
description: Which API version to install when called as a reusable workflow (defaults to latest)
9+
default: false
10+
type: boolean
11+
INSTALL_CURRENT:
12+
description: Install the currently deployed API version when true; when false install main (latest).
1513
required: false
16-
default: latest
17-
type: string
14+
default: true
15+
type: boolean
16+
workflow_call: []
1817
repository_dispatch: # Update on mobility-database-catalog repo dispatch
1918
types: [ catalog-sources-updated, gbfs-systems-updated ]
2019
jobs:
@@ -27,7 +26,14 @@ jobs:
2726
ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
2827
DB_ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
2928
API_BASE_URL: api.mobilitydatabase.org
30-
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
29+
DRY_RUN: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.DRY_RUN || 'false') || inputs.DRY_RUN || 'false' }}
30+
# Algorithm for INSTALL_CURRENT (forwarded to db-update.yml):
31+
# - If the trigger is repository_dispatch, force 'true' because we want to re-install the same repo-dispatch runs must
32+
# install the currently deployed API version (fail if unknown).
33+
# - If the trigger is from another workflow (workflow_call), currently from release.yml, force 'false'
34+
# because it's a release, we want the latest not the current.
35+
# - Otherwise (manual workflow_dispatch) use the wrapper's inputs.INSTALL_CURRENT.
36+
INSTALL_CURRENT: ${{ github.event_name == 'repository_dispatch' && 'true' || github.event_name == 'workflow_call' && 'false' || inputs.INSTALL_CURRENT || 'false' }}
3137
secrets:
3238
DB_USER_PASSWORD: ${{ secrets.PROD_POSTGRE_USER_PASSWORD }}
3339
DB_USER_NAME: ${{ secrets.PROD_POSTGRE_USER_NAME }}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ 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.
11+
INSTALL_CURRENT:
12+
description: Install the currently deployed API version when true; when false install main (latest).
1313
required: false
14-
default: installed
15-
type: string
16-
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
14+
default: false
15+
type: boolean
16+
workflow_call: []
2317

2418
repository_dispatch: # Update on mobility-database-catalog repo dispatch
2519
types: [ catalog-sources-updated, gbfs-systems-updated ]
@@ -34,8 +28,8 @@ jobs:
3428
ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
3529
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
3630
API_BASE_URL: api-qa.mobilitydatabase.org
37-
DRY_RUN: ${{ inputs.DRY_RUN }}
38-
INSTALL_MODE: ${{ inputs.INSTALL_MODE }}
31+
DRY_RUN: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.DRY_RUN || 'false') || inputs.DRY_RUN || 'false' }}
32+
INSTALL_CURRENT: ${{ github.event_name == 'repository_dispatch' && 'true' || github.event_name == 'workflow_call' && 'false' || inputs.INSTALL_CURRENT || 'false' }}
3933
secrets:
4034
DB_USER_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
4135
DB_USER_NAME: ${{ secrets.QA_POSTGRE_USER_NAME }}

.github/workflows/db-update.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +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.
78+
INSTALL_CURRENT:
79+
description: Install the currently deployed API version when true; when false install main (latest).
8080
required: false
81-
default: latest
82-
type: string
81+
default: false
82+
type: boolean
8383
DRY_RUN:
8484
description: Skip applying schema and content updates
8585
required: false
@@ -115,27 +115,30 @@ jobs:
115115
run: |
116116
set -euo pipefail
117117
EVENT='${{ github.event_name }}'
118-
INSTALL_MODE='${{ inputs.INSTALL_MODE }}'
118+
INSTALL_CURRENT='${{ inputs.INSTALL_CURRENT }}'
119119
RESOLVED='${{ steps.resolve.outputs.RESOLVED }}'
120120
COMMIT_SHA='${{ steps.resolve.outputs.COMMIT_SHA }}'
121-
echo "event=$EVENT, install_mode=$INSTALL_MODE, resolved=$RESOLVED, commit=$COMMIT_SHA"
121+
echo "event=$EVENT, install_current=$INSTALL_CURRENT, resolved=$RESOLVED, commit=$COMMIT_SHA"
122122
if [ "$EVENT" = "repository_dispatch" ]; then
123+
# For repository_dispatch we always install the currently deployed version; fail if missing
123124
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
124125
echo "ERROR: repository_dispatch requires a resolved API commit but none was found" >&2
125126
exit 1
126127
fi
127128
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
128129
elif [ "$EVENT" = "workflow_dispatch" ]; then
129-
if [ "$INSTALL_MODE" = "installed" ]; then
130+
# For manual runs, INSTALL_CURRENT=true -> install deployed; false -> install main
131+
if [ "$INSTALL_CURRENT" = "true" ]; then
130132
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
131-
echo "ERROR: manual install requested 'installed' but no resolved commit available" >&2
133+
echo "ERROR: manual install requested current version but no resolved commit available" >&2
132134
exit 1
133135
fi
134136
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
135137
else
136138
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
137139
fi
138140
else
141+
# push or other events: default to main
139142
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
140143
fi
141144
@@ -144,7 +147,10 @@ jobs:
144147
permissions: write-all
145148
runs-on: ubuntu-latest
146149
needs: [resolve-api-meta]
147-
if: ${{ always() }}
150+
# If we need to install the currently installed version Only run schema update when we're NOT installing the currently deployed API version.
151+
# INSTALL_CURRENT is a boolean input: true means install the deployed commit (skip schema),
152+
# false means install the latest from main (apply schema updates).
153+
if: ${{ !inputs.INSTALL_CURRENT }}
148154
steps:
149155
- name: Checkout repo (shallow)
150156
uses: actions/checkout@v4

0 commit comments

Comments
 (0)