-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate package release with Semantic versioning (#957)
- Loading branch information
Showing
8 changed files
with
149 additions
and
7 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,33 @@ | ||
name: Check changelog | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
- push-action/** # Temporary branches created by CasperWA/push-protected@v2 action on release workflow | ||
pull_request: | ||
types: [ opened, reopened ] | ||
workflow_call: | ||
outputs: | ||
release_type: | ||
description: The release type extracted from changelog | ||
value: ${{ jobs.check_changelog.outputs.release_type }} | ||
|
||
jobs: | ||
check_changelog: | ||
runs-on: [ ubuntu-latest ] | ||
outputs: | ||
release_type: ${{ steps.set_release_type_output.outputs.release_type }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Get release type in changelog | ||
run: echo "RELEASE_TYPE=$(cat CHANGELOG.md | grep -E '^## Unreleased \[(patch|minor|major)\]$' | grep -E -w -o "patch|minor|major" | tr -d '\n')" >> $GITHUB_ENV | ||
- name: Make release type available to subsequent jobs | ||
if: env.RELEASE_TYPE | ||
id: set_release_type_output | ||
run: | | ||
echo "Found release type '${{ env.RELEASE_TYPE }}'" | ||
echo "release_type=${{ env.RELEASE_TYPE }}" >> $GITHUB_OUTPUT | ||
- name: Fail and display error if no proper release type is found in changelog | ||
if: env.RELEASE_TYPE == '' | ||
run: echo "No valid release type found in changelog. The title of the 'Unreleased' section must contain one of the following tags '[patch]', '[minor]', '[major]'. For example, '## Unreleased [minor]'."; exit 1 |
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,76 @@ | ||
name: Release | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [ closed ] | ||
|
||
|
||
jobs: | ||
changelog: | ||
uses: "ambanum/OpenTermsArchive/.github/workflows/changelog.yml@main" | ||
test: | ||
uses: "ambanum/OpenTermsArchive/.github/workflows/test.yml@main" | ||
release: | ||
if: github.event.pull_request.merged == true | ||
needs: [ changelog, test ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | ||
|
||
- name: Configure Git author | ||
run: | | ||
git config --global user.name "Open Terms Archive Release Bot" | ||
git config --global user.email "[email protected]" | ||
- name: Bump package version | ||
run: | | ||
echo "Release type obtained from the previous job: '${{ needs.changelog.outputs.release_type }}'" | ||
echo "NEW_VERSION=$(npm --no-git-tag-version version ${{ needs.changelog.outputs.release_type }})" >> $GITHUB_ENV | ||
- name: Update changelog unreleased section with new version | ||
uses: superfaceai/release-changelog-action@v2 | ||
with: | ||
version: ${{ env.NEW_VERSION }} | ||
operation: release | ||
|
||
- name: Commit CHANGELOG.md and package.json changes and create tag | ||
run: | | ||
git add "package.json" | ||
git add "package-lock.json" | ||
git add "CHANGELOG.md" | ||
git commit -m "Release ${{ env.NEW_VERSION }}" | ||
git tag ${{ env.NEW_VERSION }} | ||
- name: Run status checks for release commit on temporary branch # Use temporary branch to enable pushing commits to this branch protected by required status checks | ||
uses: CasperWA/push-protected@v2 | ||
with: | ||
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | ||
branch: main | ||
unprotect_reviews: true | ||
|
||
- name: Push changes to repository | ||
run: git push origin && git push --tags | ||
|
||
- name: Read version changelog | ||
uses: superfaceai/release-changelog-action@v2 | ||
id: get-changelog | ||
with: | ||
version: ${{ env.NEW_VERSION }} | ||
operation: read | ||
|
||
- name: Create GitHub release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{ env.NEW_VERSION }} | ||
body: ${{ steps.get-changelog.outputs.changelog }} | ||
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | ||
|
||
- name: Publish to NPM public repository | ||
uses: JS-DevTools/npm-publish@v1 | ||
with: | ||
token: ${{ secrets.NPMJS_ACCESS_TOKEN }} |
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,14 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format is based on [Common Changelog](https://common-changelog.org).\ | ||
Unlike Common Changelog, the `unreleased` section of [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) is preserved with the addition of a tag to specify which type of release should be published and to foster discussions about it inside pull requests. This tag should be one of the names mandated by SemVer, within brackets: `[patch]`, `[minor]` or `[major]`. For example: `## Unreleased [minor]`. | ||
|
||
## Unreleased [minor] | ||
|
||
### Added | ||
|
||
- Publish package on NPM under name `@opentermsarchive/engine`. | ||
- Export `filter`, `pageDeclaration` and `fetch` in NPM module. | ||
- Add changelog. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,3 @@ | ||
export { default as pageDeclaration } from './archivist/services/pageDeclaration.js'; | ||
export { default as filter } from './archivist/filter/exports.js'; | ||
export { default as fetch } from './archivist/fetcher/exports.js'; |