Skip to content

Commit 093aeb4

Browse files
committed
fix: adjusted script to be saver and will print messages upon failure
1 parent 41b86c3 commit 093aeb4

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

.github/workflows/post_to_mastodon.sh

+43-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,59 @@
11
#!/bin/bash
22

3-
version="${${{ github.event.pull_request.title }}##* }"
3+
# Extract version from PR title passed as environment variable
4+
version="${PR_TITLE##* }"
5+
6+
# Validate version format
7+
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
8+
echo "Error: Invalid version format in PR title: $version"
9+
exit 1
10+
fi
11+
12+
# Construct changelog URL with proper quoting
413
changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}"
514

15+
# Maximum character limit for Mastodon posts (on Fediscience: 1500 characters)
16+
MAX_TOOT_LENGTH=500
17+
18+
619
read -d '\n' message << EndOfText
720
Beep, Beepi - I am the #Snakemake release bot
821
922
I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'.
1023
11-
See ${changelog} for details.
24+
See ${changelog//\'/\\\'}for details.
1225
1326
Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too.
1427
1528
#OpenScience #ReproducibleResearch #ReproducibleComputing
1629
1730
EndOfText
1831

19-
curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \
20-
-F "status=${message}" \
21-
https://fediscience.org/api/v1/statuses \
22-
-w "\nResponse code: %{http_code}\n" \
23-
-f || {
24-
echo "Failed to post to Mastodon"
25-
exit 1
26-
}
32+
# Validate message length
33+
if [ ${#message} -gt $MAX_TOOT_LENGTH ]; then
34+
echo "Error: Message exceeds Fediscience's character limit"
35+
exit 1
36+
fi
37+
38+
# Validate Mastodon token
39+
if [ -z "${MASTODONBOT}" ]; then
40+
echo "Error: MASTODONBOT secret is not set"
41+
exit 1
42+
fi
43+
44+
# Send post to Mastodon with proper quoting and error handling
45+
response=$(curl -s -w "\n%{http_code}" -X POST \
46+
-H "Authorization: Bearer ${MASTODONBOT}" \
47+
-F "status=${message}" \
48+
"https://fediscience.org/api/v1/statuses")
49+
50+
status_code=$(echo "$response" | tail -n1)
51+
response_body=$(echo "$response" | sed '$d')
52+
53+
if [ "$status_code" -ne 200 ]; then
54+
echo "Error: Failed to post to Mastodon (HTTP ${status_code})"
55+
echo "Response: ${response_body}"
56+
exit 1
57+
fi
58+
59+
echo "Successfully posted to Mastodon"

0 commit comments

Comments
 (0)