Skip to content

Commit fd71570

Browse files
authored
ci: update release workflows (#2754)
1 parent b7882d4 commit fd71570

8 files changed

+89
-39
lines changed

.github/workflows/changesets.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Changesets
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
12+
jobs:
13+
changesets:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
# Set Git operations with the bot PAT since we have tag protection rule
20+
token: ${{ secrets.BOT_PAT }}
21+
fetch-depth: 0
22+
23+
- name: Setup Node and pnpm
24+
uses: silverhand-io/actions-node-pnpm-run-steps@v2
25+
with:
26+
node: 18
27+
28+
- name: Import GPG key
29+
uses: crazy-max/ghaction-import-gpg@v5
30+
with:
31+
gpg_private_key: ${{ secrets.BOT_GPG_KEY }}
32+
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }}
33+
git_user_signingkey: true
34+
git_commit_gpgsign: true
35+
git_tag_gpgsign: true
36+
37+
- name: Configure Git user
38+
run: |
39+
git config --global user.email [email protected]
40+
git config --global user.name silverhand-bot
41+
42+
- name: Version packages
43+
run: |
44+
pnpm changeset version
45+
pnpm i --no-frozen-lockfile
46+
git status
47+
48+
- name: Create pull request
49+
if: github.event_name == 'push'
50+
uses: peter-evans/create-pull-request@v4
51+
with:
52+
token: ${{ secrets.BOT_PAT }}
53+
commit-message: 'release: version packages'
54+
committer: silverhand-bot <[email protected]>
55+
author: silverhand-bot <[email protected]>
56+
base: master
57+
branch: release/version-packages
58+
title: 'release: version packages'
59+
body: 'This is an automatic pull request from the result of `pnpm changeset version` command. Merge it will trigger the publish flow for versioned packages.'

.github/workflows/release.yml

+6-27
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,15 @@ jobs:
7878
app-name: logto-dev
7979
images: svhd/logto:edge
8080

81-
release-changesets:
81+
# Publish packages and create git tags if needed
82+
publish-and-tag:
8283
runs-on: ubuntu-latest
8384
env:
84-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
85+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
8586

8687
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
87-
steps:
88-
- uses: actions/checkout@v3
89-
with:
90-
# Set Git operations with the bot PAT since we have tag protection rule
91-
token: ${{ secrets.BOT_PAT }}
92-
fetch-depth: 0
9388

89+
steps:
9490
- name: Setup Node and pnpm
9591
uses: silverhand-io/actions-node-pnpm-run-steps@v2
9692

@@ -103,25 +99,8 @@ jobs:
10399
git_commit_gpgsign: true
104100
git_tag_gpgsign: true
105101

106-
- name: Configure Git user
107-
run: |
108-
git config --global user.email [email protected]
109-
git config --global user.name silverhand-bot
110-
111-
- name: Create release pull request
112-
uses: changesets/action@v1
113-
with:
114-
# Use our customized publish flow. See https://github.com/changesets/changesets/issues/833 for the limit of changesets.
115-
publish: node .scripts/publish.js
116-
# `changeset version` won't run version lifecycle scripts, see https://github.com/changesets/changesets/issues/860
117-
version: pnpm ci:version
118-
commit: 'release: version packages'
119-
title: 'release: version packages'
120-
# Create by our rules defined in `/.changeset/README.md`.
121-
createGithubReleases: false
122-
setupGitUser: false
123-
env:
124-
GITHUB_TOKEN: ${{ secrets.BOT_PAT }}
102+
- name: Publish
103+
run: node .script/publish.js
125104

126105
create-github-release:
127106
environment: release

.scripts/merge-eslint-reports.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
import fs from 'fs';
32

43
const directories = [
54
...fs.readdirSync('./packages'),

.scripts/packages-meta.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { execSync } from 'node:child_process';
2+
import changesetConfig from '../.changeset/config.json' assert { type: 'json' };
3+
4+
export { default as changesetConfig } from '../.changeset/config.json' assert { type: 'json' };
5+
6+
export const corePackageName = '@logto/core';
7+
/** @type {Array<{ name: string; version?: string; path: string; private: boolean; }>} */
8+
export const allPackages = JSON
9+
.parse(execSync('pnpm recursive list --depth=-1 --json', { encoding: 'utf8' }))
10+
.filter(({ name }) => !name.endsWith('/root'));
11+
12+
export const mainPackages = [...changesetConfig.fixed].map(([first]) => first);
13+
14+
export const configuredPackages = new Set(changesetConfig.fixed.flat());
15+
export const singlePackages = allPackages
16+
.filter(({ name }) => !configuredPackages.has(name))
17+
.map(({ name }) => name);

.scripts/publish.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
/**
22
* This script runs the following tasks:
33
*
4-
* 1. Tag main packages defined in `.changeset/config.json` if they are not tagged with the current version in `package.json`;
4+
* 1. Tag the first package of fixed version groups defined in `.changeset/config.json` and other single packages if they are not tagged with the current version in `package.json`;
55
* 2. If no new git tag added, exit;
66
* 3. If at least one new git tag found, run `pnpm -r publish` and `git push --tags`.
77
*
88
* The subsequential release tasks, such as create GitHub release and build Docker image, will be took over by GitHub workflows.
99
*/
1010

11-
const { execSync } = require('child_process');
12-
const changesetConfig = require('../.changeset/config.json');
11+
import { execSync } from 'child_process';
12+
import { mainPackages, allPackages, singlePackages, corePackageName } from './packages-meta.js';
1313

14-
const corePackageName = '@logto/core';
15-
/** @type {Array<{ name: string; version?: string; path: string; private: boolean; }>} */
16-
const allPackages = JSON.parse(execSync('pnpm recursive list --depth=-1 --json', { encoding: 'utf8' }));
17-
const mainPackages = [...changesetConfig.fixed, ...changesetConfig.linked].map(([first]) => first);
18-
19-
const taggedPackages = mainPackages
14+
const taggedPackages = [...mainPackages, ...singlePackages]
2015
.map((packageName) => {
2116
const packageInfo = allPackages.find(({ name }) => name === packageName);
2217

File renamed without changes.

lint-staged.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
'*.ts?(x)': ['eslint --cache --fix', () => 'tsc -p tsconfig.json --noEmit'],
33
'*.scss': 'stylelint --fix',
44
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@logto/root",
33
"private": true,
44
"license": "MPL-2.0",
5+
"type": "module",
56
"scripts": {
67
"preinstall": "npx only-allow pnpm",
78
"prepare": "if test \"$NODE_ENV\" != \"production\" && test \"$CI\" != \"true\" ; then husky install ; fi",

0 commit comments

Comments
 (0)