Skip to content

PR - Adding new check for checking PR and slots counts #61

PR - Adding new check for checking PR and slots counts

PR - Adding new check for checking PR and slots counts #61

name: Check Active PRs and Slots
#on:
# schedule:
# - cron: "0 12 */3 * *" # Schedule to run every 3rd day at 12 PM UTC
# workflow_dispatch:
on:
pull_request:
branches:
- main
defaults:
run:
shell: pwsh
permissions:
id-token: write
contents: read
jobs:
check-pr-slots:
runs-on: ubuntu-latest
outputs:
SlotID: ${{ steps.listOfSlots.outputs.SlotID }}
AreSlotsEqual: ${{steps.comparision.outputs.AreSlotsEqual }}
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
env:
AZURE_CORE_OUTPUT: json
- name: Get list of active PRs
id: PRList
run: |
$active_prs=$(curl -s "https://api.github.com/repos/SSWConsulting/SSW.Website/pulls?state=open" | 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 ' '
$SlotsWithoutPR = $SlotList | Where-Object { $_ -notin $PRList }
$AreSlotsEqual = $SlotsWithoutPR.Length -eq 0
if ( $AreSlotsEqual ) {
echo "✅ - Number of slots are equal to number of active PRs"
}
else {
echo "❌ - Number of slots are not equal to number of active PRs"
}
echo "AreSlotsEqual=$AreSlotsEqual" >> $env:GITHUB_OUTPUT
- name: List of Slots that need to be deleted #if:###{{steps.comparision.outputs.AreSlotsEqual == 'False' }}
id: listOfSlots
run: |
# Split the strings into arrays of numbers
$zzSlotList = "${{ steps.slotList.outputs.slots }}" -split ' '
$zzPRList = "${{ steps.PRList.outputs.active_prs }}" -split ' '
$SlotList = "1165 1174 1190 1183 1112 1111" -split ' '
$PRList = "1190 1183 1174 1165" -split ' '
# Find the values present in $string2 but not in $string1
$SlotsWithoutPR = $SlotList | Where-Object { $_ -notin $PRList }
if ( $SlotsWithoutPR.Length -gt 0 ) {
$SlotIDs = $SlotsWithoutPR -split ' '
$ListOfSlots = $SlotsWithoutPR -join ' '
Write-Host "⚡- These slots need to be deleted : $ListOfSlots"
$SingleSlotID = toJSON($SlotIDs)
#TODO: Currently, we are passing single id, should be passed as an array of IDs
echo "SlotID=$SingleSlotID" >> $env:GITHUB_OUTPUT
} else {
Write-Host "✅ - Some PRs have not their slot deployed!"
}
invokeDeleteSlot:
name: Invoking PR Close/Delete
needs:
- check-pr-slots #Adding second check to avoid running this flow for the second time when SlotID is already in the memory
if: needs.check-pr-slots.outputs.SlotID != '' && needs.check-pr-slots.outputs.AreSlotsEqual == 'False'
uses: ./.github/workflows/pr-close-delete-env.yml

Check failure on line 106 in .github/workflows/check-active-prs-and-slots.yml

View workflow run for this annotation

GitHub Actions / Check Active PRs and Slots

Invalid workflow file

The workflow is not valid. .github/workflows/check-active-prs-and-slots.yml (Line: 106, Col: 11): Input pullRequestIdFromFlow is required, but not provided while calling. .github/workflows/check-active-prs-and-slots.yml (Line: 108, Col: 22): Invalid input, pullRequestId is not defined in the referenced workflow.
with:
pullRequestId: ${{ needs.check-pr-slots.outputs.SlotID }}
permissions:
id-token: write
contents: read
secrets: inherit