diff --git a/.github/actions/merge-changes/action.yml b/.github/actions/merge-changes/action.yml index 70cee26630..5246238596 100644 --- a/.github/actions/merge-changes/action.yml +++ b/.github/actions/merge-changes/action.yml @@ -5,6 +5,15 @@ outputs: changes: description: A JSON array of projects where changes were reported by the build value: ${{ steps.check-changes.outputs.changes }} + dev: + description: A JSON array of projects where changes should be deployed to dev + value: ${{ steps.deployments.outputs.dev }} + preprod: + description: A JSON array of projects where changes should be deployed to preprod + value: ${{ steps.deployments.outputs.preprod }} + prod: + description: A JSON array of projects where changes should be deployed to prod + value: ${{ steps.deployments.outputs.prod }} runs: using: "composite" @@ -21,3 +30,10 @@ runs: id: check-changes shell: bash run: echo "changes=$(jq -s '[.[][]]' changes/**/*.json | jq -c '. // []')" | tee -a "$GITHUB_OUTPUT" + + - name: Check which services should be deployed + id: deployments + shell: bash + run: ./.github/actions/merge-changes/check-deployments.sh + env: + PROJECTS: ${{ steps.check-changes.outputs.changes }} \ No newline at end of file diff --git a/.github/actions/merge-changes/check-deployments.sh b/.github/actions/merge-changes/check-deployments.sh new file mode 100644 index 0000000000..cd5bab72a9 --- /dev/null +++ b/.github/actions/merge-changes/check-deployments.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +function fromJsonArray() { + jq --raw-output '.[]' +} + +function toJsonArray() { + jq --raw-input . | jq --slurp --compact-output . +} + +function deploymentEnabled() { + env=$1 + while IFS= read -r project; do + file="projects/$project/deploy/values-$env.yml" + if [ -f "$file" ] && ! grep -q 'enabled: false' "$file"; then echo "$project"; fi + done +} + +echo "dev=$(echo -n "$PROJECTS" | fromJsonArray | deploymentEnabled dev | toJsonArray)" | tee -a "$GITHUB_OUTPUT" +echo "prepod=$(echo -n "$PROJECTS" | fromJsonArray | deploymentEnabled preprod | toJsonArray)" | tee -a "$GITHUB_OUTPUT" +echo "prod=$(echo -n "$PROJECTS" | fromJsonArray | deploymentEnabled prod | toJsonArray)" | tee -a "$GITHUB_OUTPUT" diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index f1dda8d2d2..2bab662597 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -27,6 +27,9 @@ jobs: needs: build outputs: changes: ${{ steps.merge-changes.outputs.changes }} + dev_deployments: ${{ steps.merge-changes.outputs.dev }} + preprod_deployments: ${{ steps.merge-changes.outputs.preprod }} + prod_deployments: ${{ steps.merge-changes.outputs.prod }} version: ${{ needs.build.outputs.version }} steps: - uses: actions/checkout@v4 @@ -49,22 +52,22 @@ jobs: name: Deploy to test uses: ./.github/workflows/deploy.yml needs: post-build - if: ${{ needs.post-build.outputs.changes != '[]' }} + if: ${{ needs.post-build.outputs.dev_deployments != '[]' }} with: environment: test version: ${{ needs.post-build.outputs.version }} - projects: ${{ needs.post-build.outputs.changes }} + projects: ${{ needs.post-build.outputs.dev_deployments }} secrets: inherit deploy-to-preprod: name: Deploy to preprod uses: ./.github/workflows/deploy.yml needs: post-build - if: ${{ needs.post-build.outputs.changes != '[]'}} + if: ${{ needs.post-build.outputs.preprod_deployments != '[]'}} with: environment: preprod version: ${{ needs.post-build.outputs.version }} - projects: ${{ needs.post-build.outputs.changes }} + projects: ${{ needs.post-build.outputs.preprod_deployments }} secrets: inherit end-to-end-tests: @@ -78,6 +81,7 @@ jobs: outputs: failed-projects: ${{ steps.run.outputs.failed-projects }} passed-projects: ${{ steps.run.outputs.passed-projects }} + deploy-to-prod: ${{ steps.intersect.outputs.prod }} report-url: ${{ steps.run.outputs.report-url }} steps: - uses: actions/create-github-app-token@v1 @@ -92,6 +96,12 @@ jobs: with: projects: ${{ needs.post-build.outputs.changes }} token: ${{ steps.app-token.outputs.token }} + - name: Output projects with changes for production where the tests have passed + id: intersect + run: echo "prod=$(jq -crn --argjson changes "$CHANGES" --argjson passed "$PASSED" '$changes - ($changes - $passed)')" | tee -a "$GITHUB_OUTPUT" + env: + CHANGES: ${{ needs.post-build.outputs.prod_deployments }} + PASSED: ${{ steps.run.outputs.passed-projects }} report-test-failures: name: Failed testing @@ -109,12 +119,12 @@ jobs: deploy-to-prod: name: Deploy to production uses: ./.github/workflows/deploy.yml - if: ${{ (success() || (failure() && needs.end-to-end-tests.outputs.passed-projects != '[]')) && github.ref == 'refs/heads/main' }} + if: ${{ (success() || (failure() && needs.end-to-end-tests.outputs.deploy-to-prod != '[]')) }} # TODO testing from branch: && github.ref == 'refs/heads/main' }} needs: - post-build - end-to-end-tests with: environment: prod version: ${{ needs.post-build.outputs.version }} - projects: ${{ needs.end-to-end-tests.outputs.passed-projects }} + projects: ${{ needs.end-to-end-tests.outputs.deploy-to-prod }} secrets: inherit