-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (144 loc) · 5.69 KB
/
ciCreatePlatformPool.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
poolMatrixDefPath:
description: "Path to the file describing the pools to create"
required: false
default: "config/poolMatrixdef.json"
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"
poolMatrixDefPath:
description: "Path to the file describing the pools to create"
required: true
default: "config/poolMatrixdef.json"
clearPools:
description: "If checked, clear unused scratches in the pools"
required: true
default: "false"
jobs:
checkScratchLimitsThreshold:
name: "Check Scratch limits"
runs-on: ubuntu-latest
outputs:
canReplenishPool: ${{ steps.checkLimits.outputs.canReplenishPool }}
steps:
- name: Setup SF CLI
uses: navikt/sf-platform/.github/actions/installSfCli@main
with:
version: ${{ vars.SF_CLI_VERSION }}
- name: "Authenticate Dev Hub"
uses: navikt/sf-platform/.github/actions/authenticateOrg@main
with:
auth-url: ${{ secrets.SF_DEVHUB_URL }}
alias: devhub
- name: "Check scratch org limits"
id: checkLimits
run: |
printf 'get org limits...\n' >&2
sf org list limits --target-org devhub --json >> limits.json
remainingDailyScratchOrgs=$(jq '.result[] | select(.name=="DailyScratchOrgs").remaining' limits.json)
maxDailyScratchOrgs=$(jq '.result[] | select(.name=="DailyScratchOrgs").max' limits.json)
remainingActiveScratchOrgs=$(jq '.result[] | select(.name=="ActiveScratchOrgs").remaining' limits.json)
maxActiveScratchOrgs=$(jq '.result[] | select(.name=="ActiveScratchOrgs").max' limits.json)
rm limits.json
echo "canReplenishPool=true" >> "$GITHUB_OUTPUT"
printf 'Check remaining daily scratch orgs\n' >&2
if [ $remainingDailyScratchOrgs -lt ${{ vars.POOL_REMAINING_DAILY_SCRATCH_ORG_LIMIT }} ]
then
echo "::warning title=To few remaining daily scratch orgs::Max daily scatch orgs: $maxDailyScratchOrgs. Remaining daily scratch orgs: $remainingDailyScratchOrgs. Threshold: ${{ vars.POOL_REMAINING_DAILY_SCRATCH_ORG_LIMIT }}."
echo "canReplenishPool=" >> "$GITHUB_OUTPUT"
fi
printf 'Check remaining active scratch orgs\n' >&2
if [ $remainingActiveScratchOrgs -lt ${{ vars.POOL_REMAINING_ACTIVE_SCRATCH_ORG_LIMIT }} ]
then
echo "::warning title=To many active Scratch Orgs::Max active scratch orgs: $maxActiveScratchOrgs. Remaining scratch orgs: $remainingActiveScratchOrgs. Threshold: ${{ vars.POOL_REMAINING_ACTIVE_SCRATCH_ORG_LIMIT }}."
echo "canReplenishPool=" >> "$GITHUB_OUTPUT"
fi
prepareMatrix:
runs-on: ubuntu-latest
outputs:
matrixJson: ${{ steps.getMatrix.outputs.matrixJson }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
- id: getMatrix
run: |
content=$(jq --compact-output '.' ${{ inputs.poolMatrixDefPath }})
echo "matrixJson=$content" >> "$GITHUB_OUTPUT"
- name: Debug matrixJson
run: |
echo "Matrix JSON: ${{ steps.getMatrix.outputs.matrixJson }}"
createPool:
name: "Replenish Pool"
needs: [prepareMatrix, checkScratchLimitsThreshold]
if: needs.checkScratchLimitsThreshold.outputs.canReplenishPool
runs-on: ubuntu-latest
container: ghcr.io/flxbl-io/sfp:${{ vars.SFP_CONTAINER_VERSION }}
timeout-minutes: 720 #Set to Maximum Time out
strategy:
matrix:
pool: ${{ fromJson(needs.prepareMatrix.outputs.matrixJson).pools }}
permissions:
contents: read
packages: read
env:
POOL_TAG: ""
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
fetch-depth: 0
- name: Set pool tag
run: |
pooltag=$(jq --raw-output '.tag' ${{ matrix.pool.poolConfigPath }})
echo "POOL_TAG=$pooltag" >> $GITHUB_ENV
- name: Print Vaules
run: |
echo Pool Tag: "$POOL_TAG"
echo Pool Config Path: ${{ matrix.pool.poolConfigPath }}
echo Pool Delete Job Type: ${{ matrix.pool.deleteJobType }}
echo Clear unused scratch orgs: ${{ inputs.clearPools }}
- name: "Authenticate Dev Hub"
uses: navikt/sf-platform/.github/actions/authenticateOrg@main
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.pool.deleteJobType }}
- name: "Create Pool"
uses: navikt/sf-platform/.github/actions/ciCreatePool@main
with:
devhub: "devhub"
poolConfigPath: ${{ matrix.pool.poolConfigPath }}
nodeToken: ${{ secrets.GITHUB_TOKEN }}
- name: "Delete orphans"
uses: navikt/sf-platform/.github/actions/ciDeletePool@main
with:
devhub: "devhub"
deleteJobType: orphans