Skip to content

Commit 7191c49

Browse files
committed
Simplified
1 parent 364cf7c commit 7191c49

File tree

5 files changed

+28
-73
lines changed

5 files changed

+28
-73
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ runs:
5656
RESOLVED="true"
5757
echo "Resolved API version: ${API_VERSION} (commit ${COMMIT_SHA})"
5858
else
59-
echo "No token provided; skipping API metadata resolution."
59+
echo "Error: no API refresh token provided; cannot resolve deployed commit." >&2
60+
exit 1
6061
fi
6162
echo "COMMIT_SHA=${COMMIT_SHA}"
6263
echo "API_VERSION=${API_VERSION}"

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ on:
1616
required: false
1717
default: false
1818
type: boolean
19-
INSTALL_CURRENT:
20-
description: Install the currently deployed API version when true; when false install main (latest).
21-
required: false
22-
default: true
23-
type: boolean
2419
jobs:
2520
update:
2621
uses: ./.github/workflows/db-update.yml
@@ -31,8 +26,11 @@ jobs:
3126
ENVIRONMENT: ${{ vars.DEV_MOBILITY_FEEDS_ENVIRONMENT }}
3227
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
3328
API_BASE_URL: api-dev.mobilitydatabase.org
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' }}
29+
# DRY_RUN is only if requested by the user in a workflow_dispatch
30+
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.DRY_RUN }}
31+
# We always want to install the latest except if we received a dispatch from mobility_database_catalog.
32+
# In that case we want to keep the currently installed version.
33+
INSTALL_LATEST: ${{ github.event_name != 'repository_dispatch' }}
3634
secrets:
3735
DB_USER_PASSWORD: ${{ secrets.DEV_POSTGRE_USER_PASSWORD }}
3836
DB_USER_NAME: ${{ secrets.DEV_POSTGRE_USER_NAME }}

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
required: false
99
default: false
1010
type: boolean
11-
INSTALL_CURRENT:
12-
description: Install the currently deployed API version when true; when false install main (latest).
13-
required: false
14-
default: true
15-
type: boolean
1611
workflow_call: []
1712
repository_dispatch: # Update on mobility-database-catalog repo dispatch
1813
types: [ catalog-sources-updated, gbfs-systems-updated ]
@@ -26,14 +21,11 @@ jobs:
2621
ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
2722
DB_ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
2823
API_BASE_URL: api.mobilitydatabase.org
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' }}
24+
# DRY_RUN is only if requested by the user in a workflow_dispatch
25+
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.DRY_RUN }}
26+
# We always want to install the latest except if we received a dispatch from mobility_database_catalog.
27+
# In that case we want to keep the currently installed version.
28+
INSTALL_LATEST: ${{ github.event_name != 'repository_dispatch' }}
3729
secrets:
3830
DB_USER_PASSWORD: ${{ secrets.PROD_POSTGRE_USER_PASSWORD }}
3931
DB_USER_NAME: ${{ secrets.PROD_POSTGRE_USER_NAME }}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
required: false
99
default: false
1010
type: boolean
11-
INSTALL_CURRENT:
12-
description: Install the currently deployed API version when true; when false install main (latest).
13-
required: false
14-
default: false
15-
type: boolean
1611
workflow_call: []
1712

1813
repository_dispatch: # Update on mobility-database-catalog repo dispatch
@@ -28,8 +23,11 @@ jobs:
2823
ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
2924
DB_ENVIRONMENT: ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
3025
API_BASE_URL: api-qa.mobilitydatabase.org
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' }}
26+
# DRY_RUN is only if requested by the user in a workflow_dispatch
27+
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.DRY_RUN }}
28+
# We always want to install the latest except if we received a dispatch from mobility_database_catalog.
29+
# In that case we want to keep the currently installed version.
30+
INSTALL_LATEST: ${{ github.event_name != 'repository_dispatch' }}
3331
secrets:
3432
DB_USER_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
3533
DB_USER_NAME: ${{ secrets.QA_POSTGRE_USER_NAME }}

