Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slots Cleanup - Adding new check #1211

Merged
merged 181 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
92e8df6
PR - Adding new check for checking PR and slots counts
amankumarrr Aug 7, 2023
91a1e55
Adding Token-Id check
amankumarrr Aug 7, 2023
f63acfd
Adding link to actual repo and solving the query param
amankumarrr Aug 7, 2023
c4ec056
Removing --name from the query
amankumarrr Aug 7, 2023
e194d62
Checking variables
amankumarrr Aug 7, 2023
9198f3b
Adding new step to load .env
amankumarrr Aug 7, 2023
f09db17
Removing quote from the resource group
amankumarrr Aug 7, 2023
d2d6999
Adding query to filter out the result
amankumarrr Aug 7, 2023
e5ef745
Adding check to compare the numbers
amankumarrr Aug 7, 2023
e13e756
Getting the PR ids
amankumarrr Aug 7, 2023
eb3891c
adding a step to check out
amankumarrr Aug 7, 2023
c784e2b
Adding count object with the PRs slots
amankumarrr Aug 7, 2023
8ce4051
removing count from the extension
amankumarrr Aug 7, 2023
ceb355b
Wrapping the array inside the bracket
amankumarrr Aug 7, 2023
6e1b01d
Updating counting logic
amankumarrr Aug 7, 2023
508c8b9
adding tsv output for the slot name
amankumarrr Aug 7, 2023
c3e634f
Replacing the prefix of PR names
amankumarrr Aug 7, 2023
b04cc1e
Getting Slots ids to compare it with
amankumarrr Aug 7, 2023
f35d086
Adding logic to extract missing slots
amankumarrr Aug 7, 2023
7ff559e
Adding comments for the step
amankumarrr Aug 7, 2023
103db0b
Replacing the InputObject to SideIndicator to handle error
amankumarrr Aug 7, 2023
ccbf57b
Wrapping the object with double quote
amankumarrr Aug 7, 2023
f13ea4e
Logic to extract unique values
amankumarrr Aug 7, 2023
75d55e9
Unique id from the object
amankumarrr Aug 7, 2023
65e9656
Adding logic for the extraction of Slots ids
amankumarrr Aug 8, 2023
f360e60
wrapping the arrays in double quotes
amankumarrr Aug 8, 2023
3b833bd
Fixing typo with variable name
amankumarrr Aug 8, 2023
1aebc0a
Renaming variables
amankumarrr Aug 8, 2023
27c4742
Adding scheduler for the action
amankumarrr Aug 8, 2023
3c322a4
Adding workflow dispatcher
amankumarrr Aug 8, 2023
d8163b9
Adding workflow dispatch with the pull request
amankumarrr Aug 8, 2023
52fb118
removing variable with dispatcher
amankumarrr Aug 8, 2023
d21a7d7
Modifying the delete flow and adding trigger for in the new flow
amankumarrr Aug 8, 2023
15199df
Updating syntax
amankumarrr Aug 8, 2023
1fa664e
wrapping the curl request with `
amankumarrr Aug 8, 2023
d0344b5
Curl - changing the syntax
amankumarrr Aug 8, 2023
abb326d
Adding third party action to trigger the workflow
amankumarrr Aug 8, 2023
9c4db2c
Adding ref for the main branch
amankumarrr Aug 8, 2023
cb7c52b
adding the extention to find the yml
amankumarrr Aug 8, 2023
f3bfadf
Removing repo name since it's in same repo
amankumarrr Aug 8, 2023
2b672b1
removing the input for the flow
amankumarrr Aug 8, 2023
4b1402c
updating flow to callable flow and calling it from the flow itself
amankumarrr Aug 8, 2023
8a32088
Converting the input into json
amankumarrr Aug 8, 2023
0e6a2b3
adding the callable flow in separate action
amankumarrr Aug 8, 2023
5a5ec91
Inheriting secrets
amankumarrr Aug 8, 2023
a33130b
Updating the slot logic
amankumarrr Aug 8, 2023
5eca700
adding check to echo the array
amankumarrr Aug 8, 2023
cc19752
adding check for the second job
amankumarrr Aug 8, 2023
84a3861
changing array to a single id
amankumarrr Aug 8, 2023
6235f89
Clean up
amankumarrr Aug 8, 2023
2ede1c3
Updating the variable name
amankumarrr Aug 9, 2023
e047cf9
displaying the variable
amankumarrr Aug 9, 2023
4413e89
Adding firstSlotId
amankumarrr Aug 9, 2023
187a709
Changing the logic to compare the PR slots
amankumarrr Aug 9, 2023
0fc4689
fixing typo
amankumarrr Aug 9, 2023
e2280f2
Adding logic for single slot id
amankumarrr Aug 9, 2023
f7656d8
Slot id in an array
amankumarrr Aug 9, 2023
028d5bc
Adding second check to avoid to avoid running second flow
amankumarrr Aug 9, 2023
f55e18b
Putting variable to outside of condition to update itself
amankumarrr Aug 9, 2023
23b1a6e
Adding schedule to run the flow
amankumarrr Aug 9, 2023
1b10738
fixing typo
amankumarrr Aug 9, 2023
f4dd28d
Adding logic to run it for multiple ids
amankumarrr Aug 9, 2023
1457b0a
removing comment
amankumarrr Aug 9, 2023
7bc1f4a
fixing the variable name
amankumarrr Aug 9, 2023
0794bf0
adding json in the variable list
amankumarrr Aug 9, 2023
f0d5b86
spliting the input
amankumarrr Aug 9, 2023
56a99e1
removing fromJSON to matrix
amankumarrr Aug 9, 2023
59ee4ac
adding json
amankumarrr Aug 9, 2023
2af222a
adding the comma and formatting it in Json
amankumarrr Aug 9, 2023
35b2d43
adding the slotname in output
amankumarrr Aug 9, 2023
d16bac7
testing the object type
amankumarrr Aug 9, 2023
7c06a76
setting up the variable name
amankumarrr Aug 9, 2023
c9e24d3
testing param
amankumarrr Aug 9, 2023
30c1e74
removing hardcoded values
amankumarrr Aug 9, 2023
f7b3e33
testing with variable name
amankumarrr Aug 9, 2023
9c9be79
changing the syntax for output
amankumarrr Aug 9, 2023
41be2b1
changing into an array
amankumarrr Aug 9, 2023
22ef157
changing the variable wrapping
amankumarrr Aug 9, 2023
3a74afe
adding variable from json
amankumarrr Aug 9, 2023
434fae4
putting into json
amankumarrr Aug 9, 2023
3e7322e
Updating the param to JSON
amankumarrr Aug 9, 2023
689b99d
wrapping the ouput
amankumarrr Aug 9, 2023
09d0793
wrapping it with the object
amankumarrr Aug 9, 2023
2e7203b
replacing double quotes with backslashes
amankumarrr Aug 9, 2023
360bc65
fixing typo
amankumarrr Aug 9, 2023
4ce7608
removing the second check
amankumarrr Aug 9, 2023
c0d2e3a
compressing the string
amankumarrr Aug 9, 2023
6386964
removing already formatted json
amankumarrr Aug 9, 2023
0659bc5
changing the variable name
amankumarrr Aug 9, 2023
a61be49
fixing variable name
amankumarrr Aug 9, 2023
bf3d92d
fixing the echo with json
amankumarrr Aug 9, 2023
516f58b
adding string to convert the object
amankumarrr Aug 9, 2023
259b3fa
removing the output thing
amankumarrr Aug 9, 2023
578af7d
removing the step to add the string
amankumarrr Aug 9, 2023
8838989
adding the matrix back
amankumarrr Aug 9, 2023
21c4e75
adding the env
amankumarrr Aug 9, 2023
c2d3cbe
without env
amankumarrr Aug 9, 2023
0d6eba9
adding the text
amankumarrr Aug 9, 2023
fbdbaa6
removing slot and parsing it first
amankumarrr Aug 9, 2023
26cbccf
tesingt output
amankumarrr Aug 9, 2023
b5bb838
checking without env
amankumarrr Aug 9, 2023
e5a964d
with quotes
amankumarrr Aug 9, 2023
1ee1257
adding the json string for testing
amankumarrr Aug 9, 2023
bf48b97
adding double quote
amankumarrr Aug 9, 2023
10e78af
adding new formate
amankumarrr Aug 9, 2023
c5d3728
changing the type of input
amankumarrr Aug 9, 2023
8602ed4
removing some more content
amankumarrr Aug 9, 2023
850f246
without single quotes
amankumarrr Aug 9, 2023
270105b
in double quotes
amankumarrr Aug 9, 2023
271d498
changing the quotes
amankumarrr Aug 9, 2023
600ecda
adding inside the object
amankumarrr Aug 9, 2023
1026870
removing quotes
amankumarrr Aug 9, 2023
7de303e
adding text
amankumarrr Aug 9, 2023
52b1420
joining text
amankumarrr Aug 9, 2023
198ccb8
adding json
amankumarrr Aug 9, 2023
ddae65f
without quote
amankumarrr Aug 9, 2023
c7e80f7
converting from json
amankumarrr Aug 9, 2023
451c63c
adding space between comma's
amankumarrr Aug 9, 2023
4688c55
using actual example
amankumarrr Aug 9, 2023
29474c5
with env
amankumarrr Aug 9, 2023
a543c2b
adding new YML
amankumarrr Aug 9, 2023
aceebd6
assigning hardcoded values
amankumarrr Aug 9, 2023
13bb549
adding hardcoded json
amankumarrr Aug 9, 2023
4435931
single quote
amankumarrr Aug 10, 2023
d64fbae
adding formatted json
amankumarrr Aug 10, 2023
09ea143
Json from the other workflow
amankumarrr Aug 10, 2023
f0a8c14
adding listofslotsFromFirst job
amankumarrr Aug 10, 2023
aa14592
adding json format
amankumarrr Aug 10, 2023
3d42488
wrapping the text
amankumarrr Aug 10, 2023
e7335b1
Separating azure login
amankumarrr Aug 10, 2023
e346e92
Adding the dependencies for the different jobs
amankumarrr Aug 10, 2023
be513c2
reverting back last commit
amankumarrr Aug 10, 2023
f5384de
cleaning up the first flow
amankumarrr Aug 10, 2023
651fe45
adding hardcoded false
amankumarrr Aug 10, 2023
078a5b4
Clean up with the pr-close flow
amankumarrr Aug 10, 2023
686ed51
making naming conventions consistent
amankumarrr Aug 10, 2023
e6a21e5
removing testing yml
amankumarrr Aug 10, 2023
ae962d3
handling single id scenario
amankumarrr Aug 10, 2023
0391dd1
Clean up and check with single id
amankumarrr Aug 10, 2023
948541a
Removing hardcoded values
amankumarrr Aug 10, 2023
bf13041
Clean with the naming conventions
amankumarrr Aug 10, 2023
dc189b8
Adding scheduling to run this flow
amankumarrr Aug 10, 2023
f8ee939
Merge branch 'main' into adding-new-check
amankumarrr Aug 10, 2023
1cfae17
Update .github/workflows/check-active-prs-and-slots.yml
amankumarrr Aug 11, 2023
40ba43e
Update .github/workflows/check-active-prs-and-slots.yml
amankumarrr Aug 11, 2023
4dedf38
Update - camelCase for pr list step
amankumarrr Aug 11, 2023
7913b03
Removing redundant steps
amankumarrr Aug 11, 2023
9e13610
removing the quote to output the slots
amankumarrr Aug 11, 2023
1358e59
echoing slot
amankumarrr Aug 11, 2023
c9b4acf
testing echo
amankumarrr Aug 11, 2023
016ac99
Checking the length of the array
amankumarrr Aug 11, 2023
ba72b7e
Removing double quotes
amankumarrr Aug 11, 2023
780551d
adding bool value to check the next step
amankumarrr Aug 14, 2023
1353f62
updating logic for next flow
amankumarrr Aug 14, 2023
3362dcf
using github cli
amankumarrr Aug 14, 2023
f8e56e0
adding github token as env
amankumarrr Aug 14, 2023
8c09986
Adding hardcoded values
amankumarrr Aug 14, 2023
2b98eb1
Adding hardcoded value to test
amankumarrr Aug 14, 2023
8706bc5
Clean up the hardcoded values
amankumarrr Aug 14, 2023
f5a6428
Removing singular values
amankumarrr Aug 14, 2023
97627e8
adding jq query to get the values
amankumarrr Aug 14, 2023
0182c5b
Removing extra step and cleaning up the code for JSON
amankumarrr Aug 14, 2023
79a6a08
test run for multiple ids
amankumarrr Aug 14, 2023
99e3112
Clean up from hardcoded values
amankumarrr Aug 14, 2023
9b8d3b4
testing json values
amankumarrr Aug 14, 2023
fe9da88
for testing
amankumarrr Aug 14, 2023
1a64a23
testing it with JSOn
amankumarrr Aug 14, 2023
a4c446d
testing
amankumarrr Aug 14, 2023
02d52c7
quoting it
amankumarrr Aug 14, 2023
b6ba3fa
adding the env. slot name
amankumarrr Aug 14, 2023
50652d0
without outputting it
amankumarrr Aug 14, 2023
6656036
Adding the values back
amankumarrr Aug 14, 2023
7fa2c5d
removing from JSON
amankumarrr Aug 14, 2023
d603b08
adding an array for testing
amankumarrr Aug 14, 2023
92501fc
testing
amankumarrr Aug 14, 2023
d52a64e
adding from json
amankumarrr Aug 14, 2023
0650e3f
removing hardcoded values
amankumarrr Aug 14, 2023
ae3fc2b
Content - renaming the filename
amankumarrr Aug 17, 2023
5b34818
Merge branch 'main' into adding-new-check
amankumarrr Aug 17, 2023
81a709f
Update .github/workflows/slots-cleanup-weekly.yml
amankumarrr Aug 17, 2023
17af89f
File - renaming it to make more sense
amankumarrr Aug 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions .github/workflows/pr-close-delete-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,48 @@ on:
types: [closed]
workflow_dispatch:
inputs:
environment:
slotID:
description: "Pull request number"
required: true
default: ""
workflow_call:
inputs:
slotIDs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a json serialized array instead of space delimited values. That way you can use fromJson on it when defining the matrix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend json array and not space delimited (and apply to other slotIds param)

type: string
description: "Slot IDs"
required: true

defaults:
run:
shell: pwsh

env:
SLOT_NAME: pr-${{ github.event.number }}

SLOT_NAME: ${{ inputs.slotIDs || inputs.slotID || github.event.number }}
amankumarrr marked this conversation as resolved.
Show resolved Hide resolved
SLOT_PREFIX: pr-
permissions:
id-token: write
contents: read

jobs:
setting-up-slot-ids:
amankumarrr marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Converting slots into JSON Formatted Array
id: set-matrix
run: |
# TODO: Tech Debt - need to use it as JSON instead of space delimited - Github issue - https://github.com/SSWConsulting/SSW.Website/issues/1228
$slotIDs = '${{ env.SLOT_NAME }}' -split ' '
$slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs)
echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT

delete-slot:
runs-on: ubuntu-latest
needs: setting-up-slot-ids
strategy:
matrix:
SLOT_NAME: ${{ fromJson(needs.setting-up-slot-ids.outputs.matrix) }}

steps:
- uses: actions/checkout@v3
Expand All @@ -32,7 +55,6 @@ jobs:
uses: xom9ikk/dotenv@v2
with:
path: ./.github
load-mode: strict

- name: Azure CLI - Login
uses: azure/login@v1
Expand All @@ -41,7 +63,7 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Cleanup ACRPull & KeyVault permission
- name: Cleanup ACR Pull & Key Vault permission
run: |
$acrId = az acr show `
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} `
Expand All @@ -54,7 +76,7 @@ jobs:
$identityId = az webapp identity show `
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} `
--name ${{ env.APP_SERVICE_NAME }} `
--slot ${{ env.SLOT_NAME }} `
--slot ${{ env.SLOT_PREFIX }}${{ matrix.SLOT_NAME }} `
--query principalId `
--output tsv
Write-Host '✅ slot identity found'
Expand Down Expand Up @@ -92,5 +114,5 @@ jobs:
az webapp deployment slot delete `
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} `
--name ${{ env.APP_SERVICE_NAME }} `
--slot ${{ env.SLOT_NAME }} `
--slot ${{ env.SLOT_PREFIX }}${{ matrix.SLOT_NAME }} `
--output none
89 changes: 89 additions & 0 deletions .github/workflows/weekly-slots-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Weekly app service slot cleanup

