From 08f6cc5b0336d5ce6e5e9955919a755b5e43edd8 Mon Sep 17 00:00:00 2001 From: Christian Meesters Date: Sat, 18 Jan 2025 21:11:47 +0100 Subject: [PATCH 1/4] fix: ci runner ought to start now upon merge to main --- .github/workflows/post_to_mastodon.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/post_to_mastodon.yml b/.github/workflows/post_to_mastodon.yml index c84fb5cd..f9cf3260 100644 --- a/.github/workflows/post_to_mastodon.yml +++ b/.github/workflows/post_to_mastodon.yml @@ -1,11 +1,11 @@ name: Post to Mastodon on PR Merge on: - push: - branches: - - main + pull_request: types: - closed + branches: + - main permissions: pull-requests: read From 84849fbb236eb34ceca92a86fcf0bd7cf4d74128 Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 22 Jan 2025 10:39:30 +0100 Subject: [PATCH 2/4] fix: yet another attempt to run this thing upon releasing a new version --- .github/workflows/post_to_mastodon.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/post_to_mastodon.yml b/.github/workflows/post_to_mastodon.yml index c95c7e2a..e35a33db 100644 --- a/.github/workflows/post_to_mastodon.yml +++ b/.github/workflows/post_to_mastodon.yml @@ -13,7 +13,7 @@ permissions: jobs: post_to_mastodon: if: | - github.event.pull_request.merged == true && + ${{ github.event.pull_request.merged }} && (contains(github.event.pull_request.title, 'release') || contains(github.event.pull_request.title, ' v') || contains(github.event.pull_request.title, 'version')) runs-on: ubuntu-latest steps: From bc89c43aa54700e3380f20456a3680d26a293d37 Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 22 Jan 2025 14:24:45 +0100 Subject: [PATCH 3/4] fix: restricting to releases --- .github/workflows/post_to_mastodon.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index 20a65a23..3ddc024e 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -1,11 +1,20 @@ #!/bin/bash # Extract version from PR tag passed as environment variable -if [ -z "${PR_TITLE}" ]; then # apparently unset, workflow broken? +if [ -z "${PR_TITLE}" ]; then echo "Error: 'PR_TITLE' environment variable is not set." exit 1 fi -version="${PR_TITLE##* }" + +# Check if this is a release PR +if [[ ! "${PR_TITLE}" =~ ^chore\(main\):\ release ]]; then + echo "Not a release PR, skipping Mastodon post" + exit 0 +fi + +# Extract version (everything after "release ") +version="${PR_TITLE#*release }" + # Validate version format if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then From b6a18b5f05c61c33f06abc4b1d2bc63e82aac0f5 Mon Sep 17 00:00:00 2001 From: meesters Date: Wed, 22 Jan 2025 14:37:58 +0100 Subject: [PATCH 4/4] feat: regex extract of version number --- .github/workflows/post_to_mastodon.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/post_to_mastodon.sh b/.github/workflows/post_to_mastodon.sh index 3ddc024e..8ca429ed 100644 --- a/.github/workflows/post_to_mastodon.sh +++ b/.github/workflows/post_to_mastodon.sh @@ -13,8 +13,12 @@ if [[ ! "${PR_TITLE}" =~ ^chore\(main\):\ release ]]; then fi # Extract version (everything after "release ") -version="${PR_TITLE#*release }" - +if [[ "${PR_TITLE}" =~ [Rr]elease[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+) ]]; then + version="${BASH_REMATCH[1]}" +else + echo "Error: Could not extract version number from PR title" + exit 1 +fi # Validate version format if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then