Skip to content

Commit b017b16

Browse files
committed
Lukker andre deployment reviews, for å unngå å ha flere pending samtidig
1 parent 962817e commit b017b16

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

.github/workflows/build-master.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,34 @@ jobs:
8787
CLUSTER: prod-fss
8888
RESOURCE: nais/naiserator.yaml
8989
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

0 commit comments

Comments
 (0)