Skip to content

Commit 45d5655

Browse files
committed
chore: Ny workflow for push/pr
Forsøk på å forhindre at flere jobber kjører i parallell når vi dytter noe til en branch med en åpen PR
1 parent af6dd52 commit 45d5655

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: ON PUSH OR PR FEATURE BRANCH
2+
run-name:
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
paths:
8+
- "src/**"
9+
pull_request:
10+
branches-ignore:
11+
- main
12+
paths:
13+
- "src/**"
14+
workflow_dispatch:
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref_name }}
17+
jobs:
18+
staticCodeValidation:
19+
name: Validation jobs
20+
uses: navikt/sf-platform/.github/workflows/ciStaticCodeValidation.yml@main
21+
permissions:
22+
contents: read
23+
security-events: write
24+
25+
# Detect changes in the src directory
26+
# The job is executed on the ubuntu-latest runner
27+
# It runs after the staticCodeValidation job
28+
checkChanges:
29+
name: Check changes
30+
runs-on: ubuntu-latest
31+
outputs:
32+
hasSrcChanges: ${{ steps.checkChanges.outputs.hasSrcChanges }}
33+
permissions:
34+
contents: read
35+
steps:
36+
# Checkout the repository
37+
- name: "Checkout"
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
39+
with:
40+
fetch-depth: 0
41+
persist-credentials: false
42+
43+
# Check for changes in the src directory excluding .md files
44+
- uses: navikt/sf-platform/.github/actions/checkForPackageChanges@5a37e9b86c238d23ec7bc31cd8d437daaad6e952
45+
id: checkChanges
46+
47+
# Validate changes
48+
# The job is executed on the ubuntu-latest runner in a container with the SFP CLI installed
49+
# It runs after the checkChanges job and only if there are changes to the packages detected
50+
# It uses the SFP CLI to validate the changes
51+
# It also handles the case where the validation fails and deletes the scratch org
52+
# It uploads the build artifacts and logs generated during the validation process
53+
validateChanges:
54+
name: Validate changes
55+
needs: ["checkChanges", "staticCodeValidation"]
56+
if: ${{ github.event_name == 'workflow_dispatch' || needs.checkChanges.outputs.hasSrcChanges == 'true' }}
57+
runs-on: ubuntu-latest
58+
container: ghcr.io/flxbl-io/sfp:${{ vars.SFP_CONTAINER_VERSION }}
59+
permissions:
60+
contents: read
61+
packages: write
62+
env:
63+
POOLS: ${{ vars.DEFAULT_CI_POOL }}
64+
DEVHUB_ALIAS: "devhub"
65+
COVERAGE_PERCENT: ${{ vars.CODE_COVERAGE_PERCENTAGE }}
66+
SFP_LOG_LEVEL: ${{ vars.SFP_LOG_LEVEL }}
67+
EVENT: ${{ github.event_name }}
68+
steps:
69+
# Checkout the repository
70+
- name: "Checkout"
71+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
72+
with:
73+
fetch-depth: 0
74+
persist-credentials: true
75+
76+
# Authenticate with DevHub
77+
- name: Authenticate DevHub
78+
uses: navikt/sf-platform/.github/actions/authenticateOrg@8cb5b2d5a19ce8ccfd5c4ee95cecddc4d5fa984f
79+
with:
80+
auth-url: ${{ secrets.SF_DEVHUB_URL }}
81+
alias: "devhub"
82+
setDefaultDevhubUsername: "true"
83+
84+
# Quickbuild on push
85+
# This step is only executed on push events
86+
- name: "Quickbuild package"
87+
id: quickbuildPackage
88+
if: ${{ env.EVENT == 'push' }}
89+
shell: bash
90+
run: |
91+
sfp quickbuild --devhubalias devhub --diffcheck --buildnumber ${GITHUB_RUN_ID} --branch ${GITHUB_REF#refs/heads/} --loglevel ${SFP_LOG_LEVEL}
92+
93+
# Validate against CI Pool
94+
# This step is only executed on pull_request events
95+
# It validates the changes against the CI pool
96+
# and deletes the scratch org after validation
97+
# It also handles the case where the validation fails
98+
# and deletes the scratch org
99+
- name: "Validate against CI Pool"
100+
if: ${{ env.EVENT == 'pull_request' || env.EVENT == 'workflow_dispatch' }}
101+
run: |
102+
command=("sfp" "validate" "pool")
103+
command+=("--pools" "${POOLS}")
104+
command+=("--targetdevhubusername" "${DEVHUB_ALIAS}")
105+
command+=("--mode" "${MODE}")
106+
command+=("--logsgroupsymbol" "::group::,::endgroup::")
107+
command+=("--loglevel" "${SFP_LOG_LEVEL}")
108+
109+
if [ "${COVERAGE_PERCENT}" ]; then
110+
command+=("--coveragepercent" "${COVERAGE_PERCENT}")
111+
fi
112+
113+
if [ "${REF}" ]; then
114+
command+=( "--ref" "${REF}" )
115+
fi
116+
117+
if [ "${BASE_REF}" ]; then
118+
command+=( "--baseRef" "${BASE_REF}" )
119+
fi
120+
121+
if [ "${DELETE_SCRATCH}" == "true" ]; then
122+
command+=("--deletescratchorg")
123+
fi
124+
125+
echo "Executing command: ${command[*]}"
126+
"${command[@]}"
127+
env:
128+
MODE: "thorough"
129+
REF: ${{ github.event.pull_request.head.sha }}
130+
BASE_REF: ${{ github.event.pull_request.base.sha }}
131+
DELETE_SCRATCH: "true"
132+
133+
# Delete the scratch org if the validation fails
134+
# This step is only executed if the validation fails
135+
# It deletes the scratch org to clean up resources
136+
# and prevent stale orgs from accumulating
137+
# It uses the sf org delete command with the -p flag
138+
# to delete the scratch org without confirmation
139+
- name: Delete Stale Validation Org
140+
if: ${{ failure() }}
141+
run: sf org delete scratch -p
142+
143+
# Upload build artifacts and logs if present
144+
# This step is executed regardless of the outcome of the previous steps
145+
# It uploads the artifacts and logs generated during the build process
146+
# It uses the navikt/sf-platform action to upload the artifacts and logs
147+
# The artifacts are uploaded with the name "build-artifacts"
148+
# The logs are uploaded with the name "build-logs"
149+
- name: Upload artifacts and logs
150+
if: always()
151+
uses: navikt/sf-platform/.github/actions/uploadWorkflowArtifactsAndLogs@8cb5b2d5a19ce8ccfd5c4ee95cecddc4d5fa984f
152+
with:
153+
artifactName: "build-artifacts"
154+
uploadArtifacts: true
155+
logName: "build-logs"
156+
publishLogs: true

0 commit comments

Comments
 (0)