Skip to content

Commit 50eae58

Browse files
committed
Refactor release workflow and add GitHub Release step
Splits the release workflow into separate jobs for push and release events, adds a step to create a GitHub Release with generated notes, and improves version extraction logic. Ensures Docker images are built and pushed for both push and release triggers, and updates job names and conditions for clarity.
1 parent 5299fff commit 50eae58

File tree

1 file changed

+94
-26
lines changed

1 file changed

+94
-26
lines changed

.github/workflows/release.yml

Lines changed: 94 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,17 @@ on:
88
paths:
99
- Directory.Packages.props
1010

11+
permissions:
12+
contents: write
13+
1114
jobs:
12-
release-build:
15+
push-release-build:
16+
if: github.event_name == 'push'
1317
runs-on: ubuntu-latest
1418
steps:
1519
- name: Checkout
1620
uses: actions/checkout@v4
1721

18-
- name: Set up Node.js
19-
uses: actions/setup-node@v4
20-
with:
21-
node-version: '20'
22-
23-
- name: Install frontend dependencies
24-
working-directory: web-site
25-
run: npm i
26-
27-
- name: Build frontend (outputs to backend wwwroot)
28-
working-directory: web-site
29-
run: npm run build
30-
31-
- name: Set up Docker Buildx
32-
uses: docker/setup-buildx-action@v3
33-
34-
- name: Login to Docker Registry
35-
uses: docker/login-action@v3
36-
with:
37-
registry: crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com
38-
username: ${{ secrets.DOCKER_USERNAME }}
39-
password: ${{ secrets.DOCKER_PASSWORD }}
40-
4122
- name: Extract version from Directory.Packages.props
4223
id: get_version
4324
shell: pwsh
@@ -53,7 +34,6 @@ jobs:
5334
$props[$n.Name] = [string]$n.InnerText
5435
}
5536
}
56-
# Provide concrete TimeStamp (UTC yyyyMMdd) in case used in Version
5737
$props['TimeStamp'] = (Get-Date -AsUTC).ToString('yyyyMMdd')
5838
$unresolved = New-Object System.Collections.Generic.List[string]
5939
$finalVersion = [regex]::Replace($versionTemplate, '\$\(([A-Za-z0-9_.-]+)\)', {
@@ -67,7 +47,42 @@ jobs:
6747
Write-Host "Version template: $versionTemplate"
6848
Write-Host "Final version: $finalVersion"
6949
70-
- name: Build and push koala-wiki
50+
- name: Create GitHub Release v${{ steps.get_version.outputs.version }}
51+
uses: softprops/action-gh-release@v2
52+
with:
53+
tag_name: v${{ steps.get_version.outputs.version }}
54+
name: v${{ steps.get_version.outputs.version }}
55+
generate_release_notes: true
56+
draft: false
57+
prerelease: false
58+
make_latest: true
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Set up Node.js
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: '20'
66+
67+
- name: Install frontend dependencies
68+
working-directory: web-site
69+
run: npm i
70+
71+
- name: Build frontend (outputs to backend wwwroot)
72+
working-directory: web-site
73+
run: npm run build
74+
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v3
77+
78+
- name: Login to Docker Registry
79+
uses: docker/login-action@v3
80+
with:
81+
registry: crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com
82+
username: ${{ secrets.DOCKER_USERNAME }}
83+
password: ${{ secrets.DOCKER_PASSWORD }}
84+
85+
- name: Build and push koala-wiki (v${{ steps.get_version.outputs.version }})
7186
uses: docker/build-push-action@v5
7287
with:
7388
context: .
@@ -78,3 +93,56 @@ jobs:
7893
crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com/koala-ai/koala-wiki:latest
7994
crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com/koala-ai/koala-wiki:${{ steps.get_version.outputs.version }}
8095
96+
release-build:
97+
if: github.event_name == 'release' && github.actor != 'github-actions[bot]'
98+
runs-on: ubuntu-latest
99+
steps:
100+
- name: Checkout tag
101+
uses: actions/checkout@v4
102+
with:
103+
ref: ${{ github.event.release.tag_name }}
104+
105+
- name: Set up Node.js
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: '20'
109+
110+
- name: Install frontend dependencies
111+
working-directory: web-site
112+
run: npm i
113+
114+
- name: Build frontend (outputs to backend wwwroot)
115+
working-directory: web-site
116+
run: npm run build
117+
118+
- name: Set up Docker Buildx
119+
uses: docker/setup-buildx-action@v3
120+
121+
- name: Login to Docker Registry
122+
uses: docker/login-action@v3
123+
with:
124+
registry: crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com
125+
username: ${{ secrets.DOCKER_USERNAME }}
126+
password: ${{ secrets.DOCKER_PASSWORD }}
127+
128+
- name: Extract version from release tag
129+
id: get_version
130+
shell: pwsh
131+
run: |
132+
$tag = '${{ github.event.release.tag_name }}'
133+
if ([string]::IsNullOrWhiteSpace($tag)) { throw 'Release tag name is empty' }
134+
$ver = if ($tag.StartsWith('v')) { $tag.Substring(1) } else { $tag }
135+
"version=$ver" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
136+
Write-Host "Release tag: $tag"
137+
Write-Host "Version: $ver"
138+
139+
- name: Build and push koala-wiki
140+
uses: docker/build-push-action@v5
141+
with:
142+
context: .
143+
file: src/KoalaWiki/Dockerfile
144+
platforms: linux/amd64
145+
push: true
146+
tags: |
147+
crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com/koala-ai/koala-wiki:latest
148+
crpi-j9ha7sxwhatgtvj4.cn-shenzhen.personal.cr.aliyuncs.com/koala-ai/koala-wiki:${{ steps.get_version.outputs.version }}

0 commit comments

Comments
 (0)