Skip to content

hmcts-platform-operations - cancel issue:899 #1132

hmcts-platform-operations - cancel issue:899

hmcts-platform-operations - cancel issue:899 #1132

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 }}