Skip to content

Commit

Permalink
Merge pull request #18 from pantheon-systems/release-0.1.1
Browse files Browse the repository at this point in the history
Release 0.1.1
  • Loading branch information
pwtyler authored Dec 18, 2023
2 parents a4957c6 + 4e10c5f commit d461dae
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 242 deletions.
97 changes: 97 additions & 0 deletions .bin/prepare-dev.sh
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 "$@"
8 changes: 5 additions & 3 deletions .bin/release-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ jobs:
git commit -m "Release $VERSION"
git tag "$VERSION"
git push --tags
prepare-dev:
name: Prepare next dev release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Update Development Branch
run: bash ./bin/prepare-dev.sh
22 changes: 22 additions & 0 deletions .github/workflows/draft-release.yml
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
52 changes: 22 additions & 30 deletions .github/workflows/on-push.yml → .github/workflows/lint-test.yml
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
2 changes: 1 addition & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="rossums-universal-robots"/>
<property name="prefixes" type="array" value="rur"/>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
Expand Down
9 changes: 9 additions & 0 deletions Makefile
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
5 changes: 4 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ Tags: comments, spam
Requires at least: 4.5
Tested up to: 6.2.1
Requires PHP: 5.6
Stable tag: 0.1.0
Stable tag: 0.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

See the robots hard at work.

## Changelog

### 0.1.1 (18 December 2023)
* Set Counter to 0 [19](https://github.com/pantheon-systems/plugin-pipeline-example/pull/19)

### 0.1.0 (6 June 2023)
* Initial Release [[1](https://github.com/pantheon-systems/plugin-pipeline-example/pull/1)]
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require-dev": {
"pantheon-systems/pantheon-wp-coding-standards": "^1.0",
"pantheon-systems/pantheon-wp-coding-standards": "^2.0",
"pantheon-systems/pantheon-wordpress-upstream-tests": "dev-master",
"phpunit/phpunit": "^9",
"yoast/phpunit-polyfills": "^1.0"
Expand Down
Loading

0 comments on commit d461dae

Please sign in to comment.