Skip to content

Commit 5b469ee

Browse files
committed
Omskrevet litt i scriptet
1 parent 62dcdeb commit 5b469ee

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

.github/workflows/buildAndPublish.yml

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,62 @@ jobs:
4343
4444
- name: "Check for changes in src folder"
4545
run: |
46+
printf -v red '\033[0;31m'
47+
printf -v yellow '\033[0;33m'
48+
printf -v green '\033[0;32m'
49+
printf -v bold '\033[1m'
50+
printf -v reset '\033[0m'
51+
4652
echo "::group::Check for changes in source code"
47-
echo "Checking if there has been changes to source code by running git diff on the src folder excluding markdown files"
53+
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
54+
echo "${yellow}${bold}Check for changes in source code${reset}"
55+
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
56+
echo ""
57+
echo "${yellow}Checking if there has been changes to source code by running git diff on the src folder excluding markdown files${reset}"
4858
4959
changes=$(git diff HEAD^ HEAD --ignore-all-space --name-only -- src/)
60+
nonMarkdownChanges=""
61+
cancelWorkflow=false
5062
5163
if [ -n "$changes" ]; then
52-
echo "There have been changes!"
53-
changes=$(echo $changes | grep -v '\.md$')
54-
55-
if [ -n "$changes" ]; then
56-
echo "There have been changes to non-Markdown files!"
57-
else
58-
echo "Only change to markdown!"
59-
60-
echo "No changes to non-Markdown files detected. Cancelling the workflow"
61-
62-
# Use GitHub context variables directly
63-
REPO="${{ github.repository }}"
64-
RUN_ID="${{ github.run_id }}"
65-
66-
# API call to cancel the workflow
67-
curl -X POST \
68-
-H "Accept: application/vnd.github.v3+json" \
69-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
70-
"https://api.github.com/repos/$REPO/actions/runs/$RUN_ID/cancel"
71-
72-
# Wait for cancellation to be processed
73-
sleep 5
74-
75-
echo "Cancellation request sent. Note that cancellation might not be immediate."
76-
exit 0 # Explicitly exit with success to avoid running further steps if not needed
77-
fi
64+
echo "${yellow}${bold}Changes:${reset}"
65+
echo "$changes"
66+
nonMarkdownChanges=$(echo $changes | grep -v '\.md$')
7867
else
79-
echo "No Changes"
68+
echo "${yellow}No changes to files in src folder. Cancelling the workflow${reset}"
69+
cancelWorkflow=true
70+
fi
71+
72+
if [ -n "$nonMarkdownChanges" ]; then
73+
echo ""
74+
echo "${green}${bold}There have been changes to non-Markdown files! Start building 🏗️${reset}"
75+
else
76+
echo ""
77+
echo "${yellow}${bold}No changes to non-Markdown files detected. Cancelling the workflow${reset}"
78+
cancelWorkflow=true
79+
fi
80+
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 ""
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
8098
fi
8199
100+
echo ""
101+
echo "${yellow}${bold}------------------------------------------------------------------------------------------${reset}"
82102
echo "::endgroup::"
83103
84104
- name: Authenticate node

0 commit comments

Comments
 (0)