-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: release and publish from github actions #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5aaa765
chore: release and publish from github actions
Justineo 46a4193
fix: install pnpm before node
Justineo 91f56b4
improve ci
kingyue737 0631d06
add back build in test
kingyue737 d48adb0
fix: add back dist-tag
kingyue737 f4f0bac
update ci step names
kingyue737 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: CI | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
- '8.0' # remove this after 8.0 is merged into main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
cache: 'pnpm' | ||
|
||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 10.14.0 | ||
run_install: false | ||
|
||
- run: pnpm install --frozen-lockfile | ||
- run: pnpm run lint | ||
- run: pnpm run typecheck | ||
- run: pnpm run build | ||
kingyue737 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: pnpm run publint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to be a common practice to trigger releases via Git tags. Since we can extract the version directly from the tag, this simplifies the process |
||
|
||
permissions: | ||
id-token: write | ||
contents: write | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
environment: npm-publish | ||
|
||
steps: | ||
# ───── 基础环境 ───── | ||
- uses: actions/checkout@v4 | ||
kingyue737 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
cache: pnpm | ||
|
||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 10.14.0 | ||
run_install: false | ||
|
||
- run: pnpm install --frozen-lockfile | ||
|
||
- id: pkg | ||
run: echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT" | ||
|
||
- id: tag | ||
run: echo "tag=$(pnpm exec jiti scripts/dist-tag.ts '${{ steps.pkg.outputs.version }}')" >> "$GITHUB_OUTPUT" | ||
|
||
- run: pnpm exec jiti scripts/changelog.ts '${{ steps.pkg.outputs.version }}' > tmp_release_body.md | ||
kingyue737 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- run: corepack prepare [email protected] --activate | ||
|
||
- name: Publish to npm | ||
run: | | ||
pnpm exec [email protected] publish \ | ||
--tag '${{ steps.tag.outputs.tag }}' \ | ||
--access public | ||
|
||
- uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: v${{ steps.pkg.outputs.version }} | ||
body_path: tmp_release_body.md | ||
prerelease: ${{ startsWith(steps.pkg.outputs.version, '0') || contains(steps.pkg.outputs.version, '-') }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
onlyBuiltDependencies: | ||
- esbuild | ||
kingyue737 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { readFileSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
/** | ||
* Extract the changelog section for the given version from CHANGELOG.md | ||
* and print it to stdout (without leading/trailing blank lines). | ||
* | ||
* Usage: | ||
* npx jiti scripts/changelog.ts 7.0.3 > tmp_release_body.md | ||
*/ | ||
|
||
const version = process.argv[2]; | ||
|
||
if (!version) { | ||
console.error("Usage: jiti scripts/changelog.ts <version>"); | ||
process.exit(1); | ||
} | ||
|
||
const header = `## ${version}`; | ||
const changelogPath = join(process.cwd(), "CHANGELOG.md"); | ||
const lines = readFileSync(changelogPath, "utf8").split(/\r?\n/); | ||
|
||
let capturing = false; | ||
const section: string[] = []; | ||
|
||
for (const line of lines) { | ||
if (line.startsWith("## ")) { | ||
if (capturing) break; // reached next version header | ||
if (line.trim() === header) { | ||
capturing = true; // start capturing after header | ||
continue; // skip header line itself | ||
} | ||
} | ||
if (capturing) section.push(line); | ||
} | ||
|
||
// Trim leading / trailing blank lines | ||
while (section.length && section[0].trim() === "") section.shift(); | ||
while (section.length && section[section.length - 1].trim() === "") | ||
section.pop(); | ||
|
||
if (section.length === 0) { | ||
console.error(`No changelog entry found for version ${version}`); | ||
process.exit(1); | ||
} | ||
|
||
console.log(section.join("\n")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** Resolve npm dist-tag from a semver string. | ||
* Usage: jiti scripts/dist-tag.ts 1.2.3-beta.0 # → beta | ||
* jiti scripts/dist-tag.ts # picks version from package.json | ||
*/ | ||
import { readFileSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
// Prefer CLI arg, otherwise read package.json | ||
const version: string = | ||
process.argv[2] ?? | ||
JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf8")).version; | ||
|
||
// Capture first recognised prerelease label | ||
const tag = | ||
version.match(/-(alpha|beta|rc)\b/i)?.[1].toLowerCase() ?? "latest"; | ||
|
||
console.log(tag); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.