generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (68 loc) · 2.73 KB
/
pr-close.yml
File metadata and controls
79 lines (68 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: PR Closed
on:
pull_request:
types: [closed]
concurrency:
# PR open and close use the same group, allowing only one at a time
group: pr-${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
permissions: {}
jobs:
cleanup_configmap:
name: Cleanup FAM Route Allocations
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Remove FAM route allocations for PR
uses: bcgov/action-oc-runner@57a28c38359c93e43edf609d35b9a3f50a070131 # v1.4.0
env:
PR_NUMBER: ${{ github.event.number }}
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
commands: |
echo "Cleaning up route allocations for PR $PR_NUMBER"
# Check if ConfigMap exists
if ! oc get configmap fam-route-allocations &>/dev/null; then
echo "ConfigMap fam-route-allocations does not exist, nothing to clean up"
exit 0
fi
# Get current ConfigMap data
allocs=$(oc get configmap fam-route-allocations -o json | jq -r '.data // {}')
# Build patch to remove entries for this PR
patch='{"data": {'
first=true
for i in $(seq 0 49); do
for prefix in hybrid postgres; do
key="${prefix}_$i"
pr=$(echo "$allocs" | jq -r ".$key // empty")
if [[ "$pr" == "$PR_NUMBER" ]]; then
if [ "$first" = false ]; then
patch="$patch,"
fi
patch="$patch\"$key\": null"
first=false
echo "Removing reservation: $key (PR $PR_NUMBER)"
fi
done
done
patch="$patch}}"
if [ "$first" = false ]; then
oc patch configmap fam-route-allocations --type merge -p "$patch"
echo "Successfully removed route reservations for PR $PR_NUMBER"
else
echo "No route reservations found for PR $PR_NUMBER"
fi
cleanup:
name: Cleanup and Images
uses: bcgov/quickstart-openshift-helpers/.github/workflows/.pr-close.yml@ca6579bdadf383a2513397081f963889b92823a4 # v1.1.0
permissions:
packages: write
secrets:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
cleanup: label
packages: backend backend-postgres frontend
cleanup_name: ${{ github.event.repository.name }}-${{ github.event.number }}-hybrid ${{ github.event.repository.name }}-${{ github.event.number }}-postgres