From 32dbef3daa5ba28b1286c54ff04fb959b904b69c Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 15 Jan 2025 14:56:05 +0100 Subject: [PATCH 1/8] feat: splitted the code of the yaml file and the script part for the mastodon bot --- .github/workflows/post_to_mastodon.sh | 26 ++++++++++++++++++++++++++ .github/workflows/post_to_mastodon.yml | 11 ++--------- 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/post_to_mastodon.sh diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh new file mode 100644 index 0000000..9e2d8ac --- /dev/null +++ b/.github/workflows/post_to_mastodon.sh @@ -0,0 +1,26 @@ +#!bin/bash + +version="${${{ github.event.pull_request.title }}##* }" +changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}" + +read -d '\n' message << EndOfText +Beep, Beepi - I am the #Snakemake release bot + +I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'. + +See ${changelog} for details. + +Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too. + +#OpenScience #ReproducibleResearch #ReproducibleComputing + +EndOfText + +curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \ + -F "status=${message}" \ + https://fediscience.org/api/v1/statuses \ + -w "\nResponse code: %{http_code}\n" \ + -f || { + echo "Failed to post to Mastodon" + exit 1 + } diff --git a/.github/workflows/post_to_mastodon.yml b/.github/workflows/post_to_mastodon.yml index 72e17f2..f097ca9 100644 --- a/.github/workflows/post_to_mastodon.yml +++ b/.github/workflows/post_to_mastodon.yml @@ -20,12 +20,5 @@ 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: | + ./post_to_mastodon.sh From 92e48937a86368aaad0c3c2e234fdd26ed9b22a9 Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 15 Jan 2025 15:14:18 +0100 Subject: [PATCH 2/8] fix: adjusting environment --- .github/workflows/post_to_mastodon.sh | 0 .github/workflows/post_to_mastodon.yml | 3 +++ 2 files changed, 3 insertions(+) mode change 100644 => 100755 .github/workflows/post_to_mastodon.sh diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh old mode 100644 new mode 100755 diff --git a/.github/workflows/post_to_mastodon.yml b/.github/workflows/post_to_mastodon.yml index f097ca9..b233339 100644 --- a/.github/workflows/post_to_mastodon.yml +++ b/.github/workflows/post_to_mastodon.yml @@ -21,4 +21,7 @@ jobs: timeout_minutes: 2 max_attempts: 3 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 From 41b86c3623157a49da2d576c2d2e3794153c5f0f Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 15 Jan 2025 15:16:14 +0100 Subject: [PATCH 3/8] fix: shebang --- .github/workflows/post_to_mastodon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 .github/workflows/post_to_mastodon.sh diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh old mode 100755 new mode 100644 index 9e2d8ac..36d3935 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -1,4 +1,4 @@ -#!bin/bash +#!/bin/bash version="${${{ github.event.pull_request.title }}##* }" changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}" From 093aeb498a47d8d15496f12dfad1ba0094e7dd21 Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 15 Jan 2025 15:25:58 +0100 Subject: [PATCH 4/8] fix: adjusted script to be saver and will print messages upon failure --- .github/workflows/post_to_mastodon.sh | 53 ++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index 36d3935..9582cc0 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -1,14 +1,27 @@ #!/bin/bash -version="${${{ github.event.pull_request.title }}##* }" +# 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, Beepi - I am the #Snakemake release bot I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'. -See ${changelog} for details. +See ${changelog//\'/\\\'}for details. Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too. @@ -16,11 +29,31 @@ Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to EndOfText -curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \ - -F "status=${message}" \ - https://fediscience.org/api/v1/statuses \ - -w "\nResponse code: %{http_code}\n" \ - -f || { - echo "Failed to post to Mastodon" - exit 1 - } +# 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" From 66f02dfe619f6da4147f2e3f704a09aaf2abf193 Mon Sep 17 00:00:00 2001 From: Christian Meesters Date: Wed, 15 Jan 2025 19:24:44 +0100 Subject: [PATCH 5/8] feat: improved message text --- .github/workflows/post_to_mastodon.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index 9582cc0..b4bc654 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -17,16 +17,20 @@ MAX_TOOT_LENGTH=500 read -d '\n' message << EndOfText -Beep, Beepi - I am the #Snakemake release bot +Beep, Beep - I am your friendly #Snakemake release announcement bot -I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'. +There is a new release of the Snakemake executor for #SLURM on #HPC systems. Its version is '${version}'! See ${changelog//\'/\\\'}for details. -Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too. +Give us some time and you will automatically find it on #Bioconda and #Pypi. -#OpenScience #ReproducibleResearch #ReproducibleComputing +If you want to discuss the release you will find the maintainers here on Mastodon! +@rupdecat@fediscience.org and @johanneskoester@fosstodon.org +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 From 2f3ede9a6d700b19eabf48395d3372c58d5f8f23 Mon Sep 17 00:00:00 2001 From: Christian Meesters Date: Wed, 15 Jan 2025 19:31:25 +0100 Subject: [PATCH 6/8] fix: inserted corrected character limit for fediscience --- .github/workflows/post_to_mastodon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index b4bc654..0603cf7 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -13,7 +13,7 @@ fi 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 +MAX_TOOT_LENGTH=1500 read -d '\n' message << EndOfText From fafbbf32382d0ed91c7d258fb5fc45d1a3d16994 Mon Sep 17 00:00:00 2001 From: Christian Meesters Date: Wed, 15 Jan 2025 19:32:08 +0100 Subject: [PATCH 7/8] fix: added missing space character (typo) --- .github/workflows/post_to_mastodon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index 0603cf7..e1a9eff 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -21,7 +21,7 @@ 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. +See ${changelog//\'/\\\'} for details. Give us some time and you will automatically find it on #Bioconda and #Pypi. From ffbcea5406acae725b271a5cde4ea4e1f8be024a Mon Sep 17 00:00:00 2001 From: Christian Meesters Date: Thu, 16 Jan 2025 13:46:33 +0100 Subject: [PATCH 8/8] fix: added poetry.lock --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bcc3d59..ad6672d 100644 --- a/.gitignore +++ b/.gitignore @@ -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. @@ -159,4 +159,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -poetry.lock \ No newline at end of file +.aider*