Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2628 Only run deploy action for projects that are enabled #4417

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/actions/merge-changes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }}
21 changes: 21 additions & 0 deletions .github/actions/merge-changes/check-deployments.sh
Original file line number Diff line number Diff line change
@@ -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 "preprod=$(echo -n "$PROJECTS" | fromJsonArray | deploymentEnabled preprod | toJsonArray)" | tee -a "$GITHUB_OUTPUT"
echo "prod=$(echo -n "$PROJECTS" | fromJsonArray | deploymentEnabled prod | toJsonArray)" | tee -a "$GITHUB_OUTPUT"
22 changes: 16 additions & 6 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 != '[]')) && 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
Loading