Skip to content

Commit c308883

Browse files
committed
ci: add semantic-release
1 parent fefe10b commit c308883

7 files changed

Lines changed: 6334 additions & 1 deletion

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Release preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
preview:
13+
if: github.event.pull_request.head.repo.full_name == github.repository
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
fetch-depth: 0
20+
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: 26
24+
cache: npm
25+
26+
- run: npm ci
27+
28+
- id: preview
29+
run: |
30+
GITHUB_EVENT_NAME=push GITHUB_REF="refs/heads/$BRANCH" \
31+
node --input-type=module -e '
32+
import { readFileSync, writeFileSync } from "node:fs";
33+
import semanticRelease from "semantic-release";
34+
// haddock-since verifyConditions needs stack on PATH; not worth a GHC install for a preview
35+
const { plugins } = JSON.parse(readFileSync(".releaserc.json", "utf8"));
36+
const res = await semanticRelease({
37+
dryRun: true,
38+
branches: [process.env.BRANCH],
39+
plugins: plugins.filter((p) => !(Array.isArray(p) ? p[0] : p).includes("haddock-since")),
40+
});
41+
writeFileSync("comment.md", res?.nextRelease
42+
? `## Release preview\n\nNext version: \`${res.nextRelease.version}\`\n\n${res.nextRelease.notes}`
43+
: "## Release preview\n\nNo release would be published from this branch.\n");
44+
'
45+
env:
46+
BRANCH: ${{ github.head_ref }}
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- run: gh pr comment "$NUMBER" --body-file comment.md --edit-last --create-if-none
50+
env:
51+
NUMBER: ${{ github.event.pull_request.number }}
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/release.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
build:
14+
uses: ./.github/workflows/stack.yml
15+
16+
release:
17+
needs: build
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
23+
24+
# puts stack/GHC on PATH and warms .stack-work for semantic-release-haddock-since
25+
- uses: freckle/stack-action@v5
26+
with:
27+
test: false
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 26
32+
cache: npm
33+
34+
- run: npm ci
35+
36+
- run: npx semantic-release
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/stack.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
workflow_call:
6+
7+
jobs:
8+
generate-matrix:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
stack-yamls: ${{ steps.matrix.outputs.stack-yamls }}
12+
steps:
13+
- uses: actions/checkout@v6
14+
15+
- id: matrix
16+
uses: freckle/stack-action/generate-matrix@v5
17+
18+
build:
19+
needs: generate-matrix
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, macos-latest]
25+
stack-yaml: ${{ fromJSON(needs.generate-matrix.outputs.stack-yamls) }}
26+
steps:
27+
- uses: actions/checkout@v6
28+
29+
- uses: freckle/stack-action@v5
30+
env:
31+
STACK_YAML: ${{ matrix.stack-yaml }}

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.polysemy-cache
21
.stack-work/
32
dist-newstyle/
3+
node_modules/
44
*~

‎.releaserc.json‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"branches": [
3+
"main"
4+
],
5+
"tagFormat": "${version}",
6+
"plugins": [
7+
[
8+
"@semantic-release/commit-analyzer",
9+
{
10+
"preset": "conventionalcommits",
11+
"releaseRules": [
12+
{
13+
"breaking": true,
14+
"release": "minor"
15+
},
16+
{
17+
"type": "feat",
18+
"release": "patch"
19+
},
20+
{
21+
"type": "docs",
22+
"release": "patch"
23+
},
24+
{
25+
"type": "fix",
26+
"release": "patch"
27+
},
28+
{
29+
"type": "perf",
30+
"release": "patch"
31+
},
32+
{
33+
"revert": true,
34+
"release": "patch"
35+
}
36+
]
37+
}
38+
],
39+
[
40+
"@semantic-release/release-notes-generator",
41+
{
42+
"preset": "conventionalcommits",
43+
"presetConfig": {}
44+
}
45+
],
46+
"@semantic-release/changelog",
47+
"semantic-release-haddock-since",
48+
[
49+
"@semantic-release/git",
50+
{
51+
"assets": [
52+
"package.yaml",
53+
"*.cabal",
54+
"src/**/*.hs",
55+
"api/*.api",
56+
"CHANGELOG.md"
57+
]
58+
}
59+
],
60+
"@semantic-release/github"
61+
]
62+
}

0 commit comments

Comments
 (0)