-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpost_to_mastodon.sh
63 lines (45 loc) · 1.93 KB
/
post_to_mastodon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Extract version from PR title passed as environment variable
version="${PR_TITLE##* }"
# Validate version format
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format in PR title: $version"
exit 1
fi
# Construct changelog URL with proper quoting
changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}"
# Maximum character limit for Mastodon posts (on Fediscience: 1500 characters)
MAX_TOOT_LENGTH=500
read -d '\n' message << EndOfText
Beep, Beep - I am your friendly #Snakemake release announcement bot
There is a new release of the Snakemake executor for #SLURM on #HPC systems. Its version is '${version}'!
See ${changelog//\'/\\\'}for details.
Give us some time and you will automatically find it on #Bioconda and #Pypi.
If you want to discuss the release you will find the maintainers here on Mastodon!
If you find any issues, please report them on https://github.com/snakemake/snakemake-executor-plugin-slurm/issues
#Snakemake #HPC #ReproducibleComputing #ReproducibleResearch #OpenScience
EndOfText
# Validate message length
if [ ${#message} -gt $MAX_TOOT_LENGTH ]; then
echo "Error: Message exceeds Fediscience's character limit"
exit 1
fi
# Validate Mastodon token
if [ -z "${MASTODONBOT}" ]; then
echo "Error: MASTODONBOT secret is not set"
exit 1
fi
# Send post to Mastodon with proper quoting and error handling
response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: Bearer ${MASTODONBOT}" \
-F "status=${message}" \
"https://fediscience.org/api/v1/statuses")
status_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed '$d')
if [ "$status_code" -ne 200 ]; then
echo "Error: Failed to post to Mastodon (HTTP ${status_code})"
echo "Response: ${response_body}"
exit 1
fi
echo "Successfully posted to Mastodon"