Skip to content

Commit

Permalink
ci: add workflows for automated release & publish (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Oct 17, 2024
1 parent 824b2b8 commit d32c2f9
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 288 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Build, Lint, and Test

on:
push:
branches: [main]
pull_request:
workflow_call:

jobs:
build-lint-test:
Expand All @@ -13,20 +11,19 @@ jobs:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn --frozen-lockfile --ignore-scripts
- run: yarn build
- run: yarn lint
- run: yarn test
all-jobs-pass:
name: All jobs pass
runs-on: ubuntu-latest
needs:
- build-lint-test
steps:
- uses: actions/checkout@v2
- run: echo "Great success!"
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate
45 changes: 45 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create Release Pull Request

permissions:
contents: write
pull-requests: write

on:
workflow_dispatch:
inputs:
base-branch:
description: 'The base branch for git operations and the pull request.'
default: 'main'
required: true
release-type:
description: 'A SemVer version diff, i.e. major, minor, patch, prerelease etc. Mutually exclusive with "release-version".'
required: false
release-version:
description: 'A specific version to bump to. Mutually exclusive with "release-type".'
required: false

jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
# This is to guarantee that the most recent tag is fetched.
# This can be configured to a more reasonable value by consumers.
fetch-depth: 0
# We check out the specified branch, which will be used as the base
# branch for all git operations and the release PR.
ref: ${{ github.event.inputs.base-branch }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-create-release-pr@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release-type: ${{ github.event.inputs.release-type }}
release-version: ${{ github.event.inputs.release-version }}
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Main

on:
push:
branches: [main]
pull_request:

jobs:
build-lint-test:
name: Test
uses: ./.github/workflows/build-lint-test.yml

all-jobs-completed:
name: All jobs completed
runs-on: ubuntu-latest
needs:
- build-lint-test
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
steps:
- name: Set PASSED output
id: set-output
run: echo "PASSED=true" >> "$GITHUB_OUTPUT"

all-jobs-pass:
name: All jobs pass
if: ${{ always() }}
runs-on: ubuntu-latest
needs: all-jobs-completed
steps:
- name: Check that all jobs have passed
run: |
passed="${{ needs.all-jobs-completed.outputs.PASSED }}"
if [[ $passed != "true" ]]; then
exit 1
fi
is-release:
# Filtering by `push` events ensures that we only release from the `main` branch, which is a
# requirement for our npm publishing environment.
# The commit author should always be 'github-actions' for releases created by the
# 'create-release-pr' workflow, so we filter by that as well to prevent accidentally
# triggering a release.
if: github.event_name == 'push' && startsWith(github.event.head_commit.author.name, 'github-actions')
needs: all-jobs-pass
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
runs-on: ubuntu-latest
steps:
- uses: MetaMask/action-is-release@v2
id: is-release

publish-release:
needs: is-release
if: needs.is-release.outputs.IS_RELEASE == 'true'
name: Publish release
permissions:
contents: write
uses: ./.github/workflows/publish-release.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
83 changes: 83 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Publish Release

on:
workflow_call:
secrets:
NPM_TOKEN:
required: true

jobs:
publish-release:
permissions:
contents: write
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
# TODO: use default version when node.engines has been bumped to at least v16 in package.json
node-version: '20.x'
- uses: MetaMask/action-publish-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install
run: |
yarn --frozen-lockfile --ignore-scripts
yarn build
- uses: actions/cache@v4
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}

publish-npm-dry-run:
runs-on: ubuntu-latest
needs: publish-release
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v4
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v2
env:
SKIP_PREPACK: true

publish-npm:
environment: npm-publish
runs-on: ubuntu-latest
needs: publish-npm-dry-run
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/cache@v4
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Publish
uses: MetaMask/action-npm-publish@v2
with:
# This `NPM_TOKEN` needs to be manually set per-repository.
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
npm-token: ${{ secrets.NPM_TOKEN }}
env:
SKIP_PREPACK: true
25 changes: 8 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [3.1.1] - 2024-03-12

### Fixed

- Fix ESM module path ([#143](https://github.com/MetaMask/safe-event-emitter/pull/143))
- Fix ESM source map paths ([#146](https://github.com/MetaMask/safe-event-emitter/pull/146))

## [3.1.0] - 2024-03-08

### Added

- Add ESM build ([#141](https://github.com/MetaMask/safe-event-emitter/pull/141))

## [3.0.0] - 2023-04-24

### Breaking

- Drop support for Node.js < v12 ([#101](https://github.com/MetaMask/safe-event-emitter/pull/101))

### Changed

- devDependencies and CI updates
- **BREAKING**: Drop support for Node.js < v12 ([#101](https://github.com/MetaMask/safe-event-emitter/pull/101))

## [2.0.0] - 2020-09-02

### Changed

- Migrate to TypeScript ([#1](https://github.com/MetaMask/safe-event-emitter/pull/1))

[Unreleased]:https://github.com/MetaMask/safe-event-emitter/compare/v2.0.0...HEAD
[2.0.0]:https://github.com/MetaMask/safe-event-emitter/tree/v2.0.0
[Unreleased]: https://github.com/MetaMask/safe-event-emitter/compare/v3.1.1...HEAD
[3.1.1]: https://github.com/MetaMask/safe-event-emitter/compare/v3.1.0...v3.1.1
[3.1.0]: https://github.com/MetaMask/safe-event-emitter/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/MetaMask/safe-event-emitter/compare/v2.0.0...v3.0.0
[2.0.0]: https://github.com/MetaMask/safe-event-emitter/releases/tag/v2.0.0
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@metamask/auto-changelog": "^2.6.1",
"@metamask/eslint-config": "^5.0.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.21",
Expand Down
Loading

0 comments on commit d32c2f9

Please sign in to comment.