Skip to content

Commit 151b0fb

Browse files
authored
feat: Improved Mastodon Bot (#183)
We have a Mastodon release bot. This PR attempts to test a generic message format. It therefore also splits the action yaml into the action definition and the release script for better maintenance. It is an experiment. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an automated Mastodon release notification script for the Snakemake SLURM executor plugin. - Updated GitHub Actions workflow to utilize the new script for posting release updates to Mastodon automatically. - **Chores** - Enhanced the release communication process by abstracting the posting logic into a dedicated shell script for Mastodon notifications. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent da8e6ba commit 151b0fb

File tree

3 files changed

+70
-11
lines changed

3 files changed

+70
-11
lines changed

.github/workflows/post_to_mastodon.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
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
13+
changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}"
14+
15+
# Maximum character limit for Mastodon posts (on Fediscience: 1500 characters)
16+
MAX_TOOT_LENGTH=1500
17+
18+
19+
read -d '\n' message << EndOfText
20+
Beep, Beep - I am your friendly #Snakemake release announcement bot
21+
22+
There is a new release of the Snakemake executor for #SLURM on #HPC systems. Its version is '${version}'!
23+
24+
See ${changelog//\'/\\\'} for details.
25+
26+
Give us some time and you will automatically find it on #Bioconda and #Pypi.
27+
28+
If you want to discuss the release you will find the maintainers here on Mastodon!
29+
@rupdecat@fediscience.org and @johanneskoester@fosstodon.org
30+
31+
If you find any issues, please report them on https://github.com/snakemake/snakemake-executor-plugin-slurm/issues
32+
33+
#Snakemake #HPC #ReproducibleComputing #ReproducibleResearch #OpenScience
34+
EndOfText
35+
36+
# Validate message length
37+
if [ ${#message} -gt $MAX_TOOT_LENGTH ]; then
38+
echo "Error: Message exceeds Fediscience's character limit"
39+
exit 1
40+
fi
41+
42+
# Validate Mastodon token
43+
if [ -z "${MASTODONBOT}" ]; then
44+
echo "Error: MASTODONBOT secret is not set"
45+
exit 1
46+
fi
47+
48+
# Send post to Mastodon with proper quoting and error handling
49+
response=$(curl -s -w "\n%{http_code}" -X POST \
50+
-H "Authorization: Bearer ${MASTODONBOT}" \
51+
-F "status=${message}" \
52+
"https://fediscience.org/api/v1/statuses")
53+
54+
status_code=$(echo "$response" | tail -n1)
55+
response_body=$(echo "$response" | sed '$d')
56+
57+
if [ "$status_code" -ne 200 ]; then
58+
echo "Error: Failed to post to Mastodon (HTTP ${status_code})"
59+
echo "Response: ${response_body}"
60+
exit 1
61+
fi
62+
63+
echo "Successfully posted to Mastodon"

.github/workflows/post_to_mastodon.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ jobs:
2020
with:
2121
timeout_minutes: 2
2222
max_attempts: 3
23-
command: |
24-
curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \
25-
-F "status=New release in Snakemake project '${{ github.event.repository.full_name }}' for pull request '#${{ github.event.pull_request.number }}' merged: '${{ github.event.pull_request.title }}'. Get the latest release from #Bioconda or #Pypi." \
26-
https://fediscience.org/api/v1/statuses \
27-
-w "\nResponse code: %{http_code}\n" \
28-
-f || {
29-
echo "Failed to post to Mastodon"
30-
exit 1
31-
}
23+
run: |
24+
git checkout ${{ github.event.pull_request.head.sha }}
25+
export MASTODONBOT="${{ secrets.MASTODONBOT }}"
26+
export PR_TITLE="${{ github.event.pull_request.title }}"
27+
./post_to_mastodon.sh

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ipython_config.py
9999
# This is especially recommended for binary packages to ensure reproducibility, and is more
100100
# commonly ignored for libraries.
101101
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
102+
poetry.lock
103103

104104
# pdm
105105
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
@@ -159,4 +159,4 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162-
poetry.lock
162+
.aider*

0 commit comments

Comments
 (0)