From d6aca7094ab4fd37b647ffbf89f29c920c807859 Mon Sep 17 00:00:00 2001 From: Adam Cassis Date: Wed, 1 Apr 2026 09:44:23 +0200 Subject: [PATCH] fix: replace CircleCI env vars in post-release Slack notifications Also removes duplicate root-level scripts (post-release.sh, release-wporg.sh) in favor of scripts/github/ versions, and updates the legacy CircleCI job reference in src/jobs/post-release.yml. Co-Authored-By: Claude Opus 4.6 (1M context) --- post-release.sh | 73 ---------------------------------- release-wporg.sh | 49 ----------------------- scripts/github/post-release.sh | 4 +- src/jobs/post-release.yml | 2 +- 4 files changed, 3 insertions(+), 125 deletions(-) delete mode 100755 post-release.sh delete mode 100755 release-wporg.sh diff --git a/post-release.sh b/post-release.sh deleted file mode 100755 index 7bac57a..0000000 --- a/post-release.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash - -# This script should be ran on CI after a new regular (not pre-release) version is released. - -git config user.name "$GIT_COMMITTER_NAME" -git config user.email "$GITHUB_COMMITER_EMAIL" - -# The last commit message at this point is the automated release commit. The second-to-last -# commit message should contain data about the merge. -SECOND_TO_LAST_COMMIT_MSG=$(git log -n 1 --skip 1 --pretty=format:"%s") - -LATEST_VERSION_TAG=$(git describe --tags --abbrev=0) - -git pull origin release -git checkout alpha - -# If the merge was from alpha branch (the basic flow), alpha branch should be reset. -if [[ $(echo $SECOND_TO_LAST_COMMIT_MSG | grep '^Merge .*alpha') ]]; then - echo '[newspack-scripts] Release was created from the alpha branch. Alpha branch will now be reset.' - - # Reset the tip of alpha branch to the release branch. - # The alpha branch is single-serving, just for alpha releases. After a release, - # we don't care about any alpha changes. - git reset --hard release -- - # Force-push the alpha branch. - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" --force -else - echo '[newspack-scripts] Release was created from a different branch than the alpha branch (e.g. a hotfix branch).' - echo '[newspack-scripts] Alpha branch will now be updated with the lastest changes from release.' - git merge --no-ff release -m "chore(release): merge in release $LATEST_VERSION_TAG" - if [[ $? == 0 ]]; then - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" - else - git merge --abort - echo '[newspack-scripts] Post-release merge to alpha failed.' - if [ -z "$SLACK_CHANNEL_ID" ] || [ -z "$SLACK_AUTH_TOKEN" ]; then - echo '[newspack-scripts] Missing Slack channel ID and/or token. Cannot notify.' - else - echo '[newspack-scripts] Notifying the team on Slack.' - curl \ - --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to alpha failed for: \`$CIRCLE_PROJECT_REPONAME\`. Check <$CIRCLE_BUILD_URL|the build> for details.\"}}]}" \ - -H "Content-type: application/json" \ - -H "Authorization: Bearer $SLACK_AUTH_TOKEN" \ - -X POST https://slack.com/api/chat.postMessage \ - -s > /dev/null - fi - fi -fi - -# Update trunk branch with latest changes from the release branch, so they are in sync. -echo '[newspack-scripts] Merging the release branch into trunk.' -git checkout trunk - -# Merge release branch into trunk branch, and notify the team if any conflicts arise. -git merge --no-ff release -m "chore(release): merge in release $LATEST_VERSION_TAG" -if [[ $? == 0 ]]; then - echo '[newspack-scripts] Pushing updated trunk to origin.' - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" -else - git merge --abort - echo '[newspack-scripts] Post-release merge to trunk failed.' - if [ -z "$SLACK_CHANNEL_ID" ] || [ -z "$SLACK_AUTH_TOKEN" ]; then - echo '[newspack-scripts] Missing Slack channel ID and/or token. Cannot notify.' - else - echo '[newspack-scripts] Notifying the team on Slack.' - curl \ - --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to \`trunk\` failed for: \`$CIRCLE_PROJECT_REPONAME\`. Check <$CIRCLE_BUILD_URL|the build> for details.\"}}]}" \ - -H "Content-type: application/json" \ - -H "Authorization: Bearer $SLACK_AUTH_TOKEN" \ - -X POST https://slack.com/api/chat.postMessage \ - -s > /dev/null - fi -fi diff --git a/release-wporg.sh b/release-wporg.sh deleted file mode 100755 index 2d84675..0000000 --- a/release-wporg.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -# Release the latest version on wordpress.org plugin repository. -# To be run as part of CI workflow. -# Assumptions: -# - repository name matches the wordpress.org plugin name or WP_ORG_PLUGIN_NAME is set, -# - there is a `release` directory with the folder containing the files and named as the plugin in it -# Partially adapted from https://carlalexander.ca/continuous-deployment-wordpress-directory-circleci/ - -SVN_PLUGINS_URL="https://plugins.svn.wordpress.org" -SVN_REPO_LOCAL_PATH="release/svn" -WP_ORG_PLUGIN_NAME="${WP_ORG_PLUGIN_NAME:=$CIRCLE_PROJECT_REPONAME}" -SVN_REPO_URL="$SVN_PLUGINS_URL/$WP_ORG_PLUGIN_NAME" - -LATEST_GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) -# Remove the "v" at the beginning of the git tag -LATEST_SVN_TAG=${LATEST_GIT_TAG:1} - -mkdir -p $SVN_REPO_LOCAL_PATH && cd $SVN_REPO_LOCAL_PATH -sudo apt-get update -sudo apt-get install subversion - -# Check if the latest SVN tag exists already -TAG=$(svn ls "$SVN_REPO_URL/tags/$LATEST_SVN_TAG") -error=$? -if [ $error == 0 ]; then - # Tag exists, don't deploy - echo "Latest tag ($LATEST_SVN_TAG) already exists on the WordPress directory. No deployment needed!" - exit 0 -fi - -# Wait a moment to avoid a 429 by WPORG's server. -sleep 3 - -svn checkout -q "$SVN_REPO_URL" . - -rm -rf trunk - -cp -r "../$CIRCLE_PROJECT_REPONAME" ./trunk -cp -r ./trunk "./tags/$LATEST_SVN_TAG" - -# Add new files to SVN -svn stat | grep '^?' | awk '{print $2}' | xargs -I x svn add x@ - -# Remove deleted files from SVN -svn stat | grep '^!' | awk '{print $2}' | xargs -I x svn rm --force x@ - -# Commit to SVN -svn ci --no-auth-cache --username $WP_ORG_USERNAME --password $WP_ORG_PASSWORD -m "Deploy version $LATEST_SVN_TAG" diff --git a/scripts/github/post-release.sh b/scripts/github/post-release.sh index 8e3b48c..0386a2e 100755 --- a/scripts/github/post-release.sh +++ b/scripts/github/post-release.sh @@ -35,7 +35,7 @@ else else echo '[newspack-scripts] Notifying the team on Slack.' curl \ - --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to alpha failed for: \`$CIRCLE_PROJECT_REPONAME\`. Check <$CIRCLE_BUILD_URL|the build> for details.\"}}]}" \ + --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to alpha failed for: \`$GITHUB_REPOSITORY\`. Check <$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|the build> for details.\"}}]}" \ -H "Content-type: application/json" \ -H "Authorization: Bearer $SLACK_AUTH_TOKEN" \ -X POST https://slack.com/api/chat.postMessage \ @@ -61,7 +61,7 @@ else else echo '[newspack-scripts] Notifying the team on Slack.' curl \ - --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to \`trunk\` failed for: \`$CIRCLE_PROJECT_REPONAME\`. Check <$CIRCLE_BUILD_URL|the build> for details.\"}}]}" \ + --data "{\"channel\":\"$SLACK_CHANNEL_ID\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"⚠️ Post-release merge to \`trunk\` failed for: \`$GITHUB_REPOSITORY\`. Check <$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|the build> for details.\"}}]}" \ -H "Content-type: application/json" \ -H "Authorization: Bearer $SLACK_AUTH_TOKEN" \ -X POST https://slack.com/api/chat.postMessage \ diff --git a/src/jobs/post-release.yml b/src/jobs/post-release.yml index 418d190..ce3faa0 100644 --- a/src/jobs/post-release.yml +++ b/src/jobs/post-release.yml @@ -7,4 +7,4 @@ steps: - checkout_with_workspace - run: name: Perform post-release chores - command: ./node_modules/newspack-scripts/post-release.sh + command: ./node_modules/newspack-scripts/scripts/github/post-release.sh