Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
pull_request:
types: [closed]
branches:
- main

permissions:
contents: write

jobs:
release:
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Parse version from branch name
id: version
run: echo "value=$(node bin/parse-version.js '${{ github.event.pull_request.head.ref }}')" >> "$GITHUB_OUTPUT"
- name: Create tag and GitHub Release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.value }}
run: |
git tag "v$VERSION"
git push origin "v$VERSION"
gh release create "v$VERSION" --title "$VERSION" --generate-notes
20 changes: 20 additions & 0 deletions bin/parse-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node
import { pathToFileURL } from "node:url";

import { parseVersion } from "../src/release/parse-version.js";

function main() {
const branchName = process.argv[2];
const version = parseVersion(branchName);
if (!version) {
process.stderr.write(`parse-version: "${branchName}" is not a release/* branch\n`);
process.exit(1);
}
process.stdout.write(version);
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
main();
}

export { main };
4 changes: 4 additions & 0 deletions src/release/parse-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function parseVersion(branchName) {
const match = /^release\/(.+)$/.exec(branchName);
return match ? match[1] : null;
}
15 changes: 15 additions & 0 deletions test/release/parse-version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseVersion } from "../../src/release/parse-version.js";

test("parseVersion(\"release/0.0.0\") -> \"0.0.0\"", () => {
assert.equal(parseVersion("release/0.0.0"), "0.0.0");
});

test("parseVersion(\"release/1.2.3-beta.1\") -> \"1.2.3-beta.1\" (pre-release suffix passes through)", () => {
assert.equal(parseVersion("release/1.2.3-beta.1"), "1.2.3-beta.1");
});

test("parseVersion(\"feat/something\") -> null (not a release branch)", () => {
assert.equal(parseVersion("feat/something"), null);
});
Loading