sankhajuria - issue:172 #111
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Parse github form | |
run-name: ${{ github.actor }} - issue:${{ github.event.issue.number }} | |
on: | |
issues: | |
types: | |
- opened | |
- edited | |
workflow_dispatch: | |
env: | |
GH_TOKEN: ${{ secrets.PLATFORM_USER_TOKEN }} | |
permissions: | |
id-token: write | |
jobs: | |
parse: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: ${{ github.event.issue.user.login != 'renovate[bot]' }} | |
steps: | |
- name: Add eyes reaction | |
uses: aidan-mundy/[email protected] | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
reactions: eyes | |
#Uncomment for troubleshooting | |
#- name: Dump context | |
#uses: crazy-max/ghaction-dump-context@v2 | |
- name: add processing label | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: "Processing" | |
- name: Remove labels | |
uses: actions-ecosystem/action-remove-labels@v1 | |
if: env.PROCESS_SUCCESS == 'false' | |
with: | |
labels: | | |
Success | |
Error in form | |
High Cost | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
token: ${{ env.GH_TOKEN }} | |
- name: Parse issue | |
id: parse_issue | |
uses: onmax/[email protected] | |
with: | |
issue_number: ${{ github.event.issue.number }} | |
- name: Show parsed payload data | |
run: | | |
# Using the character `'` to prevent all characters enclosed within | |
# them from being treated as special characters (e.g. $ or `) | |
echo '${{ steps.parse_issue.outputs.payload }}' | |
echo NEW_DATA='${{ steps.parse_issue.outputs.payload }}' >> $GITHUB_ENV | |
echo GITHUB_REPO='${{ github.repository }}' >> $GITHUB_ENV | |
echo ISSUE_NUMBER='${{ github.event.issue.number }}' >> $GITHUB_ENV | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install Python Requirements | |
run: | | |
pip3 install -r requirements.txt | |
- name: process form data | |
continue-on-error: true | |
run: | | |
python ./scripts/file_handling.py | |
- name: Create Issue Comment | |
if: env.PROCESS_SUCCESS != 'true' | |
uses: peter-evans/[email protected] | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
${{ env.ISSUE_COMMENT }} | |
Please edit this issue and select "Update comment" to resubmit. | |
- name: 'Az CLI login' | |
uses: azure/login@v1 | |
with: | |
client-id: 2b6fa9d7-7dba-4600-a58a-5e25554997aa # DTS AKS Auto-Shutdown | |
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET | |
allow-no-subscriptions: true | |
- name: get aks resource details | |
if: env.PROCESS_SUCCESS == 'true' | |
continue-on-error: true | |
run: ./scripts/aks/resource-details.sh | |
- name: process costs | |
if: env.PROCESS_SUCCESS == 'true' | |
continue-on-error: true | |
run: | | |
python ./scripts/cost-calculator.py || echo "Calculating cost failed" | |
- name: Add cost details as a comment | |
if: env.PROCESS_SUCCESS == 'true' && env.ERROR_IN_COSTS != 'true' | |
uses: peter-evans/[email protected] | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
Total estimated cost of skipping shutdown for the provided dates is **£${{ env.COST_DETAILS_FORMATTED }}** | |
- name: Add cost error details as a comment | |
if: env.PROCESS_SUCCESS == 'true' && env.ERROR_IN_COSTS == 'true' | |
uses: peter-evans/[email protected] | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
We have been unable to estimate the cost of this skip request. | |
- name: Add high cost label | |
if: env.COST_DETAILS > 1000 | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: "High Cost" | |
- name: Add costs error label | |
if: env.ERROR_IN_COSTS == 'true' | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: "Cost Error" | |
- name: Remove error labels | |
uses: actions-ecosystem/action-remove-labels@v1 | |
if: env.PROCESS_SUCCESS == 'true' | |
with: | |
labels: | | |
Error in form | |
Processing | |
- name: Remove labels | |
uses: actions-ecosystem/action-remove-labels@v1 | |
if: env.PROCESS_SUCCESS == 'false' | |
with: | |
labels: | | |
Processing | |
Success | |
- name: Add success label | |
if: env.PROCESS_SUCCESS == 'true' | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: "Success" | |
- name: Add error label | |
if: env.PROCESS_SUCCESS != 'true' | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: "Error in form" | |
- name: Commit to master | |
if: env.PROCESS_SUCCESS == 'true' | |
run: | | |
git config user.name hmcts-platform-operations | |
git config user.email [email protected] | |
git add . | |
git commit -m parseissue-${{ github.event.issue.number }} | |
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: Close Issue | |
if: env.PROCESS_SUCCESS == 'true' | |
uses: peter-evans/close-issue@v3 | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
comment: | | |
Success! Your [commit](${{ env.COMMIT_URL }}) has been added to the json exclusions file. | |
Auto-closing issue. |