Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Release Preparation scripts #6713

Merged
merged 39 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
937e55b
Add release preparation scripts
merkushin Mar 29, 2023
b1b7360
Merge branch 'trunk' into add/release-branch-prep
merkushin Mar 29, 2023
8259d34
Merge branch 'trunk' into add/release-branch-prep
merkushin Mar 31, 2023
7e13f80
Merge branch 'trunk' into add/release-branch-prep
gabrielcaires Apr 3, 2023
e941cae
Rename release PR scripts for clarity
merkushin Apr 30, 2023
bf6a7e8
Add script to update plugin version
merkushin May 3, 2023
a14b054
Merge branch 'trunk' into add/release-branch-prep
merkushin May 26, 2023
5f886a3
Merge branch 'add/release-branch-prep' of github.com:Automattic/sense…
merkushin May 26, 2023
c8b736d
Update plugin version in plugin and package files
merkushin May 26, 2023
b3eead5
Checkout release branch and update plugin version
merkushin May 26, 2023
1c25ddf
Update version
merkushin May 26, 2023
2643efe
Update documentation for the release preparation script
merkushin Jun 1, 2023
4b8df27
Merge branch 'trunk' into add/release-branch-prep
merkushin Jun 1, 2023
276afae
Merge branch 'trunk' into add/release-branch-prep
merkushin Jun 2, 2023
3138c6c
Update Sensei version constant
merkushin Jun 2, 2023
bdfaf15
Take OS into account to be able run it locally on macOS
merkushin Jun 2, 2023
6f20f9a
Don't remove jest from package-lock.json
merkushin Jun 2, 2023
81640b3
Update Stable tag
merkushin Jun 2, 2023
97b8315
Add No Changelog label
merkushin Jun 2, 2023
c12627b
Use jq to update version in package.json and package-lock.json
merkushin Jun 4, 2023
98cef32
Update comments
merkushin Jun 4, 2023
9411f8b
Fix the key to update in packages-lock.json
merkushin Jun 4, 2023
e3e9433
Merge branch 'trunk' into add/release-branch-prep
merkushin Jun 6, 2023
d34c741
Copy changelog to readme
merkushin Jun 6, 2023
5b31d4a
Merge branch 'add/release-branch-prep' of github.com:Automattic/sense…
merkushin Jun 6, 2023
b383a25
Merge branch 'trunk' into add/release-branch-prep
merkushin Jun 22, 2023
dd06491
Unwrap links to GH in changelog
merkushin Jun 22, 2023
764c807
Merge branch 'add/release-branch-prep' of github.com:Automattic/sense…
merkushin Jun 22, 2023
ceb5a3f
Fix script path
merkushin Jun 22, 2023
92ddb3a
Run script properly
merkushin Jun 22, 2023
f6144fc
Merge branch 'trunk' into add/release-branch-prep
donnapep Jul 7, 2023
cc5ea60
Merge branch 'trunk' into add/release-branch-prep
merkushin Jul 26, 2023
947b5ca
Fix deprecated doc block
merkushin Jul 26, 2023
2e650b2
Use npm script to build translation
merkushin Jul 26, 2023
4b98623
Allow running build i18n script as root
merkushin Jul 26, 2023
04be630
Merge branch 'trunk' into add/release-branch-prep
donnapep Aug 1, 2023
2d5de6b
Pass allow root to the command
merkushin Aug 8, 2023
1c80b1e
Merge branch 'trunk' into add/release-branch-prep
merkushin Aug 9, 2023
c1a9bb1
Fix git commit `gpgsign` not working by bumping git version
m1r0 Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
/**
* Helper function to check to see if any courses exist in the database.
*
* @deprected $$next-version$$
* @deprecated $$next-version$$

Check warning on line 817 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L817

Added line #L817 was not covered by tests
*
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@
"woorelease": {
"wp_org_slug": "sensei-lms"
}
}
}
55 changes: 55 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM composer:2 AS composer
FROM php:7.4-cli

RUN set -ex; \
echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/bullseye-backports.list; \
apt-get update ; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
zip unzip \
zlib1g-dev libzip-dev \
git/bullseye-backports ssh \
jq; \
rm -rf /var/lib/apt/lists/*

RUN eval `ssh-agent -s`

# Install GitHub CLI.
ENV GITHUB_CLI_VERSION 2.32.1
RUN set -ex; \
curl -L "https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_checksums.txt" -o checksums.txt; \
curl -OL "https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_linux_arm64.deb"; \
shasum --ignore-missing -a 512 -c checksums.txt; \
dpkg -i "gh_${GITHUB_CLI_VERSION}_linux_arm64.deb"; \
rm -rf "gh_${GITHUB_CLI_VERSION}_linux_arm64.deb"; \
# verify gh binary works
gh --version;
RUN docker-php-ext-install zip

# Install composer.
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install WP CLI
RUN curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > /root/wp-cli.phar && \
chmod +x /root/wp-cli.phar && \
mv /root/wp-cli.phar /usr/local/bin/wp

# Install Node & NPM.
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y \
--no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*

# Copy a script with release PR steps.
COPY release-pr-steps.sh /usr/bin/release-pr-steps.sh
COPY update-version.sh /usr/bin/update-version.sh
COPY changelog-unwrap-pr-links.sh /usr/bin/changelog-unwrap-pr-links.sh

# Copy ssh confid and keys! Not secure!
# TODO: https://www.fastruby.io/blog/docker/docker-ssh-keys.html
COPY ssh-data /root/.ssh

CMD ["bash"]
48 changes: 48 additions & 0 deletions scripts/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Release

Here, we have 2 scripts and one Dockerfile that help preparing the release PR.

## scripts/release-pr.sh

Run it from the repository's root: `./scripts/release-pr.sh X.Y.Z`, where X.Y.Z is the version you're releasing.

If you want to create the release not from `trunk`, specify the branch name:
```
./scripts/release-pr.sh X.Y.Z feature/branch
```

The script assumes, you have:

- ~/.ssh - directory that contain all needed SSH configuration and keys for GitHub.
- ~/.gitconfig - your configuration for Git.

This script creates a copy of your SSH directory. This approach is not ideal and is considered as non-secure.
The script removes all the data in the end, so, hopefully, it won't cause damage.

However, use cautiously: don't share your Docker image or tempory directory/data.

## scripts/release-pr-steps.sh

This script is being run from inside the Docker container and runs all the needed steps:

- Checkout Sensei repository.
- Install dependencies.
- Create a local release branch.
- Replace the next version tag.
- Update changelog.
- Build POT file.
- Push all the changes to GitHub.
- Create the release PR.

## scripts/Dockerfile

Describes the image for Docker, containing:

- PHP 7.4
- Node 18.x
- composer 2
- GitHub CLI
- WordPress CLI

It also copies the ssh data directory. Once again: this approach is not ideal and is considered as non-secure.

19 changes: 19 additions & 0 deletions scripts/changelog-unwrap-pr-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# Exit on error and output commands.
set -ex

CURRENT_DIR=$(pwd)
OS_TYPE=$(uname -s)
# sed arguments in different OS passed a bit differently.
if [[ "$OS_TYPE" == "Darwin" ]]; then
sed -E -i '' "s/^.* \[#([0-9]+)\]$/&(https:\/\/github.com\/Automattic\/sensei\/pull\/\\1)/" "$CURRENT_DIR/changelog.txt"
elif [[ "$OS_TYPE" == "Linux" ]]; then
# You are on Linux
sed -E -i'' "s/^.* \[#([0-9]+)\]$/&(https:\/\/github.com\/Automattic\/sensei\/pull\/\\1)/" "$CURRENT_DIR/changelog.txt"
else
echo "Unsupported operating system"
fi



94 changes: 94 additions & 0 deletions scripts/release-pr-steps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

# Exit on error and output commands.
set -ex

NEXT_VERSION=$1
if [ "$NEXT_VERSION" = "" ]; then
echo "Error: Version not set!"
exit
fi

RELEASE_BRANCH=$2
if [ "$RELEASE_BRANCH" = "" ]; then
echo "Error: Release branch not set!"
exit
fi

# Fix permissions for ssh config and keys.
chown -R root:root /root/.ssh
export GIT_SSH_COMMAND="ssh -i /root/.ssh/id_rsa"

# Create working directory and checkout Sensei.
mkdir /release && cd /release
git clone [email protected]:Automattic/sensei.git
cd /release/sensei

# Checkout release branch.
git switch $RELEASE_BRANCH

# Exit if could not switch to release branch.
if [ $? -ne 0 ]; then
echo "Error: Could not switch to release branch!"
exit
fi

# Install dependencies.
composer install && npm ci

# Disable commit signing.
git config --global commit.gpgsign false

# Create the release branch.
git switch -c "release/$NEXT_VERSION"

echo "Replace next version tag"
./scripts/replace-next-version-tag.sh $NEXT_VERSION
if [[ -n $(git status -s) ]]; then
git add .
git commit -m 'Replace next version tag'
else
echo "There are no changes after next version tag replacement."
fi

echo "Update plugin version"
update-version.sh $NEXT_VERSION
if [[ -n $(git status -s) ]]; then
git add .
git commit -m 'Update plugin version'
else
echo "There are no changes after updating the version in plugin files."
fi

echo "Changlogger write"
# Write changelog.
composer exec -- changelogger write --add-pr-num
# Unwrap PR links.
changelog-unwrap-pr-links.sh
# Copy changelog section in readme.
./scripts/copy-changelog-to-readme.php

if [[ -n $(git status -s) ]]; then
git add .
git commit -m 'Update chaneglog'
else
echo "There are no changes after running changelogger."
fi

echo "Build translations"
npm run i18n:build -- --allow-root
if [[ -n $(git status -s) ]]; then
git add .
git commit -m 'Update translations'
else
echo "There are no changes after building translations."
fi

# Push all changes to GitHub
git push --set-upstream origin "release/$NEXT_VERSION"

# Login to create PR.
gh auth login

# Create PR.
gh pr create --assignee @me --base trunk --draft --title "Release $NEXT_VERSION" --reviewer Automattic/nexus --label "[Type] Maintenance" --label "No Changelog"
34 changes: 34 additions & 0 deletions scripts/release-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# Output commands.
set -x

NEXT_VERSION=$1
if [ "$NEXT_VERSION" = "" ]; then
echo "Error: Version not set"
exit
fi

RELEASE_BRANCH=$2
if [ "$RELEASE_BRANCH" = "" ]; then
RELEASE_BRANCH="trunk"
fi

echo "Preparing release/$NEXT_VERSION from $RELEASE_BRANCH"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo $SCRIPT_DIR

# Dangerous! Considered as non-secure way of sharing keys!
# TODO: https://www.fastruby.io/blog/docker/docker-ssh-keys.html
cp -r ~/.ssh "$SCRIPT_DIR/ssh-data"

docker build -t release-build $SCRIPT_DIR && \
docker run --name release-steps --rm -it \
-v ~/.gitconfig:/etc/gitconfig \
release-build \
bash -c "/usr/bin/release-pr-steps.sh $NEXT_VERSION $RELEASE_BRANCH"

docker image rm release-build
rm -rf "$SCRIPT_DIR/ssh-data"

65 changes: 65 additions & 0 deletions scripts/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -ex

# Check version provided
VERSION=$1
if [ -z "$VERSION" ]; then
echo "No version provided."
exit 1
fi

if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version provided is not a valid SemVer version."
exit 1
fi

# Check if jq is installed. We use it to update the version in package.json and package-lock.json
if ! command -v "jq" >/dev/null 2>&1; then
echo "jq is not installed. https://jqlang.github.io/jq/download/"
fi

CURRENT_DIR=$(pwd)
OS_TYPE=$(uname -s)
# sed arguments in different OS passed a bit differently.
if [[ "$OS_TYPE" == "Darwin" ]]; then
# You are on macOS

# Update version in sensei-lms.php
sed -E -i '' "s/\* Version: [0-9]+\.[0-9]+\.[0-9]+/\* Version: $VERSION/" "$CURRENT_DIR/sensei-lms.php"

# Find constant and replace the version in sensei-lms.php:
# define( 'SENSEI_LMS_VERSION', '4.15.0' ); // WRCS: DEFINED_VERSION.
sed -E -i '' "s/'SENSEI_LMS_VERSION', '[0-9]+\.[0-9]+\.[0-9]+/'SENSEI_LMS_VERSION', '$VERSION/" "$CURRENT_DIR/sensei-lms.php"

# Update version in the Stable Tag comment in readme.txt
# Stable tag: 4.15.0
sed -E -i '' "s/^Stable tag: [0-9]+\.[0-9]+\.[0-9]+/Stable tag: $VERSION/" "$CURRENT_DIR/readme.txt"
elif [[ "$OS_TYPE" == "Linux" ]]; then
# You are on Linux

# Update version in sensei-lms.php
sed -E -i'' "s/\* Version: [0-9]+\.[0-9]+\.[0-9]+/\* Version: $VERSION/" "$CURRENT_DIR/sensei-lms.php"

# Find constant and replace the version in sensei-lms.php:
# define( 'SENSEI_LMS_VERSION', '4.15.0' ); // WRCS: DEFINED_VERSION.
sed -E -i'' "s/'SENSEI_LMS_VERSION', '[0-9]+\.[0-9]+\.[0-9]+/'SENSEI_LMS_VERSION', '$VERSION/" "$CURRENT_DIR/sensei-lms.php"

# Update version in the Stable Tag comment in readme.txt
# Stable tag: 4.15.0
sed -E -i'' "s/^Stable tag: [0-9]+\.[0-9]+\.[0-9]+/Stable tag: $VERSION/" "$CURRENT_DIR/readme.txt"
else
echo "Unsupported operating system"
fi

# Update package.json.
jq ".version = \"$VERSION\"" "$CURRENT_DIR/package.json" > "$CURRENT_DIR/package.json.tmp" && \
mv "$CURRENT_DIR/package.json.tmp" "$CURRENT_DIR/package.json"

# Update package-lock.json: the first occurrence of version in the root object.
jq ".version = \"$VERSION\"" "$CURRENT_DIR/package-lock.json" > "$CURRENT_DIR/package-lock.json.tmp" && \
mv "$CURRENT_DIR/package-lock.json.tmp" "$CURRENT_DIR/package-lock.json"

# Update package-lock.json: the second occurrence of version.
jq ".packages.\"\".version = \"$VERSION\"" "$CURRENT_DIR/package-lock.json" > "$CURRENT_DIR/package-lock.json.tmp" && \
mv "$CURRENT_DIR/package-lock.json.tmp" "$CURRENT_DIR/package-lock.json"
Loading