Skip to content

Replenish platform pools #21

Replenish platform pools

Replenish platform pools #21

name: "Replenish platform pools"
on:
workflow_call:
inputs:
gitRef:
description: "Commit Id from where the pools should be created"
required: false
default: "main"
type: string
ciPoolConfigPath:
description: "Ci Pool Config Path"
required: true
type: string
devPoolConfigPath:
description: "Dev Pool Config Path"
required: true
type: string
clearPools:
description: "If checked, clear unused scratches in the pools"
required: true
default: false
type: boolean
secrets:
SF_DEVHUB_URL:
required: true
workflow_dispatch:
inputs:
gitRef:
description: "Commit Id from where the pools should be created"
required: false
default: "main"
ciPoolConfigPath:
description: "Ci Pool Config Path"
required: true
default: "config/sf-ci-platform-pool-def.json"
devPoolConfigPath:
description: "Dev Pool Config Path"
required: true
default: "config/sf-platform-pool-def.json"
clearPools:
description: "If checked, clear unused scratches in the pools"
required: true
default: "false"
jobs:
checkScratchLimitsThreshold:
name: "Check Scratch limits threshold"
runs-on: ubuntu-latest
outputs:
isWithinThreshold: ${{ steps.checkLimits.outputs.isWithinThreshold }}
steps:
- uses: navikt/sf-platform/.github/actions/installSfCli@main
- name: "Authenticate Dev Hub"
uses: navikt/sf-platform/.github/actions/authenticateOrg@main
with:
auth-url: ${{ secrets.SF_DEVHUB_URL }}
alias: devhub
- id: checkLimits
run: |
sf org list limits --target-org devhub --json >> limits.json
remainingDailyScratchOrgs=$(jq '.result[] | select(.name=="DailyScratchOrgs").remaining' limits.json)
remainingActiveScratchOrgs=$(jq '.result[] | select(.name=="ActiveScratchOrgs").remaining' limits.json)
rm limits.json
isThresholdPassed=false
# If to few remaining daily scratch orgs, exit
if [ $remainingDailyScratchOrgs -lt ${{ vars.POOL_REMAINING_DAILY_SCRATCH_ORG_LIMIT }} ]
then
echo "::error title=Close to remaining Daily Scratch Org Limit::Remaining DailyScratchOrgs: $remainingDailyScratchOrgs"
$isThresholdPassed=true
fi
# If to few remaining active scratch orgs, exit
if [ $remainingActiveScratchOrgs -lt ${{ vars.POOL_REMAINING_ACTIVE_SCRATCH_ORG_LIMIT }} ]
then
echo "::error title=Close to remaining Active Scratch Orgs::Remaining ActiveScratchOrgs: $remainingActiveScratchOrgs"
$isThresholdPassed=true
fi
if [$isThresholdPassed]
then
echo "isWithinThreshold=false" >> "$GITHUB_OUTPUT"
fi
createPool:
name: "Replenish Pool"
needs: checkScratchLimitsThreshold
if: ${{ needs.checkScratchLimitsThreshold.outputs.isWithinThreshold }}
runs-on: ubuntu-latest
container: ghcr.io/flxbl-io/sfp:${{ vars.SFP_CONTAINER_VERSION }}
timeout-minutes: 720 #Set to Maximum Time out
strategy:
matrix:
include:
- poolType: "CI"
poolConfigPath: ${{ inputs.ciPoolConfigPath }}
deleteJobType: allscratchorgs
- poolType: "DEV"
poolConfigPath: ${{ inputs.devPoolConfigPath }}
deleteJobType: unassigned
permissions:
contents: read
packages: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
fetch-depth: 0
- name: Get pool tag
run: |
pooltag=$(jq --raw-output '.tag' ${{ matrix.poolConfigPath }})
echo "POOL_TAG=$pooltag" >> $GITHUB_ENV
- name: Print Vaules
run: |
echo Pool Tag: "$POOL_TAG"
echo Pool Type: ${{ matrix.poolType }}
echo Pool Config Path: ${{ matrix.poolConfigPath }}
echo Pool Delete Job Type: ${{ matrix.deleteJobType }}
echo Clear unused scratch orgs: ${{ inputs.clearPools }}
- name: "Authenticate Dev Hub"
uses: navikt/sf-platform/.github/actions/authenticateOrg@dxAtScale
with:
auth-url: ${{ secrets.SF_DEVHUB_URL }}
alias: devhub
- name: "Clear pool"
id: clearPool
if: ${{ github.event.schedule == '15 2 * * *' }}
uses: navikt/sf-platform/.github/actions/ciDeletePool@main
with:
devhub: "devhub"
poolTag: ${{ env.POOL_TAG }}
deleteJobType: ${{ matrix.deleteJobType }}
- name: "Create Pool"
uses: navikt/sf-platform/.github/actions/ciCreatePool@main
with:
devhub: "devhub"
poolConfigPath: ${{ matrix.poolConfigPath }}
nodeToken: ${{ secrets.GITHUB_TOKEN }}
- name: "Delete orphans"
uses: navikt/sf-platform/.github/actions/ciDeletePool@main
with:
devhub: "devhub"
deleteJobType: orphans