.github/workflows/db-update.yml

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ on:
7575
required: false
7676
default: api.mobilitydatabase.org
7777
type: string
78-
INSTALL_CURRENT:
79-
description: Install the currently deployed API version when true; when false install main (latest).
78+
INSTALL_LATEST:
79+
description: Install the latest (main) API version when true; when false keep the currently deployed version.
8080
required: false
8181
default: false
8282
type: boolean
@@ -97,64 +97,32 @@ jobs:
9797
# Run this job for all triggers; the action itself will skip resolution when API_BASE_URL or token is not provided.
9898
# Keeping it unconditional ensures CHECKOUT_REF is always set (defaults to 'main') for downstream jobs.
9999
outputs:
100-
COMMIT_SHA: ${{ steps.resolve.outputs.COMMIT_SHA }}
101-
API_VERSION: ${{ steps.resolve.outputs.API_VERSION }}
102-
CHECKOUT_REF: ${{ steps.decide_ref.outputs.CHECKOUT_REF }}
100+
# Use resolved commit when available; otherwise default to 'main'.
101+
CHECKOUT_REF: ${{ steps.resolve.outputs.COMMIT_SHA != '' && steps.resolve.outputs.COMMIT_SHA || 'main' }}
103102
steps:
104103
- name: Checkout repo (for scripts and local action)
105104
uses: actions/checkout@v4
106105
- name: Resolve API commit/version
107106
id: resolve
108-
# The composite action itself checks for a missing token and will skip resolution when none is provided.
107+
if: ${{ inputs.INSTALL_LATEST == false }}
109108
uses: ./.github/actions/resolve-api-meta
110109
with:
111110
api_base_url: ${{ inputs.API_BASE_URL }}
112111
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_CURRENT='${{ inputs.INSTALL_CURRENT }}'
119-
RESOLVED='${{ steps.resolve.outputs.RESOLVED }}'
120-
COMMIT_SHA='${{ steps.resolve.outputs.COMMIT_SHA }}'
121-
echo "event=$EVENT, install_current=$INSTALL_CURRENT, resolved=$RESOLVED, commit=$COMMIT_SHA"
122-
if [ "$EVENT" = "repository_dispatch" ]; then
123-
# For repository_dispatch we always install the currently deployed version; fail if missing
124-
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
125-
echo "ERROR: repository_dispatch requires a resolved API commit but none was found" >&2
126-
exit 1
127-
fi
128-
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
129-
elif [ "$EVENT" = "workflow_dispatch" ]; then
130-
# For manual runs, INSTALL_CURRENT=true -> install deployed; false -> install main
131-
if [ "$INSTALL_CURRENT" = "true" ]; then
132-
if [ "$RESOLVED" != "true" ] || [ -z "$COMMIT_SHA" ]; then
133-
echo "ERROR: manual install requested current version but no resolved commit available" >&2
134-
exit 1
135-
fi
136-
echo "CHECKOUT_REF=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
137-
else
138-
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
139-
fi
140-
else
141-
# push or other events: default to main
142-
echo "CHECKOUT_REF=main" >> "$GITHUB_OUTPUT"
143-
fi
144112

145113
db-schema-update:
146114
name: 'Database Schema Update'
147115
permissions: write-all
148116
runs-on: ubuntu-latest
149117
needs: [resolve-api-meta]
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 }}
118+
# Only run the schema update when INSTALL_LATEST is true (we're installing main/latest).
119+
# If not, we have nothing to do since we will use the version already installed.
120+
if: ${{ inputs.INSTALL_LATEST == true }}
154121
steps:
155122
- name: Checkout repo (shallow)
156123
uses: actions/checkout@v4
157124
with:
125+
# Use the job-level CHECKOUT_REF (already resolves to COMMIT_SHA or 'main')
158126
ref: ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
159127
fetch-depth: 0
160128

@@ -218,11 +186,12 @@ jobs:
218186
permissions: write-all
219187
runs-on: ubuntu-latest
220188
needs: [resolve-api-meta, db-schema-update]
221-
if: ${{ always() && contains('repository_dispatch,workflow_dispatch', github.event_name) }}
189+
if: ${{ always() }}
222190
steps:
223191
- name: Checkout repo (shallow)
224192
uses: actions/checkout@v4
225193
with:
194+
# Use the job-level CHECKOUT_REF (already resolves to COMMIT_SHA or 'main')
226195
ref: ${{ needs.resolve-api-meta.outputs.CHECKOUT_REF }}
227196
fetch-depth: 0
228197

@@ -240,8 +209,6 @@ jobs:
240209
uses: google-github-actions/setup-gcloud@v2
241210

242211
- name: Update .env file
243-
env:
244-
API_VERSION: ${{ needs.resolve-api-meta.outputs.API_VERSION }}
245212
run: |
246213
echo "PGUSER=${{ secrets.DB_USER_NAME }}" > config/.env.local
247214
echo "POSTGRES_USER=${{ secrets.DB_USER_NAME }}" >> config/.env.local
@@ -251,7 +218,6 @@ jobs:
251218
echo "POSTGRES_PORT=5432" >> config/.env.local
252219
echo "POSTGRES_HOST=localhost" >> config/.env.local
253220
echo "ENV=${{ inputs.ENVIRONMENT }}" >> config/.env.local
254-
if [[ -n "${API_VERSION}" ]]; then echo "API_VERSION=${API_VERSION}" >> config/.env.local; fi
255221
cat config/.env.local
256222
257223
- name: Load secrets from 1Password

0 commit comments

Comments
 (0)