Skip to content

Commit e00bf3c

Browse files
committed
Skip Database Staging job on pull requests that don't change database migrations
1 parent d9309ea commit e00bf3c

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/account.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,28 @@ jobs:
4545
version: ${{ steps.generate_version.outputs.version }}
4646
deploy_staging: ${{ steps.determine_deployment.outputs.deploy_staging }}
4747
deploy_production: ${{ steps.determine_deployment.outputs.deploy_production }}
48+
migrations_changed: ${{ steps.detect_migrations.outputs.migrations_changed }}
4849

4950
steps:
5051
- name: Checkout Code
5152
uses: actions/checkout@v6
53+
with:
54+
# Full history is required to diff base..head for migration-change detection.
55+
fetch-depth: 0
56+
57+
- name: Detect Migration Changes
58+
id: detect_migrations
59+
env:
60+
BASE_REF: ${{ github.event.pull_request.base.sha || format('{0}~1', github.sha) }}
61+
HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
62+
run: |
63+
if git diff --name-only "$BASE_REF" "$HEAD_REF" | grep -q "^application/account/Core/Database/Migrations/"; then
64+
echo "migrations_changed=true" >> $GITHUB_OUTPUT
65+
echo "Migration changes detected — Database Staging will run."
66+
else
67+
echo "migrations_changed=false" >> $GITHUB_OUTPUT
68+
echo "No migration changes — Database Staging will be skipped on pull requests."
69+
fi
5270
5371
- name: Generate Version
5472
id: generate_version
@@ -109,7 +127,7 @@ jobs:
109127
dotnet test account/Account.slnf --no-build
110128
111129
- name: Save Backend Build Artifacts for Migration Plan
112-
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
130+
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' && (github.event_name != 'pull_request' || steps.detect_migrations.outputs.migrations_changed == 'true') }}
113131
uses: actions/upload-artifact@v7
114132
with:
115133
name: account-build
@@ -161,7 +179,7 @@ jobs:
161179

162180
database-migrations-stage:
163181
name: Database Staging
164-
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
182+
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' && (github.event_name != 'pull_request' || needs.build-and-test.outputs.migrations_changed == 'true') }}
165183
needs: build-and-test
166184
uses: ./.github/workflows/_migrate-database.yml
167185
secrets: inherit

.github/workflows/main.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,28 @@ jobs:
4545
version: ${{ steps.generate_version.outputs.version }}
4646
deploy_staging: ${{ steps.determine_deployment.outputs.deploy_staging }}
4747
deploy_production: ${{ steps.determine_deployment.outputs.deploy_production }}
48+
migrations_changed: ${{ steps.detect_migrations.outputs.migrations_changed }}
4849

4950
steps:
5051
- name: Checkout Code
5152
uses: actions/checkout@v6
53+
with:
54+
# Full history is required to diff base..head for migration-change detection.
55+
fetch-depth: 0
56+
57+
- name: Detect Migration Changes
58+
id: detect_migrations
59+
env:
60+
BASE_REF: ${{ github.event.pull_request.base.sha || format('{0}~1', github.sha) }}
61+
HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
62+
run: |
63+
if git diff --name-only "$BASE_REF" "$HEAD_REF" | grep -q "^application/main/Core/Database/Migrations/"; then
64+
echo "migrations_changed=true" >> $GITHUB_OUTPUT
65+
echo "Migration changes detected — Database Staging will run."
66+
else
67+
echo "migrations_changed=false" >> $GITHUB_OUTPUT
68+
echo "No migration changes — Database Staging will be skipped on pull requests."
69+
fi
5270
5371
- name: Generate Version
5472
id: generate_version
@@ -109,7 +127,7 @@ jobs:
109127
dotnet test main/Main.slnf --no-build
110128
111129
- name: Save Backend Build Artifacts for Migration Plan
112-
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
130+
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' && (github.event_name != 'pull_request' || steps.detect_migrations.outputs.migrations_changed == 'true') }}
113131
uses: actions/upload-artifact@v7
114132
with:
115133
name: main-build
@@ -156,7 +174,7 @@ jobs:
156174

157175
database-migrations-stage:
158176
name: Database Staging
159-
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
177+
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' && (github.event_name != 'pull_request' || needs.build-and-test.outputs.migrations_changed == 'true') }}
160178
needs: build-and-test
161179
uses: ./.github/workflows/_migrate-database.yml
162180
secrets: inherit

0 commit comments

Comments
 (0)