Skip to content

Commit 7f4ecf7

Browse files
authored
Automate versioning and releasing (#22)
* add workflow to automate release tagging * don't create or update patch tags automatically * add instructions for creating a release * update readme examples for new versioning process * add changesets for versioning * revise release workflow to use changesets * use different commit and title messages * update development and release instructions * add instructions for ensuring node and npm version * clairfy getting started steps
1 parent 88887fd commit 7f4ecf7

File tree

11 files changed

+5212
-2
lines changed

11 files changed

+5212
-2
lines changed

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/actions/publish/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Publish release tags
2+
description: Ensures major, minor, and patch version tags for a given version.
3+
inputs:
4+
version:
5+
description: 'Patch version to publish.'
6+
required: true
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- run: "${{ github.action_path }}/publish.sh ${{ inputs.version }}"
11+
shell: bash

.github/actions/publish/publish.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
print_usage_instructions() {
6+
echo "Usage: bash publish.sh <version>";
7+
echo "";
8+
echo "Example use:";
9+
echo " bash publish.sh 3.1.1";
10+
exit 1
11+
}
12+
13+
if [ $# -eq 0 ]; then
14+
print_usage_instructions
15+
fi
16+
17+
version="$1"
18+
19+
# We will only handle versions >= v1 in the format {MAJOR}.{MINOR}?.{PATCH}?
20+
# capture 1: major number
21+
# capture 2: minor number with dot
22+
# capture 3: minor number without dot
23+
# capture 4: patch number with dot
24+
# capture 5: patch number without dot
25+
VERSION_REGEX="^([1-9][0-9]*)(\.(0|[1-9][0-9]*)){0,1}(\.(0|[1-9][0-9]*)){0,1}$"
26+
27+
if [[ "$version" =~ $VERSION_REGEX ]] ; then
28+
majorTag="v${BASH_REMATCH[1]}"
29+
minorTag="$majorTag.${BASH_REMATCH[3]:-0}"
30+
patchTag="$minorTag.${BASH_REMATCH[5]:-0}"
31+
tagsToUpdate=("$majorTag" "$minorTag")
32+
else
33+
echo "Provided version does not match the format \"{MAJOR}.{MINOR}?.{PATCH}?\". Skipping tag updates."
34+
exit 0
35+
fi
36+
37+
if [ "$(git tag -l "$patchTag")" ]; then
38+
echo "Version $patchTag has already been released! Skipping tag updates."
39+
exit 0
40+
else
41+
echo "Creating tag: $patchTag"
42+
git tag -a "$patchTag" -m " Release $patchTag"
43+
git push origin "$patchTag"
44+
fi
45+
46+
for tag in "${tagsToUpdate[@]}"; do
47+
message="Release $patchTag"
48+
49+
if [ "$(git tag -l "$tag")" ]; then
50+
echo "Updating tag: $tag"
51+
message="Update to $patchTag"
52+
else
53+
echo "Creating tag: $tag"
54+
fi
55+
56+
git tag -fa "$tag" -m "$message"
57+
git push origin "$tag" --force
58+
done

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Version and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Version and Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Node.js 16.x
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: 16.x
24+
25+
- name: Install Dependencies
26+
run: npm ci
27+
28+
- name: Create Release Pull Request
29+
id: changesets
30+
uses: changesets/action@v1
31+
with:
32+
commit: "Version Action"
33+
title: "Version Action"
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Get current version
38+
id: version
39+
run: echo "::set-output name=CURRENT_VERSION::$(node -p "require('./package.json').version")"
40+
41+
- name: Publish tags
42+
if: steps.changesets.outputs.hasChangesets == 'false'
43+
uses: ./.github/actions/publish
44+
with:
45+
version: ${{ steps.version.outputs.CURRENT_VERSION }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v16

DEVELOPMENT.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Development
2+
3+
## Getting Started
4+
5+
Before you get started, we recommend installing [Node Version Manager](https://github.com/nvm-sh/nvm#installing-and-updating) to help manage `node` and `npm` versions. Next, from your local copy of the action run `nvm use` and `npm install`. You're ready to start coding!
6+
7+
## Git Workflows
8+
9+
We use the [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow). The workflow for a typical code change looks like this:
10+
11+
1. Create a new branch for the feature.
12+
2. Make changes to the code.
13+
3. Use `npx changeset` to create a changeset describing the change to users.
14+
4. Commit your changes.
15+
5. Open a pull request to the `main` branch.
16+
6. Once all checks are passing and the PR is approved, Squash and Merge into the `main` branch.
17+
18+
## Creating a release
19+
20+
We use [Changesets](https://github.com/changesets/changesets) to automate versioning and releasing. When you are ready to release, the first step is to create the new version.
21+
22+
1. Go to pull requests and view the "Version Action" PR.
23+
2. Review the PR:
24+
- [ ] Changelog entries were created.
25+
- [ ] Version number in package.json was bumped.
26+
- [ ] All `.changeset/*.md` files were removed.
27+
3. Approve, then "Squash and merge" the PR into `main`.
28+
29+
Merging the versioning PR will run a workflow that creates or updates all necessary tags. The next step is to create a release in GitHub. This may be automated in the future, but for now the process is:
30+
31+
1. In GitHub, visit "Releases -> Draft new release"
32+
2. In the "Choose a tag" dropdown, choose the tag you want to release. This is usually the most recently created patch tag (`v{MAJOR}.{MINOR}.{PATCH}`). Major/minor tags (i.e `v3` and `v3.0`) are only present to allow users to opt into automatic patch or minor version updates and should not be associated with a GitHub release.
33+
3. Leave the target branch set to `main`.
34+
4. Give the release a title. Typically, this will be identical to the release's tag name.
35+
5. Copy the [CHANGLELOG.md](./CHANGELOG.md) entry for this release into the release body.
36+
6. Click "Publish Release".

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
steps:
6060
- uses: actions/checkout@v2
6161
- name: GitHub Action Deploy to WP Engine
62-
uses: wpengine/github-action-wpe-site-deploy@v3.0
62+
uses: wpengine/github-action-wpe-site-deploy@v3
6363
with:
6464
WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}
6565
WPE_ENV: <your_install_name_here>
@@ -79,7 +79,7 @@ jobs:
7979
steps:
8080
- uses: actions/checkout@v2
8181
- name: GitHub Action Deploy to WP Engine
82-
uses: wpengine/github-action-wpe-site-deploy@v3.0
82+
uses: wpengine/github-action-wpe-site-deploy@v3
8383
with:
8484
# Deploy vars
8585
WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}

0 commit comments

Comments
 (0)