-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from pantheon-systems/release-0.1.1
Release 0.1.1
- Loading branch information
Showing
15 changed files
with
531 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
IFS=$'\n\t' | ||
|
||
# shellcheck disable=SC2155 | ||
readonly SELF_DIRNAME="$(dirname -- "$0")" | ||
readonly BASE_DIR="${SELF_DIRNAME}/.." | ||
|
||
# TODO: Parameterize or make case-insensitive when this is an action | ||
readonly CANONICAL_FILE="README.MD" | ||
readonly GIT_USER="[email protected]" | ||
readonly GIT_NAME="Pantheon Automation" | ||
|
||
readonly RELEASE_BRANCH="release" | ||
readonly DEVELOP_BRANCH="alt-main" | ||
|
||
new_dev_version_from_current(){ | ||
local CURRENT_VERSION="$1" | ||
IFS='.' read -ra parts <<< "$CURRENT_VERSION" | ||
patch="${parts[2]}" | ||
patch=$((patch + 1)) | ||
INCREMENTED="${parts[0]}.${parts[1]}.${patch}-dev" | ||
echo "$INCREMENTED" | ||
} | ||
|
||
process_file(){ | ||
local file="$1" | ||
if [ ! -f "$file" ]; then | ||
return | ||
fi | ||
echo "Checking file '${file}'..." | ||
if [[ "$file" = "$BASE_DIR/package-lock.json" ]];then | ||
# skip package-lock and let `npm i` do it when package.json is processed. | ||
echo "skipping sed of package lock" | ||
return | ||
fi | ||
|
||
( | ||
shopt -s nocasematch # make the "if readme" case insensitive | ||
if [[ "${file}" == "$BASE_DIR/readme.txt" ]]; then | ||
echo "adding new heading" | ||
new_heading="### ${NEW_DEV_VERSION}" | ||
awk -v heading="$new_heading" '/## Changelog/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md | ||
mv tmp.md "$file" | ||
git add "$file" | ||
return | ||
elif [[ "${file}" == "$BASE_DIR/readme.md" ]]; then | ||
echo "adding new heading" | ||
new_heading="= ${NEW_DEV_VERSION} =" | ||
awk -v heading="$new_heading" '/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md | ||
mv tmp.md "$file" | ||
git add "$file" | ||
return | ||
fi | ||
) | ||
|
||
echo "search-and-replace with sed" | ||
# Use `sed` to perform the search and replace operation in each file | ||
sed -i.tmp -e "s/${CANONICAL_VERSION}/${NEW_DEV_VERSION}/g" "$file" && rm "$file.tmp" | ||
if [[ "$file" == "$BASE_DIR/package.json" ]];then | ||
# TODO: This seems unsafe as we might update dependencies as well. | ||
# Is it safe to just sed package-lock instead? That also seems wrong. | ||
echo "running 'npm i --package-lock-only' to update package-lock.json" | ||
npm i --package-lock-only | ||
git add "$BASE_DIR/package-lock.json" | ||
fi | ||
|
||
git add "$file" | ||
} | ||
|
||
main() { | ||
local CANONICAL_VERSION | ||
CANONICAL_VERSION="$(grep 'Stable tag:' < "${CANONICAL_FILE}" | awk '{print $3}')" | ||
|
||
git checkout "${RELEASE_BRANCH}" | ||
git pull origin "${RELEASE_BRANCH}" | ||
git checkout "${DEVELOP_BRANCH}" | ||
git pull origin "${DEVELOP_BRANCH}" | ||
git rebase "${RELEASE_BRANCH}" | ||
|
||
local NEW_DEV_VERSION | ||
NEW_DEV_VERSION=$(new_dev_version_from_current "$CANONICAL_VERSION") | ||
|
||
echo "Updating ${CANONICAL_VERSION} to ${NEW_DEV_VERSION}" | ||
# Iterate through each file in the top-level directory | ||
for file in "$BASE_DIR"/*; do | ||
process_file "$file" | ||
done | ||
# Who am I? | ||
git config user.email "${GIT_USER}" | ||
git config user.name "${GIT_NAME}" | ||
|
||
git commit -m "Prepare ${NEW_DEV_VERSION}" | ||
git push origin "${DEVELOP_BRANCH}" | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,17 +58,19 @@ main() { | |
fi | ||
done | ||
# Who am I? | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Pantheon Automation" | ||
git config user.email "[email protected]" | ||
git config user.name "Pantheon Automation" | ||
|
||
RELEASE_MESSAGE="Release ${NEW_VERSION}" | ||
git commit -m "${RELEASE_MESSAGE}" | ||
git push origin "${RELEASE_BRANCH}" --force | ||
|
||
# Create a draft PR | ||
if ! gh pr view "${RELEASE_BRANCH}"; then | ||
local PR_TITLE="${RELEASE_MESSAGE}" | ||
local PR_BODY="${RELEASE_MESSAGE}. If CI tests have not run, close this PR and re-open it." | ||
gh pr create --draft --base "release" \ | ||
--title "${RELEASE_MESSAGE}" --body "${RELEASE_MESSAGE}." \ | ||
--title "${PR_TITLE}" --body "${PR_BODY}" \ | ||
--label "automation" | ||
fi | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Draft Release PR | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
draft-release: | ||
name: Draft Release PR | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Create or Update Release PR | ||
run: | | ||
bash .bin/release-pr.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
name: On Push | ||
on: push | ||
name: Lint and Test | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
lint-test: | ||
runs-on: ubuntu-latest | ||
|
@@ -10,6 +17,8 @@ jobs: | |
DB_HOST: localhost | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run shell linter | ||
run: make lint-shell | ||
- name: Install NPM & Composer dependencies | ||
run: | | ||
composer install | ||
|
@@ -32,23 +41,12 @@ jobs: | |
runs-on: ubuntu-latest | ||
name: WP.org Code Analysis | ||
steps: | ||
- name: Checkout Plugin | ||
uses: actions/checkout@v3 | ||
- name: Checkout WP.org Code Analysis | ||
- name: WP.org Code Analysis | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: WordPress/wporg-code-analysis | ||
ref: trunk | ||
path: wporg-code-analysis | ||
- name: WP.org Code Analysis | ||
run: | | ||
path=$(pwd) | ||
echo "WP.org Code Analysis is installed to ${path}/wporg-code-analysis. cd'ing there..." | ||
cd ${path}/wporg-code-analysis | ||
echo "Setting up WP.org Code Analysis" | ||
composer install -n | ||
echo "Running WP.org Code Analysis" | ||
vendor/bin/phpcs -s --standard=MinimalPluginStandard --ignore=wporg-code-analysis/* $path | ||
uses: pantheon-systems/[email protected] | ||
with: | ||
type: plugin | ||
phpcompatibility: | ||
runs-on: ubuntu-latest | ||
name: PHP Compatibility | ||
|
@@ -63,18 +61,12 @@ jobs: | |
uses: pantheon-systems/phpcompatibility-action@dev | ||
with: | ||
test-versions: 8.0- | ||
draft-release: | ||
name: Draft Release PR | ||
needs: | ||
- lint-test | ||
- wporg-code-analysis | ||
if: github.ref == 'refs/heads/main' | ||
validate-readme-spacing: | ||
name: Validate README Spacing | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Create or Update Release PR | ||
run: | | ||
bash .bin/release-pr.sh | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- uses: pantheon-systems/validate-readme-spacing@v1 | ||
with: | ||
filepath: 'README.MD' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
lint-shell: | ||
shellcheck .bin/prepare-dev.sh .bin/release-pr.sh | ||
lint: lint-shell | ||
composer lint | ||
|
||
test: | ||
composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.