Skip to content

Commit 41693e8

Browse files
committed
chore(ci): add github actions and semantic release
1 parent ecd9f3f commit 41693e8

9 files changed

Lines changed: 237 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master, develop]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up JDK 21
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: "21"
20+
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v3
23+
with:
24+
cache-read-only: ${{ github.event_name == 'pull_request' }}
25+
26+
- name: Build
27+
run: ./gradlew build

.github/workflows/release.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up JDK 21
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: "21"
20+
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v3
23+
with:
24+
cache-read-only: true
25+
26+
- name: Build
27+
run: ./gradlew build
28+
29+
release:
30+
runs-on: ubuntu-latest
31+
needs: build
32+
permissions:
33+
contents: write
34+
issues: write
35+
pull-requests: write
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Set up JDK 21
43+
uses: actions/setup-java@v4
44+
with:
45+
distribution: temurin
46+
java-version: "21"
47+
48+
- name: Setup Gradle
49+
uses: gradle/actions/setup-gradle@v3
50+
with:
51+
cache-read-only: true
52+
53+
- name: Set up Node.js
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: "20"
57+
cache: pnpm
58+
59+
- name: Set up pnpm
60+
uses: pnpm/action-setup@v4
61+
with:
62+
version: 9.12.3
63+
64+
- name: Install release tooling
65+
run: pnpm install --no-lockfile
66+
67+
- name: Configure Git user
68+
run: |
69+
git config user.name "github-actions[bot]"
70+
git config user.email "github-actions[bot]@users.noreply.github.com"
71+
72+
- name: Run semantic-release
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
run: pnpm run release

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ hs_err_pid*
2323
.idea/**/dynamic.xml
2424
.idea/**/uiDesigner.xml
2525
.idea/**/dbnavigator.xml
26+
.idea/
2627
.idea/**/gradle.xml
2728
.idea/**/libraries
2829
cmake-build-*/
@@ -44,4 +45,7 @@ fabric.properties
4445
gradle-app.setting
4546
!gradle-wrapper.jar
4647
.gradletasknamecache
47-
run/
48+
run/
49+
node_modules/
50+
pnpm-debug.log
51+
tsconfig.tsbuildinfo

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file by semantic-release.

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "voyager-release-tools",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "Semantic-release setup for the Voyager build",
6+
"license": "UNLICENSED",
7+
"engines": {
8+
"node": ">=18"
9+
},
10+
"packageManager": "pnpm@9.12.3",
11+
"scripts": {
12+
"release": "pnpm exec ts-node-esm ./scripts/run-semantic-release.mts",
13+
"bump-version": "node ./scripts/bump-version.js"
14+
},
15+
"devDependencies": {
16+
"@semantic-release/changelog": "6.0.3",
17+
"@semantic-release/commit-analyzer": "11.1.0",
18+
"@semantic-release/exec": "6.0.3",
19+
"@semantic-release/git": "10.0.1",
20+
"@semantic-release/github": "9.0.2",
21+
"@semantic-release/release-notes-generator": "12.1.0",
22+
"semantic-release": "23.0.0",
23+
"ts-node": "10.9.2",
24+
"typescript": "5.6.3"
25+
}
26+
}

release.config.mts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Options } from "semantic-release";
2+
3+
/** Semantic-release configuration using pnpm and Gradle version bumping. */
4+
const config: Options = {
5+
branches: ["main", "master"],
6+
tagFormat: "v${version}",
7+
plugins: [
8+
"@semantic-release/commit-analyzer",
9+
"@semantic-release/release-notes-generator",
10+
[
11+
"@semantic-release/changelog",
12+
{
13+
changelogFile: "CHANGELOG.md"
14+
}
15+
],
16+
[
17+
"@semantic-release/exec",
18+
{
19+
prepareCmd: "pnpm run bump-version ${nextRelease.version}"
20+
}
21+
],
22+
[
23+
"@semantic-release/git",
24+
{
25+
assets: ["CHANGELOG.md", "build.gradle.kts"],
26+
message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
27+
}
28+
],
29+
"@semantic-release/github"
30+
]
31+
};
32+
33+
export default config;

scripts/bump-version.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Replace the Gradle project version in build.gradle.kts with the provided value.
5+
* Used by semantic-release via @semantic-release/exec.
6+
*/
7+
const fs = require("fs");
8+
const path = require("path");
9+
10+
const [, , nextVersion] = process.argv;
11+
12+
if (!nextVersion) {
13+
console.error("No version supplied to bump-version script.");
14+
process.exit(1);
15+
}
16+
17+
const gradleFile = path.join(__dirname, "..", "build.gradle.kts");
18+
const fileContent = fs.readFileSync(gradleFile, "utf8");
19+
const versionPattern = /(^\s*version\s*=\s*")[^"]+(")/m;
20+
21+
if (!versionPattern.test(fileContent)) {
22+
console.error(`Could not find version declaration in ${gradleFile}`);
23+
process.exit(1);
24+
}
25+
26+
const updatedContent = fileContent.replace(versionPattern, `$1${nextVersion}$2`);
27+
fs.writeFileSync(gradleFile, updatedContent, "utf8");
28+
console.log(`Set project version to ${nextVersion}`);

scripts/run-semantic-release.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import semanticRelease from "semantic-release";
2+
import config from "../release.config.mts";
3+
4+
/**
5+
* Programmatic entrypoint so we can keep the release config in TypeScript (.mts).
6+
*/
7+
async function main() {
8+
const result = await semanticRelease(config);
9+
10+
if (!result) {
11+
console.log("No release published.");
12+
return;
13+
}
14+
15+
const { lastRelease, nextRelease, releases } = result;
16+
console.log(
17+
`Published ${nextRelease.type} release version ${nextRelease.version} ` +
18+
`(previous ${lastRelease ? lastRelease.version : "none"})`
19+
);
20+
releases.forEach((release) => {
21+
console.log(` - ${release.name} @ ${release.url}`);
22+
});
23+
}
24+
25+
main().catch((error) => {
26+
console.error(error);
27+
process.exit(1);
28+
});

tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"esModuleInterop": true,
7+
"resolveJsonModule": true,
8+
"strict": false,
9+
"skipLibCheck": true
10+
},
11+
"include": ["release.config.mts", "scripts/**/*.mts"]
12+
}

0 commit comments

Comments
 (0)