Skip to content

Commit 5db3a04

Browse files
Update release workflow (#26)
* Update release workflow
1 parent 5c7228d commit 5db3a04

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
name: Perform a Release
1+
name: Publish
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
npm-version-arg:
7-
description: Argument to npm-version
8-
default: minor
9-
required: true
4+
release:
5+
types: [published, edited]
106

117
jobs:
128
build:
@@ -33,13 +29,13 @@ jobs:
3329
- name: Update package version
3430
id: update-package-version
3531
run: |
36-
VERSION=$(npm version "${{ github.event.inputs.npm-version-arg }}")
32+
git tag -d "${{ github.event.release.tag_name }}"
33+
VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version)
3734
echo "::set-output name=version::$VERSION"
38-
39-
# Update the branch with the new commit
40-
- name: Push new version
41-
run: git push
42-
35+
git add package.json package-lock.json
36+
git commit -m "[skip ci] Bump $VERSION"
37+
git push origin HEAD:main
38+
4339
# Now carry on, business as usual
4440
- name: Perform npm tasks
4541
run: npm run ci
@@ -50,8 +46,12 @@ jobs:
5046
- name: Commit to release branch
5147
id: release_info
5248
run: |
53-
# Retrieve the previously created tag
54-
TAG="${{ steps.update-package-version.outputs.version }}"
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%.*})
5555
5656
# Add the built artifacts. Using --force because dist/lib should be in
5757
# .gitignore
@@ -60,23 +60,21 @@ jobs:
6060
# Make the commit
6161
MESSAGE="Build for $(git rev-parse --short HEAD)"
6262
git commit --allow-empty -m "$MESSAGE"
63+
git tag -f -a -m "Release $longVersion" $longVersion
6364
64-
# Create an annotated tag and push it to origin. Using -f to overwrite
65-
# the tag that `npm version` made for us in a previous step
66-
git tag -f -a -m "Release $TAG" $TAG
67-
git push origin $TAG
68-
69-
release:
70-
name: Release
71-
runs-on: ubuntu-latest
72-
needs: build
73-
steps:
74-
- name: Create Release
75-
uses: actions/create-release@v1
76-
env:
77-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78-
with:
79-
tag_name: ${{ needs.build.outputs.tag }}
80-
release_name: Release ${{ needs.build.outputs.tag }}
81-
draft: true
82-
prerelease: false
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

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)