1- name : Copy PROD DB to QA
1+ # Called when the Mobility Catalog is updated.
2+ name : Mobility Catalog Update
23on :
3- workflow_dispatch : # Supports manual deployment
4+ workflow_dispatch :
45 inputs :
5- dest_database_name :
6- description : ' The name of the destination database (using MobilityDatabase will overwrite the current QA DB) '
6+ DRY_RUN :
7+ description : Dry run. Skip applying schema and content updates
78 required : false
8- default : ' MobilityDatabaseProdDuplicate'
9- backup_db :
10- description : ' Backup the current QA DB before importing the dump'
11- required : false
12- default : ' false'
13- release :
14- types : [ prereleased ]
9+ default : true
10+ type : boolean
11+ repository_dispatch : # Update on mobility-database-catalog repo dispatch
12+ types : [ catalog-sources-updated, gbfs-systems-updated ]
13+
14+ env :
15+ python_version : ' 3.11'
16+ liquibase_version : ' 4.33.0'
1517
1618jobs :
17- run-script :
19+ resolve-api-meta :
20+ name : ' Resolve API commit/version'
1821 runs-on : ubuntu-latest
19- env :
20- SOURCE_PROJECT_ID : ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
21- DEST_PROJECT_ID : ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }}
22- DUMP_BUCKET_NAME : " mobilitydata-database-dump-qa"
23- BUCKET_PROJECT_ID : ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }}
24- GCP_REGION : ${{ vars.MOBILITY_FEEDS_REGION }}
25- DB_INSTANCE_NAME : ${{ secrets.DB_INSTANCE_NAME }}
26- DEST_DATABASE_PASSWORD : ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
27- DUMP_FILE_NAME : " prod-db-dump.sql"
28- SOURCE_DATABASE_NAME : ${{ vars.PROD_POSTGRE_SQL_DB_NAME }}
29- DEST_DATABASE_NAME : ${{ inputs.dest_database_name || 'MobilityDatabase' }}
30- DEST_DATABASE_USER : ${{ secrets.QA_POSTGRE_USER_NAME }}
31- DEST_DATABASE_IMPORT_USER : ${{ secrets.PROD_POSTGRE_USER_NAME }}
32- GCP_FEED_BASTION_SSH_KEY : ${{ secrets.GCP_FEED_BASTION_SSH_KEY }}
33- BACKUP_DB : ${{ inputs.backup_db || 'false' }}
34-
22+ outputs :
23+ # Use resolved commit when available; otherwise default to 'main'.
24+ CHECKOUT_REF : ${{ steps.resolve.outputs.COMMIT_SHA != '' && steps.resolve.outputs.COMMIT_SHA || 'main' }}
3525 steps :
36- - name : Checkout code
37- uses : actions/checkout@v2
38-
39- - name : Authenticate to Google Cloud PROD project
40- id : gcloud_auth_prod
41- uses : google-github-actions/auth@v2
42- with :
43- credentials_json : ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
44-
45- - name : GCloud Setup PROD
46- uses : google-github-actions/setup-gcloud@v2
47-
48- - name : Get PROD SQL service account
49- run : |
50- SERVICE_ACCOUNT=$(gcloud sql instances describe "mobilitydata-database-instance" --project=$SOURCE_PROJECT_ID --format="value(serviceAccountEmailAddress)")
51- echo "SOURCE_SQL_SERVICE_ACCOUNT=$SERVICE_ACCOUNT" >> $GITHUB_ENV
52- echo "Destination SQL Service Account: $SERVICE_ACCOUNT"
53-
54- - name : Authenticate to Google Cloud QA project
55- id : gcloud_auth_qa
56- uses : google-github-actions/auth@v2
57- with :
58- credentials_json : ${{ secrets.QA_GCP_MOBILITY_FEEDS_SA_KEY }}
59-
60- - name : GCloud Setup QA
61- uses : google-github-actions/setup-gcloud@v2
62-
63- - name : Create DB dump bucket and give permissions
64- run : bash scripts/duplicate-prod-db/create-dump-bucket.sh
65-
66- - name : Authenticate to Google Cloud PROD project Again
67- uses : google-github-actions/auth@v2
68- with :
69- credentials_json : ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
70-
71- - name : GCloud Setup PROD again
72- uses : google-github-actions/setup-gcloud@v2
73-
74- - name : Dump the PROD DB
75- run : |
76- gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$SOURCE_DATABASE_NAME --quiet
77-
78- - name : Authenticate to Google Cloud QA project Again
79- uses : google-github-actions/auth@v2
26+ - name : Checkout repo (for scripts and local action)
27+ uses : actions/checkout@v4
28+ - name : Resolve API commit/version
29+ id : resolve
30+ uses : ./.github/actions/resolve-api-meta
8031 with :
81- credentials_json : ${{ secrets.QA_GCP_MOBILITY_FEEDS_SA_KEY }}
82-
83- - name : GCloud Setup QA Again
84- uses : google-github-actions/setup-gcloud@v2
85-
86- - name : QA backup and import dump into the QA DB
87- run : bash scripts/duplicate-prod-db/copy-prod-db-to-qa.sh
88-
89- - name : Load secrets from 1Password
90- uses : 1password/load-secrets-action@v2.0.0
91- with :
92- export-env : true # Export loaded secrets as environment variables
93- env :
94- OP_SERVICE_ACCOUNT_TOKEN : ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
95- GCP_FEED_SSH_USER : " op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GCP_FEED_SSH_USER/username"
96- GCP_FEED_BASTION_NAME : " op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GCP_FEED_BASTION_NAME/username"
97- GCP_FEED_BASTION_SSH_KEY : " op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GCP_FEED_BASTION_SSH_KEY/private key"
98-
99- - name : Tunnel and run SQL scripts on imported database
100- run : bash scripts/duplicate-prod-db/post-import.sh
101-
32+ api_base_url : ${{ inputs.API_BASE_URL }}
33+ api_refresh_token : ${{ secrets.API_TEST_REFRESH_TOKEN }}
34+
35+ update-content-qa :
36+ name : Call DB content update for QA
37+ uses : ./.github/workflows/db-update-content.yml
38+ with :
39+ PROJECT_ID : ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }}
40+ REGION : ${{ vars.MOBILITY_FEEDS_REGION }}
41+ DB_NAME : ${{ vars.QA_POSTGRE_SQL_DB_NAME }}
42+ ENVIRONMENT : ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
43+ DB_ENVIRONMENT : ${{ vars.QA_MOBILITY_FEEDS_ENVIRONMENT }}
44+ DRY_RUN : ${{ github.event_name == 'repository_dispatch' || (github.event_name == 'workflow_dispatch' && inputs.DRY_RUN) || false }}
45+ CHECKOUT_REF : main
46+ secrets : inherit
0 commit comments