on:
schedule:
# Monday at 12 PM UTC - https://cron.help/#0_12_*_*_MON
- cron: "0 12 * * MON"
workflow_dispatch:

env:
GH_TOKEN: ${{ github.token }}

defaults:
run:
shell: pwsh

permissions:
id-token: write
contents: read

jobs:
check-pr-slots:
runs-on: ubuntu-latest
outputs:
slotsExistThatRequireDeletion: ${{ steps.comparision.outputs.slotsExistThatRequireDeletion }}

steps:
- name: Checking out
uses: actions/checkout@v2

- name: Load .env file
uses: xom9ikk/dotenv@v2
with:
path: ./.github

- name: Azure CLI - Login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Get list of deployed Slots
id: slotList
run: |
$slots = $(az webapp deployment slot list `
--name ${{ env.APP_SERVICE_NAME }} `
--resource-group ${{env.AZURE_RESOURCE_GROUP }} `
--query '[].name' `
--output tsv | `
sed 's/pr-//g')
echo "slots=$slots" >> $env:GITHUB_OUTPUT

- name: Get list of active PRs
id: prList
run: |
$active_prs=$(gh pr list --state open --json number | jq -r '.[].number')
echo "active_prs=$active_prs" >> $env:GITHUB_OUTPUT

- name: Compare PRs with Slots
id: comparision
run: |
# Comparing the number of Slots and PRs
$prList = "${{ steps.PRList.outputs.active_prs }}" -split ' '
$slotList = "${{ steps.slotList.outputs.slots }}" -split ' '

$slotsExistThatRequireDeletion = $slotList | Where-Object { $_ -notin $prList }
$slotsNeedDeletion = $slotsExistThatRequireDeletion.Length -gt 0

if ( ! $slotsNeedDeletion ) {
echo "✅ - Number of slots are equal to number of active PRs - 🏃 Skipping next step"
}
else {
echo "❌ - Number of slots are not equal to number of active PRs"
Write-Host "⚡- These slots need to be deleted : $slotsExistThatRequireDeletion"
}
echo "slotsExistThatRequireDeletion=$slotsExistThatRequireDeletion" >> $env:GITHUB_OUTPUT

invokeDeleteSlot:
name: Invoking PR Close/Delete
needs:
- check-pr-slots #Adding second check to avoid running this flow
if: needs.check-pr-slots.outputs.slotsExistThatRequireDeletion != ''
uses: ./.github/workflows/pr-close-delete-env.yml
with:
slotIDs: ${{ needs.check-pr-slots.outputs.slotsExistThatRequireDeletion }}
permissions:
id-token: write
contents: read
secrets: inherit
Loading