Skip to content

Commit 27edfe2

Browse files
committed
Splitte opp i to jobber
1 parent 1c776ba commit 27edfe2

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

.github/workflows/buildAndPublish.yml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212
jobs:
13-
buildAndPublish:
14-
name: Build and Publish
13+
checkChanges:
14+
name: Check changes
1515
# Always run on workflow call and workflow dispatch
1616
# Only run on workflow_run if there has been a change in the src folder,
1717
# excluding markdown files
@@ -23,25 +23,19 @@ jobs:
2323
github.event.workflow_run.conclusion == 'success'
2424
)
2525
}}
26-
2726
runs-on: ubuntu-latest
28-
container: ghcr.io/flxbl-io/sfp:${{ vars.SFP_CONTAINER_VERSION }}
27+
outputs:
28+
continueWorkflow: ${{ steps.checkChanges.outputs.continueWorkflow }}
2929
permissions:
30-
contents: write
31-
packages: write
30+
contents: read
3231
steps:
3332
- name: "Checkout"
3433
uses: actions/checkout@v4
3534
with:
36-
fetch-depth: 0
37-
38-
- name: "Set Git Config"
39-
run: |
40-
git config --global user.email "<>"
41-
git config --global user.name "GitHub Action"
42-
git config --system --add safe.directory "$GITHUB_WORKSPACE"
35+
fetch-depth: 2
4336

4437
- name: "Check for changes in src folder"
38+
id: checkChanges
4539
run: |
4640
printf -v red '\033[0;31m'
4741
printf -v yellow '\033[0;33m'
@@ -53,12 +47,12 @@ jobs:
5347
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
5448
echo "${yellow}${bold}Check for changes in source code${reset}"
5549
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
56-
echo "${newLine}"
50+
5751
echo "${yellow}Checking if there has been changes to source code by running git diff on the src folder excluding markdown files${reset}"
5852
5953
changes=$(git diff HEAD^ HEAD --ignore-all-space --name-only -- src/)
6054
nonMarkdownChanges=""
61-
cancelWorkflow=false
55+
continueWorkflow=true
6256
6357
if [ -n "$changes" ]; then
6458
echo "${yellow}${bold}Changes:${reset}"
@@ -71,35 +65,40 @@ jobs:
7165
else
7266
echo "${newLine}"
7367
echo "${yellow}No changes to non-Markdown files detected. Cancelling the workflow${reset}"
74-
cancelWorkflow=true
68+
continueWorkflow=false
7569
fi
7670
else
71+
echo "${newLine}"
7772
echo "${yellow}No changes to files in src folder. Cancelling the workflow${reset}"
78-
cancelWorkflow=true
73+
continueWorkflow=false
7974
fi
8075
81-
if [ "$cancelWorkflow" = true ]; then
82-
# Use GitHub context variables directly
83-
REPO="${{ github.repository }}"
84-
RUN_ID="${{ github.run_id }}"
85-
86-
# API call to cancel the workflow
87-
curl -X POST \
88-
-H "Accept: application/vnd.github.v3+json" \
89-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
90-
"https://api.github.com/repos/$REPO/actions/runs/$RUN_ID/cancel"
91-
92-
# Wait for cancellation to be processed
93-
sleep 5
94-
95-
echo "${newLine}"
96-
echo "Cancellation request sent. Note that cancellation might not be immediate."
97-
exit 0 # Explicitly exit with success to avoid running further steps if not needed
98-
fi
76+
echo "continueWorkflow=$continueWorkflow" >> "$GITHUB_OUTPUT"
9977
10078
echo "${newLine}"
10179
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
10280
81+
buildAndPublish:
82+
name: Build and Publish
83+
needs: checkChanges
84+
if: ${{ needs.checkChanges.outputs.continueWorkflow == 'true' }}
85+
runs-on: ubuntu-latest
86+
container: ghcr.io/flxbl-io/sfp:${{ vars.SFP_CONTAINER_VERSION }}
87+
permissions:
88+
contents: write
89+
packages: write
90+
steps:
91+
- name: "Checkout"
92+
uses: actions/checkout@v4
93+
with:
94+
fetch-depth: 0
95+
96+
- name: "Set Git Config"
97+
run: |
98+
git config --global user.email "<>"
99+
git config --global user.name "GitHub Action"
100+
git config --system --add safe.directory "$GITHUB_WORKSPACE"
101+
103102
- name: Authenticate node
104103
uses: navikt/sf-platform/.github/actions/authenticateNode@main
105104
if: ${{ github.ref_name == 'refs/heads/main' }}

0 commit comments

Comments
 (0)