Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit ac38b88

Browse files
committed
Create npm release CD pipeline utilizing lerna
Manually create commits, tags, and GitHub releases, even though `lerna` could handle them, just to keep this release pipeline as consistent and similar to our other open-source packages as possible.
1 parent 7305174 commit ac38b88

4 files changed

Lines changed: 3317 additions & 41 deletions

File tree

.github/workflows/cd.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "CD"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
description: "Type of release?"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
release:
17+
name: "Release"
18+
if: ${{ github.ref == 'refs/heads/master' }}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: "Checkout code"
22+
uses: actions/checkout@v2
23+
with:
24+
token: ${{ secrets.GH_PAT }}
25+
26+
- name: "Set up Node"
27+
uses: actions/setup-node@v2
28+
with:
29+
node-version: '12'
30+
cache: 'yarn'
31+
32+
- name: "Install dependencies"
33+
run: yarn install --frozen-lockfile
34+
35+
- name: "Build the sources"
36+
run: yarn build
37+
38+
- name: "Publish to npm"
39+
id: publish
40+
run: |
41+
yarn publish:all ${{ github.event.inputs.release-type }}
42+
echo "::set-output name=version::$(node --print 'require("./lerna.json").version')"
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
46+
- name: "Update the changelog"
47+
# Find the first line that starts with `###` or `## [<number>` from the CHANGELOG and insert the new version header before it.
48+
run: |
49+
current_date="$(date -u '+%Y-%m-%d')"
50+
sed -i "0,/^\(###\|## *\[[0-9]\).*/{s//## [${{ steps.publish.outputs.version }}] - ${current_date}\n\n&/}" CHANGELOG.md
51+
52+
- name: "Extract version's changelog for release notes"
53+
# 1. Find the lines between the first `## [<number>` and the second `## [<number>`.
54+
# 2. Remove all leading and trailing newlines from the output.
55+
run: sed '1,/^## *\[[0-9]/d;/^## *\[[0-9]/Q' CHANGELOG.md | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.txt
56+
57+
- name: "Commit and tag the changes"
58+
uses: EndBug/add-and-commit@8c12ff729a98cfbcd3fe38b49f55eceb98a5ec02 # v7.5.0
59+
with:
60+
add: '["lerna.json", "*package.json", "CHANGELOG.md"]'
61+
message: 'Release ${{ steps.publish.outputs.version }}'
62+
tag: 'v${{ steps.publish.outputs.version }} --annotate --file /dev/null'
63+
default_author: github_actions
64+
pathspec_error_handling: exitImmediately
65+
66+
- name: "Create a GitHub release"
67+
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1
68+
with:
69+
tag_name: v${{ steps.publish.outputs.version }}
70+
name: v${{ steps.publish.outputs.version }}
71+
body_path: release_notes.txt

lerna.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": "1.0.1",
3+
"packages": ["packages/*"],
4+
"npmClient": "yarn",
5+
"useWorkspaces": true
6+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"packages/*"
55
],
66
"scripts": {
7-
"build": "for dir in packages/*; do echo \"$dir\" && yarn --cwd=\"$dir\" build; done",
8-
"clean": "for dir in packages/*; do echo \"$dir\" && yarn --cwd=\"$dir\" clean; done",
7+
"build": "lerna run build",
8+
"clean": "lerna run clean",
9+
"publish:all": "lerna publish --force-publish='*' --exact --no-git-tag-version --yes",
910
"format": "prettier --write '**/*.{ts,js,json}' && eslint --fix --max-warnings=0 --ext=.ts,.js .",
1011
"lint": "prettier --check '**/*.{ts,js,json}' && eslint --max-warnings=0 --ext=.ts,.js .",
1112
"type-check": "yarn tsc --noEmit",
@@ -22,6 +23,7 @@
2223
"eslint-plugin-import": "2.25.4",
2324
"eslint-plugin-simple-import-sort": "7.0.0",
2425
"jest": "27.4.7",
26+
"lerna": "4.0.0",
2527
"prettier": "2.5.1",
2628
"supertest": "6.1.6",
2729
"ts-jest": "27.1.2",

0 commit comments

Comments
 (0)