Skip to content

Commit

Permalink
Add trunk rolling release capability to the Autotagger. (#38994)
Browse files Browse the repository at this point in the history
* Added auto-tagger mechanism for rolling trunk releases.

* Added the release from trunk property to wpcomsh.

* Changelog.

* Added a separate autotagger workflow for rolling releases.

* Removing additional logic from the autotagger workflow.

* Moved the rolling mode into the jobs array.

* Fixup versions.

* Added an autorelease flow for rolling releases.

* Removed the autotagger rolling mode step.

* Added the wpcomsh prefix, removed the wpcomsh prefix.

* Project versions.

* Attempt to switch to gh for release creation and artifact upload.

* Added release cleanup.

* Changing the token name to GH_TOKEN.

* Removed requirement for repository and API URL.

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Additional agruments conditional to the rolling release.

* Moved the alpha check into the tag logic block.

* Removed the `--prerelease` parameter from rolling mode releases.

* Using the version and timestamp in the rolling tag.

* Added cleaning up of stale rolling releases.

* Version fixup.

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Update .github/files/gh-autorelease/files/autorelease.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Removed the bottom part of the upload group.

---------

Co-authored-by: Brad Jorsch <[email protected]>
  • Loading branch information
zinigor and anomiex authored Aug 27, 2024
1 parent ab5cd1b commit 9c85d0b
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 92 deletions.
169 changes: 89 additions & 80 deletions .github/files/gh-autorelease/files/autorelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@

set -eo pipefail

: "${GH_TOKEN:?Build argument needs to be set and non-empty.}"
: "${GITHUB_REF:?Build argument needs to be set and non-empty.}"
: "${GITHUB_SHA:?Build argument needs to be set and non-empty.}"
: "${API_TOKEN_GITHUB:?Build argument needs to be set and non-empty.}"
: "${GITHUB_API_URL:?Build argument needs to be set and non-empty.}"
: "${GITHUB_REPOSITORY:?Build argument needs to be set and non-empty.}"

## Determine tag
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v?[0-9]+(\.[0-9]+)+(-[a-z0-9._-]+)?$ ]]; then
echo "::error::Expected GITHUB_REF like \`refs/tags/v1.2.3\` or \`refs/tags/1.2.3\`, got \`$GITHUB_REF\`"
if [[ ! -f composer.json ]]; then
echo '::error::No composer.json. Did it get excluded from the mirror?'
exit 1
fi
TAG="${GITHUB_REF#refs/tags/}"

## Check for alphas
if [[ "$TAG" =~ -(alpha|a\.[0-9]*[02468])$ ]]; then
echo "Not creating a release for alpha version $TAG"
exit 0
fi
echo "Creating release for $TAG"
## Determine tag
ROLLING_MODE=
if [[ "$GITHUB_REF" =~ ^refs/tags/v?[0-9]+(\.[0-9]+)+(-[a-z0-9._-]+)?$ ]]; then
TAG="${GITHUB_REF#refs/tags/}"

## Determine slug and title format.
if [[ ! -f composer.json ]]; then
echo '::error::No composer.json. Did it get excluded from the mirror?'
## Check for alphas
if [[ "$TAG" =~ -(alpha|a\.[0-9]*[02468])$ ]]; then
echo "Not creating a release for alpha version $TAG"
exit 0
fi
elif [[ "$GITHUB_REF" == "refs/heads/trunk" ]]; then
if ! jq -e '.extra.autorelease["rolling-release"]? // false' composer.json > /dev/null; then
echo "::notice::Skipping trunk release because autorelease rolling mode is not enabled."
exit 0
fi
ROLLING_MODE=true
CURRENT_VER=$( sed -nEe 's/^## \[?([^]]*)\]? - .*/\1/;T;p;q' CHANGELOG.md || true )
GIT_SUFFIX=$( git log -1 --format=%h . )
TAG="$CURRENT_VER+rolling.$GIT_SUFFIX"
else
echo "::error::Expected GITHUB_REF like \`refs/tags/v1.2.3\` or \`refs/tags/1.2.3\` or \`refs/heads/trunk\` for rolling releases, got \`$GITHUB_REF\`"
exit 1
fi

echo "Creating release for $TAG"

## Determine slug and title format.
SLUG="$(jq -r '.extra.autorelease.slug? // .extra["wp-plugin-slug"] // .extra["beta-plugin-slug"] // ( .name | sub( "^.*/"; "" ) )' composer.json)"
if [[ -z "$SLUG" ]]; then
echo '::error::Failed to get slug from composer.json.'
Expand All @@ -48,76 +58,75 @@ echo "::group::Creating $SLUG.zip"
git archive -v --output="$SLUG.zip" --prefix="$SLUG/" HEAD 2>&1
echo "::endgroup::"

## Create the release note.
# Extract the changelog section.
echo "::group::Extracting release notes"
if [[ ! -f CHANGELOG.md ]]; then
echo '::endgroup::'
echo '::error::No CHANGELOG.md for release notes.'
exit 1
fi
SCRIPT="
/^## \\[?$(sed 's/[.\[\]\\*^$\/()+?{}|]/\\&/g' <<<"${TAG#v}")\\]? - / {
bc
if [[ -z "$ROLLING_MODE" ]]; then
## Create the release note.
# Extract the changelog section.
echo "::group::Extracting release notes"
if [[ ! -f CHANGELOG.md ]]; then
echo '::endgroup::'
echo '::error::No CHANGELOG.md for release notes.'
exit 1
fi
SCRIPT="
/^## \\[?$(sed 's/[.\[\]\\*^$\/()+?{}|]/\\&/g' <<<"${TAG#v}")\\]? - / {
bc
:a
n
/^## / {
q
}
:c
s/^## \[([^]]+)\]/## \1/
p
ba
}
"
ENTRY=$(sed -n -E -e "$SCRIPT" CHANGELOG.md)
if [[ -z "$ENTRY" ]]; then
echo '::endgroup::'
echo "::error::Failed to find section for ${TAG#v} in CHANGELOG.md"
exit 1
fi

