Skip to content

Commit

Permalink
Automate package release with Semantic versioning (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt authored Dec 6, 2022
2 parents eceace1 + b07f62a commit c04cfbe
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/changelog.yml
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
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
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 }}
14 changes: 14 additions & 0 deletions CHANGELOG.md
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.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ First of all, thanks for taking the time to contribute! 🎉👍
- [Pull requests](#pull-requests)
- [Commit messages](#commit-messages)
- [Continuous delivery](#continuous-delivery)
- [Changelog](#changelog)
- [Development](#development)
- [Documentation](#documentation)
- [Naming](#naming)
Expand Down Expand Up @@ -52,6 +53,10 @@ We add this additional rule:

- Do not rely on GitHub issue reference numbers in commit messages, as we have no guarantee the host system and its autolinking will be stable in time. Make sure the context is self-explanatory. If an external reference is given, use its full URL.

### Changelog

All changes to the codebase that impact users must be documented in the [`CHANGELOG.md`](./CHANGELOG.md) file. The format to use is documented in the file itself.

## Development

### Documentation
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "open-terms-archive",
"version": "0.15.0",
"description": "Tracks and makes visible all changes to the Terms Of Service of online service providers.",
"name": "@opentermsarchive/engine",
"version": "0.16.0",
"description": "Tracks and makes visible changes to the terms of online services",
"homepage": "https://github.com/ambanum/OpenTermsArchive#readme",
"bugs": {
"url": "https://github.com/ambanum/OpenTermsArchive/issues"
Expand All @@ -14,6 +14,7 @@
"author": "ambanum",
"type": "module",
"exports": {
".": "./src/exports.js",
"./fetch": "./src/archivist/fetcher/exports.js",
"./filter": "./src/archivist/filter/exports.js",
"./page-declaration": "./src/archivist/services/pageDeclaration.js"
Expand All @@ -39,6 +40,12 @@
"posttest": "npm run lint",
"test:debug": "npm run test -- --inspect-brk --exit"
},
"files": [
"bin",
"config",
"scripts",
"src"
],
"dependencies": {
"@accordproject/markdown-cicero": "^0.15.2",
"@accordproject/markdown-pdf": "^0.15.2",
Expand Down
8 changes: 6 additions & 2 deletions src/archivist/recorder/repositories/git/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ describe('GitRepository', () => {
let records;
const expectedIds = [];

before(async () => {
before(async function () {
this.timeout(5000);

const { id: id1 } = await subject.save(new Record({
serviceId: SERVICE_PROVIDER_ID,
documentType: DOCUMENT_TYPE,
Expand Down Expand Up @@ -529,7 +531,9 @@ describe('GitRepository', () => {
describe('#count', () => {
let count;

before(async () => {
before(async function () {
this.timeout(5000);

await subject.save(new Record({
serviceId: SERVICE_PROVIDER_ID,
documentType: DOCUMENT_TYPE,
Expand Down
3 changes: 3 additions & 0 deletions src/exports.js
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';

0 comments on commit c04cfbe

Please sign in to comment.