Skip to content

Commit f0e45fe

Browse files
Update release process to automate semantic versioning (#41)
* update release.yml to update semantic versions
1 parent f8c7a05 commit f0e45fe

File tree

3 files changed

+95
-82
lines changed

3 files changed

+95
-82
lines changed

.github/workflows/publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published, edited]
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
outputs:
12+
tag: ${{ steps.update-package-version.outputs.version }}
13+
steps:
14+
# Configure runner with the right stuff
15+
- uses: actions/checkout@v2
16+
with:
17+
token: ${{ secrets.GITHUB_TOKEN }}
18+
- name: Configure git
19+
run: |
20+
git config user.name 'Release Action'
21+
git config user.email '<>'
22+
- uses: actions/setup-node@v1
23+
with:
24+
node-version: "12"
25+
26+
# Call `npm version`. It increments the version and commits the changes.
27+
# We'll save the output (new version string) for use in the following
28+
# steps
29+
- name: Update package version
30+
id: update-package-version
31+
run: |
32+
git tag -d "${{ github.event.release.tag_name }}"
33+
VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version)
34+
echo "::set-output name=version::$VERSION"
35+
git add package.json package-lock.json
36+
git commit -m "[skip ci] Bump $VERSION"
37+
git push origin HEAD:main
38+
39+
# Now carry on, business as usual
40+
- name: Perform npm tasks
41+
run: npm run ci
42+
43+
# Finally, create a detached commit containing the built artifacts and tag
44+
# it with the release. Note: the fact that the branch is locally updated
45+
# will not be relayed (pushed) to origin
46+
- name: Commit to release branch
47+
id: release_info
48+
run: |
49+
# Check for semantic versioning
50+
echo "Preparing release for version $longVersion"
51+
longVersion="${{github.event.release.tag_name}}"
52+
[[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1)
53+
majorVersion=$(echo ${longVersion%.*.*})
54+
minorVersion=$(echo ${longVersion%.*})
55+
56+
# Add the built artifacts. Using --force because dist/lib should be in
57+
# .gitignore
58+
git add --force dist lib
59+
60+
# Make the commit
61+
MESSAGE="Build for $(git rev-parse --short HEAD)"
62+
git commit --allow-empty -m "$MESSAGE"
63+
git tag -f -a -m "Release $longVersion" $longVersion
64+
65+
# Get the commit of the tag you just released
66+
commitHash=$(git rev-list -n 1 $longVersion)
67+
68+
# Delete the old major and minor version tags locally
69+
git tag -d $majorVersion || true
70+
git tag -d $minorVersion || true
71+
72+
# Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above
73+
git tag -f $majorVersion $commitHash
74+
git tag -f $minorVersion $commitHash
75+
76+
# Force push the new minor version tag to overwrite the old tag remotely
77+
echo "Pushing new tags"
78+
git push -f origin $longVersion
79+
git push -f origin $majorVersion
80+
git push -f origin $minorVersion

.github/workflows/release.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

devel/contributing.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Contributing
2+
3+
Verify changes by running tests and building locally with the following command:
4+
5+
```
6+
npm run ci
7+
```
8+
9+
## Creating a New Release
10+
11+
Familiarize yourself with the best practices for [releasing and maintaining GitHub actions](https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions).
12+
13+
Changes should be made on a new branch. The new branch should be merged to the main branch via a pull request. Ensure that all of the CI pipeline checks and tests have passed for your changes.
14+
15+
After the pull request has been approved and merged to main, follow the Github process for [creating a new release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository). The release must follow semantic versioning (ex: vX.Y.Z). This will kick off a new pipeline execution, and the action will automatically be published to the GitHub Actions Marketplace if the pipeline finishes successfully. Check the [GitHub Marketplace](https://github.com/marketplace/actions/setup-matlab) and check the major version in the repository (ex: v1 for v1.0.0) to ensure that the new semantically versioned tag is available.

0 commit comments

Comments
 (0)