forked from hmcts/auto-shutdown
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (84 loc) · 3.55 KB
/
cancel-github-issue.yaml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Cancel issue
run-name: ${{ github.actor }} - cancel issue:${{ github.event.issue.number }}
on:
issues:
types:
- opened
- edited
- labeled
workflow_dispatch:
env:
GH_TOKEN: ${{ secrets.PLATFORM_USER_TOKEN }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
APPROVAL_STATE: "Pending Approval"
APPROVAL_COMMENT: "Pending Approval"
SLACK_TOKEN: ${{ secrets.AUTO_SHUTDOWN_OAUTH_TOKEN }}
PROJECT_NUMBER: 30
PROJECT_OWNER: hmcts
permissions:
id-token: write
jobs:
process-request:
permissions: write-all
runs-on: ubuntu-latest
if: github.event.issue.user.login != 'renovate[bot]' && contains(github.event.issue.labels.*.name, 'cancel')
steps:
#Allows workflow to access repo
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
token: ${{ env.GH_TOKEN }}
#Check if the "cancel" label is added
- name: Check for cancel label
run: |
# Logic to remove entry from issues_list.json
python ./scripts/remove_entry.py ${{ github.event.issue.number }}
#Commit issue removal if canceled
- name: Commit changes - issue canceled
if: contains(github.event.issue.labels.*.name, 'cancel') && github.event.action == 'labeled'
run: |
ISSUE_NUMBER='${{ github.event.issue.number }}'
git config user.name hmcts-platform-operations
git config user.email github-platform-operations@hmcts.net
git add .
git commit -m parseissue-$ISSUE_NUMBER-removed
git push
commit_tree_url=$(gh browse -c -n)
commit_url=${commit_tree_url/tree/commit}
echo "COMMIT_URL=$(echo $commit_url)" >> $GITHUB_ENV
- name: Run if cancel label added
if: contains(github.event.issue.labels.*.name, 'cancel')
run: |
CURRENT_TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q .title)
if [[ "$CURRENT_TITLE" != *"- ❌"* ]]; then
NEW_TITLE="${CURRENT_TITLE} - ❌"
gh issue edit ${{ github.event.issue.number }} --title "$NEW_TITLE"
fi
ITEM_ID=$(gh project item-add $PROJECT_NUMBER --owner $PROJECT_OWNER --url ${{ github.event.issue.html_url }} --format json | jq -r '.id')
echo "Item ID: $ITEM_ID"
gh project item-delete $PROJECT_NUMBER --owner $PROJECT_OWNER --id $ITEM_ID
# Check if the auto start stop script should run
- name: Check the time
run: |
CURRENT_HOUR=$(TZ=Europe/London date +%H)
echo "Current hour is $CURRENT_HOUR"
if [ $CURRENT_HOUR -ge 0 ] && [ $CURRENT_HOUR -lt 7 ]; then
echo "It's after midnight but before 7am"
echo "Auto-start-stop script will run"
echo "RUN_AUTO_START_STOP_SCRIPT=true" >> $GITHUB_ENV
elif [ $CURRENT_HOUR -lt 23 ] && [ $CURRENT_HOUR -ge 7 ]; then
echo "It's between 7am and 11pm"
echo "Auto-start-stop script won't run"
echo "RUN_AUTO_START_STOP_SCRIPT=false" >> $GITHUB_ENV
else
echo "It's sometime after 11pm but before midnight"
echo "Auto-start-stop script will run"
echo "RUN_AUTO_START_STOP_SCRIPT=true" >> $GITHUB_ENV
fi
- name: AKS Auto Shutdown
if: env.RUN_AUTO_START_STOP_SCRIPT == 'true'
run: ./scripts/aks/auto-start-stop.sh stop
- name: AKS Auto Shutdown status check
if: env.RUN_AUTO_START_STOP_SCRIPT == 'true'
run: ./scripts/aks/auto-shutdown-status.sh stop ${{ secrets.SLACK_WEBHOOK }}