Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improved Mastodon Bot #183

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/post_to_mastodon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,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=1500


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!
@[email protected] and @[email protected]

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"
14 changes: 5 additions & 9 deletions .github/workflows/post_to_mastodon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ jobs:
with:
timeout_minutes: 2
max_attempts: 3
command: |
curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \
-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." \
https://fediscience.org/api/v1/statuses \
-w "\nResponse code: %{http_code}\n" \
-f || {
echo "Failed to post to Mastodon"
exit 1
}
run: |
git checkout ${{ github.event.pull_request.head.sha }}
export MASTODONBOT="${{ secrets.MASTODONBOT }}"
export PR_TITLE="${{ github.event.pull_request.title }}"
./post_to_mastodon.sh
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
poetry.lock

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

poetry.lock
.aider*
Loading