Skip to content

Commit e9f494f

Browse files
committed
Nytt forsøk på lukking av pending deployments
1 parent b3e03ab commit e9f494f

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

.github/workflows/build-master.yaml

+41-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,49 @@ jobs:
7272
RESOURCE: nais/naiserator.yaml
7373
VARS: nais/dev-fss.json
7474

75+
close-old-deployment-reviews:
76+
runs-on: ubuntu-latest
77+
needs: [ build, test, deploy-dev ]
78+
permissions:
79+
deployments: write
80+
steps:
81+
- name: Close older deployment reviews
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
run: |
85+
echo "Fetching pending deployment reviews..."
86+
PENDING_REVIEWS=$(gh api \
87+
repos/${{ github.repository }}/environments/prod-fss:k9saksbehandling/deployment_protection_rules/pending_deployments \
88+
--jq '.pending_deployments[] | {run_id: .deployment.workflow_run_id, deploy_id: .deployment.id}')
89+
90+
if [ -z "$PENDING_REVIEWS" ]; then
91+
echo "No pending deployment reviews found."
92+
exit 0
93+
fi
94+
95+
echo "Found pending reviews: $PENDING_REVIEWS"
96+
97+
# Close all deployment reviews except for this run
98+
echo "$PENDING_REVIEWS" | jq -c '.' | while read -r review; do
99+
RUN_ID=$(echo "$review" | jq -r '.run_id')
100+
DEPLOY_ID=$(echo "$review" | jq -r '.deploy_id')
101+
102+
if [[ "$RUN_ID" != "${{ github.run_id }}" ]]; then
103+
echo "Closing deployment review for Run ID: $RUN_ID, Deploy ID: $DEPLOY_ID"
104+
gh api \
105+
--method POST \
106+
repos/${{ github.repository }}/actions/deployments/$DEPLOY_ID/reject \
107+
-f environment_name="prod-fss:k9saksbehandling" \
108+
-f state="rejected" \
109+
-f comment="Automatically rejected - newer deployment is available"
110+
else
111+
echo "Skipping current run's deployment review: $RUN_ID"
112+
fi
113+
done
114+
75115
deploy-prod:
76116
runs-on: ubuntu-latest
77-
needs: [ deploy-dev ]
117+
needs: [ deploy-dev, close-old-deployment-reviews ]
78118
environment: "prod-fss:k9saksbehandling"
79119
concurrency: "prod-fss:k9saksbehandling"
80120
steps:

0 commit comments

Comments
 (0)