From 7cd80dc3a101e390fd036f82e8daa5e1589e0278 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Tue, 23 Apr 2024 16:22:22 +0200 Subject: [PATCH] ci: only run if migrations are changed (#669) ## Description - Only run migrations if relevant files are changed - Run the deployment of apps regardless of if migration was run ## Related Issue(s) - #{issue number} ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) --- .github/workflows/action-check-for-changes.yml | 7 ++++++- .github/workflows/action-deploy-apps.yml | 8 ++++++++ .github/workflows/ci-cd-main.yml | 1 + .github/workflows/ci-cd-staging.yml | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/action-check-for-changes.yml b/.github/workflows/action-check-for-changes.yml index 543cc7ba1..bc6723a59 100644 --- a/.github/workflows/action-check-for-changes.yml +++ b/.github/workflows/action-check-for-changes.yml @@ -12,6 +12,9 @@ on: hasSlackNotifierChanges: description: "Slack Notifier function related files changed" value: ${{ jobs.check-for-changes.outputs.hasSlackNotifierChanges }} + hasMigrationChanges: + description: "Migration related files changed" + value: ${{ jobs.check-for-changes.outputs.hasMigrationChanges }} jobs: check-for-changes: name: Filter @@ -20,7 +23,7 @@ jobs: hasBackendChanges: ${{ steps.filter.outputs.backend_any_changed == 'true' }} hasAzureChanges: ${{ steps.filter.outputs.azure_any_changed == 'true' }} hasSlackNotifierChanges: ${{ steps.filter.outputs.slackNotifier_any_changed == 'true'}} - + hasMigrationChanges: ${{ steps.filter.outputs.migration_any_changed == 'true'}} steps: - name: Checkout uses: actions/checkout@v4 @@ -43,3 +46,5 @@ jobs: slackNotifier: - '.github/**/*' - 'src/Digdir.Tool.Dialogporten.SlackNotifier/**/*' + migration: + - 'src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/**/*' diff --git a/.github/workflows/action-deploy-apps.yml b/.github/workflows/action-deploy-apps.yml index b73d31ac3..4702ac348 100644 --- a/.github/workflows/action-deploy-apps.yml +++ b/.github/workflows/action-deploy-apps.yml @@ -37,6 +37,11 @@ on: description: "Current version to use as tag" required: true type: string + runMigration: + description: "If true, the migration job will be run." + required: false + type: boolean + default: false concurrency: # Existing runs are cancelled if someone repeatedly commits to their own Pull Request (PR). However, it does not stop others' dry runs or actual deployments from the main branch. # Also, the cancellation does not occur on merges to the main branch. Therefore, if multiple merges to main are performed simultaneously, they will just be queued up. @@ -47,6 +52,7 @@ jobs: deploy-migration-job: name: Deploy migration job to ${{ inputs.environment }} runs-on: ubuntu-latest + if: ${{ inputs.runMigration }} environment: ${{inputs.environment}} permissions: id-token: write @@ -108,6 +114,8 @@ jobs: deploy-apps: name: Deploy ${{ matrix.name }} to ${{ inputs.environment }} runs-on: ubuntu-latest + # Should run even though the migration job was skipped + if: ${{ always() && !failure() && !cancelled() }} needs: deploy-migration-job strategy: fail-fast: true diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index f516172f5..81c3888f5 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -106,6 +106,7 @@ jobs: environment: test region: norwayeast version: ${{ needs.get-current-version.outputs.version }}-${{ needs.generate-git-short-sha.outputs.gitShortSha }} + runMigration: ${{ needs.check-for-changes.outputs.hasMigrationChanges == 'true' }} deploy-slack-notifier-test: name: Deploy slack notifier (test) diff --git a/.github/workflows/ci-cd-staging.yml b/.github/workflows/ci-cd-staging.yml index 680754687..91d23c239 100644 --- a/.github/workflows/ci-cd-staging.yml +++ b/.github/workflows/ci-cd-staging.yml @@ -68,6 +68,7 @@ jobs: environment: staging region: norwayeast version: ${{ needs.get-current-version.outputs.version }} + runMigration: ${{ needs.check-for-changes.outputs.hasMigrationChanges == 'true' }} run-e2e-tests: name: "Run K6 functional end-to-end tests"