|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
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 |
4 | 13 | changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}"
|
5 | 14 |
|
| 15 | +# Maximum character limit for Mastodon posts (on Fediscience: 1500 characters) |
| 16 | +MAX_TOOT_LENGTH=500 |
| 17 | + |
| 18 | + |
6 | 19 | read -d '\n' message << EndOfText
|
7 | 20 | Beep, Beepi - I am the #Snakemake release bot
|
8 | 21 |
|
9 | 22 | I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'.
|
10 | 23 |
|
11 |
| -See ${changelog} for details. |
| 24 | +See ${changelog//\'/\\\'}for details. |
12 | 25 |
|
13 | 26 | Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too.
|
14 | 27 |
|
15 | 28 | #OpenScience #ReproducibleResearch #ReproducibleComputing
|
16 | 29 |
|
17 | 30 | EndOfText
|
18 | 31 |
|
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