Skip to content

Commit 52f193d

Browse files
ci: add release workflow and update dependances (#17)
1 parent 9114edc commit 52f193d

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

.github/scripts/create-release.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = async ({ github, context }) => {
2+
const newTag = process.env.NEW_TAG;
3+
const repository = process.env.REPOSITORY;
4+
5+
const { data } = await github.rest.repos.generateReleaseNotes({
6+
owner: context.repo.owner,
7+
repo: context.repo.repo,
8+
tag_name: newTag,
9+
});
10+
11+
const dockerInfo = `
12+
13+
---
14+
As with all our previous releases, you can find the Docker images:
15+
- [Backend](https://ghcr.io/${repository}/backend:${newTag})
16+
- [Ingester](https://ghcr.io/${repository}/ingester:${newTag})
17+
18+
19+
${data.body}`;
20+
21+
await github.rest.repos.createRelease({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
tag_name: newTag,
25+
name: data.name,
26+
body: dockerInfo,
27+
draft: true,
28+
prerelease: false,
29+
});
30+
};

.github/workflows/publish-image.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Build and push docker images
22

33
on:
44
workflow_call:
5+
inputs:
6+
release-tag:
7+
description: Release tag to add to images
8+
required: false
9+
type: string
10+
default: ''
511
workflow_dispatch:
612

713
permissions:
@@ -42,6 +48,7 @@ jobs:
4248
type=ref,event=branch
4349
type=sha,format=short
4450
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
51+
type=raw,value=${{ inputs.release-tag }},enable=${{ inputs.release-tag != '' }}
4552
4653
- name: Build and push Docker image
4754
uses: docker/build-push-action@v6

.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 Cairo Coder
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
description: Type of release
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
default: minor
15+
16+
permissions:
17+
contents: write
18+
packages: write
19+
20+
jobs:
21+
update-version:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
new-version: ${{ steps.version.outputs.new-version }}
25+
new-tag: ${{ steps.version.outputs.new-tag }}
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Update version and create tag
34+
id: version
35+
run: |
36+
npm version ${{ inputs.release-type }} --no-git-tag-version
37+
NEW_VERSION=$(node -p "require('./package.json').version")
38+
39+
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
40+
echo "new-tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
41+
42+
echo "NEW_VERSION=$NEW_VERSION"
43+
echo "NEW_TAG=v$NEW_VERSION"
44+
45+
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
46+
git config --local user.name "${{ github.actor }}"
47+
48+
git add package.json
49+
git commit -m "release: v$NEW_VERSION"
50+
git tag "v$NEW_VERSION"
51+
git push origin HEAD --tags
52+
53+
build-new-image:
54+
needs: update-version
55+
uses: ./.github/workflows/publish-image.yml
56+
with:
57+
release-tag: ${{ needs.update-version.outputs.new-tag }}
58+
secrets: inherit
59+
60+
create-release:
61+
needs: [update-version, build-new-image]
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout repository
65+
uses: actions/checkout@v4
66+
67+
- name: Create draft release
68+
uses: actions/github-script@v7
69+
with:
70+
script: |
71+
const script = require('./.github/scripts/create-release.js');
72+
await script({ github, context });
73+
env:
74+
NEW_TAG: ${{ needs.update-version.outputs.new-tag }}
75+
REPOSITORY: ${{ github.repository }}

.trunk/trunk.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ runtimes:
1818
lint:
1919
enabled:
2020
21-
2221
- git-diff-check
2322
2423

0 commit comments

Comments
 (0)