Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa44466
Create namespace updater script
agibson-godaddy Mar 4, 2025
d8c820f
Merge branch 'master' into feature/prep-release-script
agibson-godaddy Mar 4, 2025
7cb475f
Set up workflow logic
agibson-godaddy Mar 4, 2025
c2d2e06
Update constant values
agibson-godaddy Mar 4, 2025
fd54942
Add new changelog heading
agibson-godaddy Mar 4, 2025
9e6b7af
Update workflow
agibson-godaddy Mar 4, 2025
d74596c
Adjust commands
agibson-godaddy Mar 4, 2025
2e104e4
Job name
agibson-godaddy Mar 4, 2025
6e5e71c
Install ruby & sass
agibson-godaddy Mar 4, 2025
e1b7b15
Specify Ruby version
agibson-godaddy Mar 4, 2025
fe7d0f7
Try installing Sass with npm
agibson-godaddy Mar 4, 2025
dda5bc1
Setup WP CLI
agibson-godaddy Mar 4, 2025
b071ee6
Try disabling xdebug
agibson-godaddy Mar 4, 2025
864748a
Set upstream to
agibson-godaddy Mar 4, 2025
96356f5
Just set upstream
agibson-godaddy Mar 4, 2025
90eaa4a
Try passing in as variable
agibson-godaddy Mar 4, 2025
630ff10
Env£
agibson-godaddy Mar 4, 2025
4168e63
Validate branch doesn't exist & add GH token
agibson-godaddy Mar 4, 2025
c6bd239
Tweak branch validation logic
agibson-godaddy Mar 4, 2025
3e72a61
Remove branch validation for now
agibson-godaddy Mar 4, 2025
bd0af1b
Include body
agibson-godaddy Mar 4, 2025
904d5e8
New validation logic
agibson-godaddy Mar 4, 2025
0095f31
Adjust logic again!
agibson-godaddy Mar 4, 2025
95191ba
Remove unnecessary permission
agibson-godaddy Mar 4, 2025
544113c
Merge branch 'master' into feature/prep-release-script
agibson-godaddy Mar 5, 2025
7db7996
Make the PR a draft
agibson-godaddy Mar 5, 2025
d3a15e6
Remove unnecessary colon
agibson-godaddy Mar 6, 2025
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
57 changes: 57 additions & 0 deletions .github/scripts/update-namespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -Eeuo pipefail

SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
if ! command -v jq >/dev/null; then
echo "Please install jq"
exit 1
fi

COMPOSER_FILE="${SCRIPT_DIR}/../../composer.json"

OLD_VERSION=$(jq -e -r .version "${COMPOSER_FILE}")
echo "Old version: ${OLD_VERSION}"
echo "New version: ${NEW_VERSION}"

