chore: ci

This commit is contained in:
xilesun 2024-09-02 11:39:11 +08:00
parent 567d2e961f
commit 91e0a68ab8
3 changed files with 67 additions and 7 deletions

View File

@ -0,0 +1,55 @@
name: Write changelog and create release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- feat/auto-changelog
tags:
- 'v*-beta'
jobs:
app-token:
uses: nocobase/nocobase/.github/workflows/get-nocobase-app-token.yml@main
secrets: inherit
write-changelog-and-release:
needs:
- app-token
runs-on: ubuntu-latest
steps:
- name: Decrypt app token
id: app-token
shell: bash
run: |
ENCRYPTED_SECRET=${{ needs.app-token.outputs.token }};
APP_TOKEN=$(echo -n "$ENCRYPTED_SECRET" | base64 --decode | openssl enc -aes-256-cbc -pbkdf2 -d -salt -k "${{ secrets.APP_TOKEN_ENCRYPTION_PASSWORD }}");
echo "token=$APP_TOKEN" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
with:
repository: nocobase/nocobase
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true
fetch-depth: 0
- name: Set user
run: |
git config --global user.name '${{ needs.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ needs.app-token.outputs.user-id }}+${{ needs.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- name: Set Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Run release.sh
shell: bash
run: |
node scripts/release/changelogAndRelease.js
env:
PRO_PLUGIN_REPOS: ${{ vars.PRO_PLUGIN_REPOS }}
- name: Commit and push
run: |
git add .
git commit -m "docs: update changelogs"
# git push origin main

View File

@ -28,7 +28,4 @@ cd ../../
git add . git add .
git commit -m "chore(versions): 😊 publish v$(jq -r '.version' lerna.json)" git commit -m "chore(versions): 😊 publish v$(jq -r '.version' lerna.json)"
git tag v$(jq -r '.version' lerna.json) git tag v$(jq -r '.version' lerna.json)
yarn changelog --breaking-pattern "BREAKING CHANGE:"
git add .
git commit -m "chore: update changelog"
# git push --atomic origin main v$(jq -r '.version' lerna.json) # git push --atomic origin main v$(jq -r '.version' lerna.json)

View File

@ -4,7 +4,7 @@ const path = require('path');
const { Command } = require('commander'); const { Command } = require('commander');
const program = new Command(); const program = new Command();
program.option('-f, --from [from]').option('-t, --to [to]').option('-b, --branch [branch]'); program.option('-f, --from [from]').option('-t, --to [to]').option('-v, --version [version]');
program.parse(process.argv); program.parse(process.argv);
const header = { const header = {
@ -179,10 +179,10 @@ function arrangeChangelogs(changelogs) {
} }
async function collect() { async function collect() {
let { from, to, branch = 'main' } = program.opts(); let { from, to, version = 'beta' } = program.opts();
if (!from || !to) { if (!from || !to) {
// git describe --tags $(git rev-list --tags --max-count=2) --abbrev=0 // git describe --tags $(git rev-list --tags --max-count=2) --abbrev=0
const tagPattern = branch === 'main' ? 'v*-beta' : 'v*-alpha'; const tagPattern = `v*-${version}`;
const { stdout: tags } = await execa( const { stdout: tags } = await execa(
'git', 'git',
['describe', '--tags', `$(git rev-list --tags=${tagPattern} --max-count=2)`, '--abbrev=0'], ['describe', '--tags', `$(git rev-list --tags=${tagPattern} --max-count=2)`, '--abbrev=0'],
@ -320,16 +320,24 @@ async function writeChangelog(cn, en, from, to) {
} }
async function createRelease(cn, en, to) { async function createRelease(cn, en, to) {
let { version = 'beta' } = program.opts();
// gh release create -t title -n note -d // gh release create -t title -n note -d
if (version === 'alpha') {
await execa('gh', ['release', 'create', to, '-t', to, '-n', `${en}\n---\n${cn}`, '-d', '-p']);
return;
}
await execa('gh', ['release', 'create', to, '-t', to, '-n', `${en}\n---\n${cn}`, '-d']); await execa('gh', ['release', 'create', to, '-t', to, '-n', `${en}\n---\n${cn}`, '-d']);
} }
async function writeChangelogAndCreateRelease() { async function writeChangelogAndCreateRelease() {
let { version = 'beta' } = program.opts();
const { cn, en, from, to } = await generateChangelog(); const { cn, en, from, to } = await generateChangelog();
if (!cn && !en) { if (!cn && !en) {
throw new Error('No changelog generated'); throw new Error('No changelog generated');
} }
await writeChangelog(cn, en, from, to); if (version === 'beta') {
await writeChangelog(cn, en, from, to);
}
await createRelease(cn, en, to); await createRelease(cn, en, to);
} }