Skip to content

Commit ac8c3ae

Browse files
authored
chore: release workflow (#6671)
1 parent a36d683 commit ac8c3ae

File tree

7 files changed

+180
-26
lines changed

7 files changed

+180
-26
lines changed

Diff for: .github/workflows/create-release-tag.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Create Release
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
create-release:
6+
name: Create Release
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v3
11+
with:
12+
fetch-depth: 1
13+
14+
- name: Extract version from branch name
15+
id: extract_version
16+
run: |
17+
BRANCH_NAME="${GITHUB_REF##*/}"
18+
echo "Branch name: $BRANCH_NAME"
19+
20+
if [[ "$BRANCH_NAME" =~ ^release-v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
21+
VERSION="${BASH_REMATCH[1]}"
22+
echo "Extracted version: $VERSION"
23+
echo "version=$VERSION" >> $GITHUB_ENV
24+
else
25+
echo "Branch name does not match the expected format (release-vx.x.x)"
26+
exit 1
27+
fi
28+
29+
- name: Get PR body
30+
id: get_pr_body
31+
uses: actions/github-script@v6
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
script: |
36+
const branchName = process.env.GITHUB_REF.replace('refs/heads/', '');
37+
38+
const { data: pulls } = await github.rest.pulls.list({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
state: 'all',
42+
base: 'main',
43+
head: `${context.repo.owner}:${branchName}`
44+
});
45+
46+
if (pulls.length === 0) {
47+
core.setFailed('No pull request found for this branch.');
48+
} else {
49+
const pr = pulls[0];
50+
core.info(`Found PR: ${pr.title}`);
51+
core.setOutput('body', pr.body || '');
52+
}
53+
54+
55+
- name: Create Release
56+
id: create_release
57+
uses: actions/create-release@v1
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
tag_name: v${{ env.version }}
62+
release_name: v${{ env.version }}
63+
body: ${{ steps.get_pr_body.outputs.body }}
64+
draft: false
65+
prerelease: false

Diff for: .github/workflows/release-pull-request.yml

+27-22
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ name: Release Pull Request
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
type: choice
8-
description: 'Release Type(next, beta, alpha, latest)'
9-
required: true
10-
default: 'latest'
11-
options:
12-
- next
13-
- beta
14-
- alpha
15-
- latest
165
jobs:
176
release:
187
name: Create Release Pull Request
@@ -49,15 +38,31 @@ jobs:
4938
- name: Prepare Monorepo-Tools
5039
run: pnpm run --filter @modern-js/monorepo-tools... build
5140

52-
- name: Create Release Pull Request
53-
uses: web-infra-dev/actions@v2
41+
- name: Get Release Version
42+
id: get-release-version
43+
run: |
44+
output=$(pnpm run get-release-version)
45+
version=$(echo "$output" | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+')
46+
echo "version=$version" >> $GITHUB_OUTPUT
47+
48+
- name: Get Release Note
49+
id: get-release-note
50+
run: |
51+
output=$(pnpm run gen-release-note | tail -n +7)
52+
echo "release_note<<EOF" >> $GITHUB_OUTPUT
53+
echo "$output" >> $GITHUB_OUTPUT
54+
echo "EOF" >> $GITHUB_OUTPUT
55+
56+
- name: Bump Version
57+
run: |
58+
pnpm run bump
59+
pnpm install
60+
61+
- name: Create Pull Request
62+
uses: peter-evans/create-pull-request@v7
5463
with:
55-
# this expects you to have a script called release which does a build for your packages and calls changeset publish
56-
version: ${{ github.event.inputs.version || 'latest' }}
57-
versionNumber: 'auto'
58-
type: 'pull request'
59-
tools: 'modern'
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62-
REPOSITORY: ${{ github.repository }}
63-
REF: ${{ github.ref }}
64+
token: ${{ secrets.GITHUB_TOKEN }}
65+
commit-message: "Release: ${{ steps.get-release-version.outputs.version }}"
66+
branch: release-${{ steps.get-release-version.outputs.version }}
67+
title: "Release: ${{ steps.get-release-version.outputs.version }}"
68+
body: ${{ steps.get-release-note.outputs.release_note }}

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"pre": "modern pre",
3636
"change-status": "modern change-status",
3737
"gen-release-note": "modern gen-release-note",
38+
"get-release-version": "cd ./scripts/release-version && pnpm start",
3839
"release": "modern release --ignore-scripts",
3940
"fix:lockfile": "pnpm install --fix-lockfile",
4041
"update:lockfile": "pnpm install --lockfile-only",

Diff for: pnpm-lock.yaml

+26-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/release-version/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@scripts/release-versin",
3+
"version": "2.63.4",
4+
"private": true,
5+
"scripts": {
6+
"dev": "tsc --watch",
7+
"build": "tsc",
8+
"start": "tsx ./src/index.ts"
9+
},
10+
"dependencies": {
11+
"@changesets/read": "^0.5.9",
12+
"@manypkg/get-packages": "^1.1.3",
13+
"@changesets/config": "^2.1.1",
14+
"@changesets/assemble-release-plan": "^5.2.1"
15+
},
16+
"devDependencies": {
17+
"@types/node": "^18.0.1",
18+
"tsx": "^3.12.7"
19+
}
20+
}

Diff for: scripts/release-version/src/index.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import path from 'path';
2+
import assembleReleasePlan from '@changesets/assemble-release-plan';
3+
import { read } from '@changesets/config';
4+
import readChangesets from '@changesets/read';
5+
import { getPackages } from '@manypkg/get-packages';
6+
7+
async function run() {
8+
const cwd = process.cwd();
9+
const repoDir = path.join(cwd, '../../');
10+
const changesets = await readChangesets(repoDir, process.env.BASE_BRANCH);
11+
const packages = await getPackages(repoDir);
12+
const config = await read(repoDir, packages);
13+
const releasePlan = assembleReleasePlan(
14+
changesets,
15+
packages,
16+
config,
17+
undefined,
18+
);
19+
if (releasePlan.releases.length === 0) {
20+
return;
21+
}
22+
const releaseVersion = `v${
23+
releasePlan.releases.filter(
24+
release => !release.name.includes('generator'),
25+
)[0].newVersion
26+
}`;
27+
console.log(releaseVersion);
28+
}
29+
30+
run().catch(e => {
31+
console.error(e);
32+
process.exit(1);
33+
});

Diff for: scripts/release-version/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@modern-js/tsconfig/base",
3+
"compilerOptions": {
4+
"baseUrl": "./",
5+
"outDir": "./dist"
6+
},
7+
"include": ["src"]
8+
}

0 commit comments

Comments
 (0)