File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 87
87
CLUSTER : prod-fss
88
88
RESOURCE : nais/naiserator.yaml
89
89
VARS : nais/prod-fss.json
90
+
91
+ close-old-deployment-reviews :
92
+ runs-on : ubuntu-latest
93
+ needs : [ build, test, deploy-dev ]
94
+ steps :
95
+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v3
96
+
97
+ - name : Close all older deployment reviews
98
+ env :
99
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
100
+ run : |
101
+ PENDING_REVIEWS=$(gh api \
102
+ repos/${{ github.repository }}/environments/prod-fss:k9saksbehandling/deployment_protection_rules/pending_deployments \
103
+ --jq '.pending_deployments[] | {run_id: .deployment.workflow_run_id, deploy_id: .deployment.id}')
104
+
105
+ # Lukk ALLE andre deployment reviews unntatt for denne run
106
+ echo "$PENDING_REVIEWS" | jq -c '.' | while read -r review; do
107
+ RUN_ID=$(echo "$review" | jq -r '.run_id')
108
+ DEPLOY_ID=$(echo "$review" | jq -r '.deploy_id')
109
+
110
+ # Sjekk om review er fra en annen workflow run
111
+ if [[ "$RUN_ID" != "${{ github.run_id }}" ]]; then
112
+ echo "Lukker deployment review for Run ID: $RUN_ID"
113
+ gh api \
114
+ --method POST \
115
+ repos/${{ github.repository }}/actions/deployments/$DEPLOY_ID/reject \
116
+ -f environment_name="prod-fss:k9saksbehandling" \
117
+ -f state="rejected" \
118
+ -f comment="Automatisk avvist - nyere deployment er tilgjengelig"
119
+ fi
120
+ done
You can’t perform that action at this time.
0 commit comments