Skip to content

Commit f271f75

Browse files
committed
Nytt steg som kansellerer workflowen dersom det ikke er endringer av kildekode
1 parent 75bc26f commit f271f75

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/buildAndPublish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ jobs:
3535
with:
3636
fetch-depth: 0
3737

38+
- name: "Check for changes in src folder"
39+
run: |
40+
echo "::group::Check for changes in source code"
41+
echo "Checking if there has been changes to source code by running git diff on the src folder excluding markdown files"
42+
43+
if changes=$(git diff HEAD^ HEAD --ignore-all-space --name-only -- src/ | grep -v '\.md$' 2>&1); then
44+
if [ -n "$changes" ]; then
45+
echo "There have been changes to non-Markdown files!"
46+
else
47+
echo "No changes to non-Markdown files detected. Cancelling the workflow"
48+
49+
# Use GitHub context variables directly
50+
REPO="${{ github.repository }}"
51+
RUN_ID="${{ github.run_id }}"
52+
53+
# API call to cancel the workflow
54+
curl -X POST \
55+
-H "Accept: application/vnd.github.v3+json" \
56+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
57+
"https://api.github.com/repos/$REPO/actions/runs/$RUN_ID/cancel"
58+
59+
# Wait for cancellation to be processed
60+
sleep 5
61+
62+
echo "Cancellation request sent. Note that cancellation might not be immediate."
63+
exit 0 # Explicitly exit with success to avoid running further steps if not needed
64+
fi
65+
else
66+
# If git diff fails for any reason, this block will handle the error
67+
echo "::error title=Error executing git diff::$changes"
68+
exit 1
69+
fi
70+
echo "::endgroup::"
71+
3872
- name: "Set Git Config"
3973
run: |
4074
git config --global user.email "<>"

0 commit comments

Comments
 (0)