Skip to content

Commit 9cb9bd7

Browse files
committed
Add release workflow
1 parent 3c2da8f commit 9cb9bd7

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

.github/tools/create-release.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const [type] = Deno.args;
2+
3+
const ghOutput = Deno.env.get("GITHUB_OUTPUT")!;
4+
if (!ghOutput) {
5+
throw new Error("Can not find GITHUB_OUTPUT environment variable");
6+
}
7+
8+
if (!["major", "minor", "patch"].includes(type)) {
9+
throw new Error(
10+
"Invalid version bump type. Use 'major', 'minor', or 'patch'.",
11+
);
12+
}
13+
14+
const cargoTomlPath = "./Cargo.toml";
15+
const cargoToml = await Deno.readTextFile(cargoTomlPath);
16+
17+
// Extract version
18+
const versionRegex = /version\s*=\s*"(\d+)\.(\d+)\.(\d+)"/;
19+
const match = versionRegex.exec(cargoToml);
20+
if (!match) {
21+
throw new Error("Version not found in Cargo.toml");
22+
}
23+
24+
let [major, minor, patch] = match.slice(1).map(Number);
25+
26+
switch (type) {
27+
case "major":
28+
major++;
29+
minor = 0;
30+
patch = 0;
31+
break;
32+
case "minor":
33+
minor++;
34+
patch = 0;
35+
break;
36+
case "patch":
37+
patch++;
38+
break;
39+
}
40+
41+
const newVersion = `${major}.${minor}.${patch}`;
42+
const updatedCargoToml = cargoToml.replace(
43+
versionRegex,
44+
`version = "${newVersion}"`,
45+
);
46+
await Deno.writeTextFile(cargoTomlPath, updatedCargoToml);
47+
await Deno.writeTextFile(ghOutput, `NEW_VERSION=${newVersion}`, { append: true });
48+
49+
console.log(`Version updated to ${newVersion}`, ghOutput);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Create release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump_type:
7+
description: 'Select the type'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
version_bump:
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
- name: Set up Deno
27+
uses: denoland/setup-deno@v2
28+
with:
29+
deno-version: v2.x
30+
31+
- name: Bump version using Deno
32+
id: bump_version
33+
run: deno run -A .github/tools/create-release.ts ${{ inputs.bump_type }}
34+
35+
- name: Create Pull Request
36+
uses: peter-evans/create-pull-request@v5
37+
env:
38+
NEW_VERSION: ${{ steps.bump_version.outputs.NEW_VERSION }}
39+
with:
40+
token: ${{ secrets.GITHUB_TOKEN }}
41+
commit-message: "Bump version to ${{ env.NEW_VERSION }}"
42+
title: "Release (${{ env.NEW_VERSION }})"
43+
body: "This PR bumps the Cargo.toml version to ${{ env.NEW_VERSION }}."
44+
draft: false
45+
branch: "release/${{ env.NEW_VERSION }}"
46+
delete-branch: true
47+
labels: |
48+
release
49+
reviewers: jonasstrehle,benStre

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: Publish Crate
12
on:
23
release:
34
types: [published]

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2025 unyt.org
2+
3+
Permission is hereby granted, free of charge, to any
4+
person obtaining a copy of this software and associated
5+
documentation files (the "Software"), to deal in the
6+
Software without restriction, including without
7+
limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software
10+
is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice
14+
shall be included in all copies or substantial portions
15+
of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)