|
| 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" |
0 commit comments