Skip to content

Commit 6b4c1a3

Browse files
authored
Merge pull request #139 from platformatic/publish-release
fix: Automate releases.
2 parents 7f571f7 + 4e6b450 commit 6b4c1a3

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Publish release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'The version number to tag and release'
8+
required: true
9+
type: string
10+
prerelease:
11+
description: 'Release as pre-release'
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
jobs:
17+
release-npm:
18+
runs-on: ubuntu-latest
19+
environment: main
20+
permissions:
21+
id-token: write
22+
contents: write
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: latest
30+
- name: Use supported Node.js Version
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: 22
34+
registry-url: 'https://registry.npmjs.org'
35+
cache: 'pnpm'
36+
- name: Restore cached dependencies
37+
uses: actions/cache@v3
38+
with:
39+
path: ~/.pnpm-store
40+
key: node-modules-${{ hashFiles('package.json') }}
41+
- name: Install dependencies
42+
run: pnpm install
43+
- name: Bump Version
44+
run: node scripts/bump-version.js "${{ inputs.version }}" "${{ github.actor }}"
45+
env:
46+
GITHUB_ACTIONS: 'true'
47+
- name: Push changes
48+
run: git push origin HEAD:${{ github.ref }}
49+
- name: Update npm
50+
run: npm install -g npm@latest
51+
- name: Publish to NPM
52+
run: pnpm publish --access public --tag ${{ inputs.prerelease == true && 'next' || 'latest' }} --publish-branch ${{ github.ref_name }} --no-git-checks
53+
- name: 'Create release notes'
54+
run: |
55+
pnpx @matteo.collina/release-notes -a ${{ secrets.GH_RELEASE_TOKEN }} -t v${{ inputs.version }} -r watt-admin -o platformatic ${{ github.event.inputs.prerelease == 'true' && '-p' || '' }} -c ${{ github.ref }}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/bump-version.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env -S node
2+
3+
import { execSync } from 'node:child_process'
4+
import { readFile, writeFile } from 'node:fs/promises'
5+
import { inc } from 'semver'
6+
7+
function getUserInfo () {
8+
const username = process.argv[3] ?? process.env.GITHUB_ACTOR
9+
const defaultUser = 'mcollina'
10+
11+
const users = {
12+
mcollina: ['Matteo Collina', 'hello@matteocollina.com'],
13+
ShogunPanda: ['Paolo Insogna', 'paolo@cowtech.it']
14+
}
15+
16+
let userInfo = users[username]
17+
18+
if (!userInfo) {
19+
userInfo = users[defaultUser]
20+
}
21+
22+
return userInfo
23+
}
24+
25+
async function getVersion () {
26+
const version = process.argv[2].replace(/^v/, '')
27+
28+
if (['minor', 'major', 'patch'].includes(process.argv[2])) {
29+
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
30+
return inc(packageJson.version, version)
31+
}
32+
33+
return version
34+
}
35+
36+
async function updatePackageJson (version) {
37+
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
38+
packageJson.version = version
39+
await writeFile('package.json', JSON.stringify(packageJson, null, 2))
40+
}
41+
42+
const userInfo = getUserInfo()
43+
const version = await getVersion()
44+
45+
await updatePackageJson(version)
46+
47+
if (process.env.GITHUB_ACTIONS === 'true') {
48+
execSync(`git config --global user.name "${userInfo[0]}"`)
49+
execSync(`git config --global user.email "${userInfo[1]}"`)
50+
}
51+
52+
execSync(`git commit -a -m "chore: Bumped v${version}." -m "Signed-off-by: ${userInfo[0]} <${userInfo[1]}>"`)

0 commit comments

Comments
 (0)