# Strip unwanted sections.
SCRIPT="
:a
n
/^## / {
q
/^### .* This section will not be copied to readme\.txt/ {
:b
n
/^#/ ba
bb
}
:c
s/^## \[([^]]+)\]/## \1/
p
ba
}
"
ENTRY=$(sed -n -E -e "$SCRIPT" CHANGELOG.md)
if [[ -z "$ENTRY" ]]; then
echo '::endgroup::'
echo "::error::Failed to find section for ${TAG#v} in CHANGELOG.md"
exit 1
"
ENTRY=$(sed -n -E -e "$SCRIPT" <<<"$ENTRY")

echo "Release notes:"
echo "-----"
echo "$ENTRY"
echo "-----"
echo "::endgroup::"
else
## Using a brief explanation for the rolling release note.
ENTRY="### Rolling release based on the trunk branch."
fi

if [[ -n "$ROLLING_MODE" ]]; then
echo "::group::Deleting stale rolling release"

for R in $( gh release list --limit 100 --json tagName --jq '.[].tagName | select( contains( "rolling" ) )' ); do
echo "Found $R, deleting"
gh release delete "$R" --cleanup-tag --yes
done

echo "::endgroup::"
fi

# Strip unwanted sections.
SCRIPT="
:a
/^### .* This section will not be copied to readme\.txt/ {
:b
n
/^#/ ba
bb
}
p
"
ENTRY=$(sed -n -E -e "$SCRIPT" <<<"$ENTRY")

echo "Release notes:"
echo "-----"
echo "$ENTRY"
echo "-----"
echo "::endgroup::"

echo "::group::Creating release"
curl -v -L \
--write-out '%{response_code}' \
--output out.json \
--request POST \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--header 'accept: application/vnd.github.v3+json' \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \
--data "$(jq -n --arg tag "$TAG" --arg sha "$GITHUB_SHA" --arg title "$TITLE" --arg body "$ENTRY" '{ tag_name: $tag, target_commitish: $sha, name: $title, body: $body}')" \
2>&1 > code.txt
cat out.json
echo
[[ "$(<code.txt)" =~ ^2[0-9][0-9]$ ]] || exit 1
echo "::endgroup::"
gh release create "$TAG" "$SLUG.zip" \
--notes "$ENTRY" \
--target "$GITHUB_SHA" \
--title "$TITLE"

echo "::group::Uploading artifact to release"
curl -v --fail -L \
--request POST \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header "content-type: application/zip" \
--url "$(jq -r '.upload_url | sub( "{\\?[^}]*}$"; "" )' out.json)?name=$SLUG.zip" \
--data-binary "@$SLUG.zip" \
2>&1
echo "::endgroup::"
4 changes: 3 additions & 1 deletion .github/files/gh-autorelease/workflows/autorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'v?[0-9]+.[0-9]+.[0-9]+-*'
- 'v?[0-9]+.[0-9]+.[0-9]+.[0-9]+'
- 'v?[0-9]+.[0-9]+.[0-9]+.[0-9]+-*'
branches:
- 'trunk'

jobs:
publish:
Expand All @@ -18,5 +20,5 @@ jobs:
- uses: actions/checkout@v4
- name: Create release
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/files/autorelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Added a switch that will enable rolling trunk releases.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


16 changes: 9 additions & 7 deletions projects/plugins/wpcomsh/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,23 @@
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_6_1"
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_6_2_alpha"
},
"extra": {
"mirror-repo": "Automattic/wpcom-site-helper",
"autorelease": true,
"autorelease": {
"rolling-release": true,
"titlefmt": "wpcomsh %s"
},
"autotagger": true,
"beta-plugin-slug": "wpcomsh",
"release-branch-prefix": [
"wpcomsh",
"weekly"
],
"installer-disable": true,
"changelogger": {
"versioning": "semver"
},
"installer-disable": true,
"release-branch-prefix": [
"wpcomsh"
],
"version-constants": {
"WPCOMSH_VERSION": "wpcomsh.php"
}
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@automattic/jetpack-wpcomsh",
"description": "A helper for connecting WordPress.com sites to external host infrastructure.",
"homepage": "https://jetpack.com",
"version": "5.6.1",
"version": "5.6.2-alpha",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: WordPress.com Site Helper
* Description: A helper for connecting WordPress.com sites to external host infrastructure.
* Version: 5.6.1
* Version: 5.6.2-alpha
* Author: Automattic
* Author URI: http://automattic.com/
*
* @package wpcomsh
*/

define( 'WPCOMSH_VERSION', '5.6.1' );
define( 'WPCOMSH_VERSION', '5.6.2-alpha' );

// If true, Typekit fonts will be available in addition to Google fonts
add_filter( 'jetpack_fonts_enable_typekit', '__return_true' );
Expand Down

0 comments on commit 9c85d0b

Please sign in to comment.