mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
Merge pull request #2412 from logto-io/gao-add-publish-script
chore: add pubilsh script
This commit is contained in:
commit
ceb43d5d34
8 changed files with 68 additions and 90 deletions
|
@ -7,15 +7,15 @@
|
|||
"@logto/cli",
|
||||
"@logto/create"
|
||||
], [
|
||||
"@logto/console",
|
||||
"@logto/core",
|
||||
"@logto/console",
|
||||
"@logto/integration-tests",
|
||||
"@logto/ui"
|
||||
]],
|
||||
"linked": [[
|
||||
"@logto/schemas",
|
||||
"@logto/phrases",
|
||||
"@logto/phrases-ui",
|
||||
"@logto/schemas"
|
||||
"@logto/phrases-ui"
|
||||
]],
|
||||
"//": "END OF CAUTION",
|
||||
"access": "restricted",
|
||||
|
|
2
.github/workflows/integration-test.yml
vendored
2
.github/workflows/integration-test.yml
vendored
|
@ -25,7 +25,7 @@ jobs:
|
|||
run: pnpm -r build
|
||||
|
||||
- name: Package
|
||||
run: ./package.sh
|
||||
run: ./.scripts/package.sh
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
|
71
.github/workflows/publish.yml
vendored
71
.github/workflows/publish.yml
vendored
|
@ -1,71 +0,0 @@
|
|||
name: Publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
semver:
|
||||
description: Semver bump type
|
||||
required: true
|
||||
preid:
|
||||
description: Pre ID
|
||||
required: true
|
||||
default: alpha
|
||||
append:
|
||||
description: Additional options
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
environment: release
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: master
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.BOT_PAT }}
|
||||
|
||||
- name: Import GPG key
|
||||
uses: crazy-max/ghaction-import-gpg@v5
|
||||
with:
|
||||
gpg_private_key: ${{ secrets.BOT_GPG_KEY }}
|
||||
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }}
|
||||
git_user_signingkey: true
|
||||
git_commit_gpgsign: true
|
||||
|
||||
- name: Setup Node and pnpm
|
||||
uses: silverhand-io/actions-node-pnpm-run-steps@v2
|
||||
|
||||
- name: Configure Git user
|
||||
run: |
|
||||
git config --global user.email bot@silverhand.io
|
||||
git config --global user.name silverhand-bot
|
||||
|
||||
- name: Publish to GitHub
|
||||
# add `no-verify-access` due to https://github.com/lerna/lerna/issues/2788
|
||||
run: |
|
||||
pnpm \
|
||||
--package=conventional-changelog-conventionalcommits \
|
||||
--package=lerna@^5.0.0 \
|
||||
dlx lerna publish \
|
||||
-m "release: %s" \
|
||||
--conventional-commits \
|
||||
--preid=${{ github.event.inputs.preid }} \
|
||||
--no-verify-access \
|
||||
--sign-git-commit \
|
||||
--sign-git-tag \
|
||||
--no-push \
|
||||
--yes \
|
||||
${{ github.event.inputs.semver }} ${{ github.event.inputs.append }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.BOT_PAT }}
|
||||
|
||||
- name: Push to protected branch
|
||||
uses: CasperWA/push-protected@v2
|
||||
with:
|
||||
token: ${{ secrets.BOT_PAT }}
|
||||
branch: master
|
||||
tags: true
|
||||
timeout: 20
|
18
.github/workflows/release.yml
vendored
18
.github/workflows/release.yml
vendored
|
@ -104,9 +104,8 @@ jobs:
|
|||
- name: Create release pull request
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
# Disable temporarily since https://github.com/changesets/changesets/issues/833.
|
||||
# Wait for our customized publish flow.
|
||||
# publish: pnpm changeset tag
|
||||
# Use our customized publish flow. See https://github.com/changesets/changesets/issues/833 for the limit of changesets.
|
||||
publish: node .scripts/publish.js
|
||||
commit: 'release: version packages'
|
||||
title: 'release: version packages'
|
||||
# Create by our rules defined in `/.changeset/README.md`.
|
||||
|
@ -128,24 +127,15 @@ jobs:
|
|||
- name: Setup Node and pnpm
|
||||
uses: silverhand-io/actions-node-pnpm-run-steps@v2
|
||||
|
||||
- name: Extract changelog
|
||||
run: |
|
||||
git diff HEAD~1 HEAD --exit-code -- CHANGELOG.md | \
|
||||
tail -n +5 | \
|
||||
grep -E "^\+" | \
|
||||
sed -E 's/^\+//' | \
|
||||
cat -s \
|
||||
> /tmp/changelog.txt
|
||||
|
||||
- name: Build
|
||||
run: pnpm -r build
|
||||
|
||||
- name: Package
|
||||
run: ./package.sh
|
||||
run: ./.scripts/package.sh
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
token: ${{ secrets.BOT_PAT }}
|
||||
body_path: /tmp/changelog.txt
|
||||
body: <Release notes WIP>
|
||||
files: /tmp/logto.tar.gz
|
||||
|
|
2
.github/workflows/upload-annotations.yml
vendored
2
.github/workflows/upload-annotations.yml
vendored
|
@ -28,7 +28,7 @@ jobs:
|
|||
run: pnpm prepack
|
||||
|
||||
- name: Lint with Report
|
||||
run: pnpm -r --parallel lint:report && node merge-eslint-reports.js
|
||||
run: pnpm -r --parallel lint:report && node .scripts/merge-eslint-reports.js
|
||||
|
||||
- name: Annotate Code Linting Results
|
||||
uses: ataylorme/eslint-annotate-action@1.2.0
|
||||
|
|
59
.scripts/publish.js
Normal file
59
.scripts/publish.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* This script runs the following tasks:
|
||||
*
|
||||
* 1. Tag main packages defined in `.changeset/config.json` if they are not tagged with the current version in `package.json`;
|
||||
* 2. If no new git tag added, exit;
|
||||
* 3. If at least one new git tag found, run `pnpm -r publish` and `git push --tags`.
|
||||
*
|
||||
* The subsequential release tasks, such as create GitHub release and build Docker image, will be took over by GitHub workflows.
|
||||
*/
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const changesetConfig = require('../.changeset/config.json');
|
||||
|
||||
const corePackageName = '@logto/core';
|
||||
/** @type {Array<{ name: string; version?: string; path: string; private: boolean; }>} */
|
||||
const allPackages = JSON.parse(execSync('pnpm recursive list --depth=-1 --json', { encoding: 'utf8' }));
|
||||
const mainPackages = [...changesetConfig.fixed, ...changesetConfig.linked].map(([first]) => first);
|
||||
|
||||
const taggedPackages = mainPackages
|
||||
.map((packageName) => {
|
||||
const packageInfo = allPackages.find(({ name }) => name === packageName);
|
||||
|
||||
if (!packageInfo) {
|
||||
throw new Error(`Package ${packageName} not found`);
|
||||
}
|
||||
|
||||
const { name, version } = packageInfo;
|
||||
if (!version) {
|
||||
throw new Error(`No version found in package ${packageName}`);
|
||||
}
|
||||
|
||||
const tag = name + '@' + version;
|
||||
const hasTag = Boolean(execSync(`git tag -l ${tag}`, { encoding: 'utf8' }));
|
||||
|
||||
if (hasTag) {
|
||||
console.log(`Tag ${tag} exists, skipping`);
|
||||
return;
|
||||
}
|
||||
|
||||
execSync(`git tag -a ${tag} -m'${tag}'`);
|
||||
console.log(`Tag ${tag} added`);
|
||||
|
||||
if (packageName === corePackageName) {
|
||||
const semver = 'v' + version;
|
||||
execSync(`git tag -a ${semver} -m'${semver}'`);
|
||||
console.log(`Tag ${semver} added (SemVer of core package ${corePackageName})`);
|
||||
}
|
||||
|
||||
return packageName;
|
||||
})
|
||||
.filter((value) => !!value);
|
||||
|
||||
if (taggedPackages.length === 0) {
|
||||
console.log('No package tagged, exiting');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
execSync('pnpm -r publish');
|
||||
execSync('git push --tags');
|
Loading…
Reference in a new issue