# replace `.` with `_` to build our namespace string
OLD_VERSION_WITH_UNDERSCORES=${OLD_VERSION//./_}
OLD_NAMESPACE_STRING="v${OLD_VERSION_WITH_UNDERSCORES}"

NEW_VERSION_WITH_UNDERSCORES=${NEW_VERSION//./_}
NEW_NAMESPACE_STRING="v${NEW_VERSION_WITH_UNDERSCORES}"

# replace version in `composer.json`
echo "Updating composer.json version"
UPDATED_JSON="$(jq --arg NEW_VERSION "${NEW_VERSION}" '.version = $NEW_VERSION' "${COMPOSER_FILE}")"

# replace autoload namespaces in `composer.json`
echo "Updating autoload namespaces in composer.json"
AUTOLOAD_PSR4="$(echo "${UPDATED_JSON}" | jq -e '.autoload["psr-4"]')"
AUTOLOAD_PSR4="$(echo "${AUTOLOAD_PSR4}" | sed "s/${OLD_NAMESPACE_STRING}/${NEW_NAMESPACE_STRING}/g")"

AUTOLOAD_DEV_PSR4="$(echo "${UPDATED_JSON}" | jq -e '.["autoload-dev"]["psr-4"]')"
AUTOLOAD_DEV_PSR4="$(echo "${AUTOLOAD_DEV_PSR4}" | sed "s/${OLD_NAMESPACE_STRING}/${NEW_NAMESPACE_STRING}/g")"

UPDATED_JSON="$(echo "${UPDATED_JSON}" | jq --argjson AUTOLOAD_PSR4 "${AUTOLOAD_PSR4}" --argjson AUTOLOAD_DEV_PSR4 "${AUTOLOAD_DEV_PSR4}" '.autoload["psr-4"] = $AUTOLOAD_PSR4 | .["autoload-dev"]["psr-4"] = $AUTOLOAD_DEV_PSR4')"
echo "${UPDATED_JSON}" > "${COMPOSER_FILE}"

# replace namespace in `./woocommerce/` directory; we're looking in PHP and JS files only
echo "Replacing instances of ${OLD_NAMESPACE_STRING} with ${NEW_NAMESPACE_STRING} in ./woocommerce/"
find "${SCRIPT_DIR}/../../woocommerce/" -type f \( -name '*.php' -o -name '*.js' \) -exec sed -i "s/${OLD_NAMESPACE_STRING}/${NEW_NAMESPACE_STRING}/g" {} \;

# replace namespace in `./tests/` directory
echo "Replacing instances of ${OLD_NAMESPACE_STRING} with ${NEW_NAMESPACE_STRING} in ./tests/"
find "${SCRIPT_DIR}/../../tests/" -type f -name '*.php' -exec sed -i "s/${OLD_NAMESPACE_STRING}/${NEW_NAMESPACE_STRING}/g" {} \;

# replace version number in `./woocommerce/class-sv-wc-plugin.php` file
echo "Replacing VERSION constant value in ./woocommerce/class-sv-wc-plugin.php file"
sed -i -e "s/public const VERSION = '${OLD_VERSION}';/public const VERSION = '${NEW_VERSION}';/g" "${SCRIPT_DIR}/../../woocommerce/class-sv-wc-plugin.php"

# replace version number in `./woocommerce-framework-plugin-loader-sample.php` file
echo "Replacing FRAMEWORK_VERSION constant value in ./woocommerce-framework-plugin-loader-sample.php file"
sed -i -e "s/public const FRAMEWORK_VERSION = '${OLD_VERSION}';/public const FRAMEWORK_VERSION = '${NEW_VERSION}';/g" "${SCRIPT_DIR}/../../woocommerce-framework-plugin-loader-sample.php"

# add new changelog heading on line 3
echo "Adding changelog heading for new version"
CHANGELOG_HEADING="$(date +%Y).nn.nn - version ${NEW_VERSION}\n"
sed -i "3i ${CHANGELOG_HEADING}" "${SCRIPT_DIR}/../../woocommerce/changelog.txt"
76 changes: 76 additions & 0 deletions .github/workflows/prep-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,79 @@ name: Prepare Release

on:
workflow_dispatch:
inputs:
new-version:
type: string
description: "New version number"
required: true

permissions:
contents: write
pull-requests: write

jobs:
prepare-release:
name: Prepare Release v${{ inputs.new-version }}
runs-on: ubuntu-latest
env:
NEW_VERSION: ${{ inputs.new-version }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate release branch
run: |
BRANCH="release/${NEW_VERSION}"
BRANCH_EXISTS=$(git ls-remote --heads origin $BRANCH | wc -l)

if [[ $BRANCH_EXISTS == '1' ]]; then
echo The release/"${NEW_VERSION}" branch already exists. Please delete it to proceed.
exit 1
else
echo The release/"${NEW_VERSION}" branch does not exist... proceeding!
fi

- name: Create new release branch
run: git checkout -b release/"${NEW_VERSION}"

- name: Replace namespaces and versions through entire codebase
run: ./.github/scripts/update-namespace.sh

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Install sass
run: npm install -g sass

# We disable Xdebug because when enabled it makes the WP pot generation fail :shrug:
- name: Disable Xdebug
run: sudo phpdismod xdebug

- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@1

- name: Install packages
run: npm install

- name: Bump package.json version
run: npm version --no-git-tag-version --allow-same-version "${NEW_VERSION}"

- name: Build assets
run: npm run build

- name: Commit
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Version ${NEW_VERSION}"
git push --set-upstream origin release/"${NEW_VERSION}"

- name: Create pull request
run: |
gh pr create -B "${BASE_BRANCH}" -H release/"${NEW_VERSION}" --title "Release v${NEW_VERSION}" --body "Release v${NEW_VERSION}" --draft
env:
BASE_BRANCH: ${{ github.ref_name }}
GH_TOKEN: ${{ github.token }}
Loading