Skip to content

Commit ba8e16f

Browse files
committed
feat: enhance GitHub Actions workflow with version check for prerelease and improved environment variable handling
1 parent d43c3d8 commit ba8e16f

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ jobs:
1717
id: detect-package-manager
1818
run: |
1919
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
20-
echo "manager=yarn" >> $GITHUB_OUTPUT
21-
echo "command=install" >> $GITHUB_OUTPUT
22-
echo "runner=yarn" >> $GITHUB_OUTPUT
23-
exit 0
20+
echo "manager=yarn" >> "$GITHUB_OUTPUT"
21+
echo "command=install" >> "$GITHUB_OUTPUT"
22+
echo "runner=yarn" >> "$GITHUB_OUTPUT"
2423
elif [ -f "${{ github.workspace }}/package.json" ]; then
25-
echo "manager=npm" >> $GITHUB_OUTPUT
26-
echo "command=ci" >> $GITHUB_OUTPUT
27-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
28-
exit 0
24+
echo "manager=npm" >> "$GITHUB_OUTPUT"
25+
echo "command=ci" >> "$GITHUB_OUTPUT"
26+
echo "runner=npx --no-install" >> "$GITHUB_OUTPUT"
2927
else
3028
echo "Unable to determine package manager"
3129
exit 1
@@ -41,13 +39,28 @@ jobs:
4139
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
4240

4341
- name: Build with Next.js
44-
run: ${{ steps.detect-package-manager.outputs.runner }} build
42+
env:
43+
API_SECRET_KEY: ${{ secrets.API_SECRET_KEY }}
44+
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
45+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
4546

4647
- name: Get version from package.json
4748
id: get_version
4849
run: |
4950
VERSION=$(jq -r '.version' package.json)
50-
echo "VERSION=$VERSION" >> $GITHUB_ENV
51+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
52+
53+
- name: Check version for prerelease
54+
id: check_version
55+
run: |
56+
# 從 $VERSION 取出 major 版號
57+
major=$(echo "$VERSION" | cut -d'.' -f1)
58+
echo "Detected major version: $major"
59+
if [ "$major" -lt 1 ]; then
60+
echo "prerelease=true" >> "$GITHUB_OUTPUT"
61+
else
62+
echo "prerelease=false" >> "$GITHUB_OUTPUT"
63+
fi
5164
5265
- name: Prepare production package
5366
run: |
@@ -61,22 +74,21 @@ jobs:
6174
[ -f example.env ] && cp example.env production/ || true
6275
6376
- name: Compress production package
64-
run: |
65-
tar --exclude='./node_modules' --exclude='./.git' -czf production.tar.gz production
77+
run: tar --exclude='./node_modules' --exclude='./.git' -czf production.tar.gz production
6678

6779
- name: Create Release
6880
id: create_release
69-
uses: actions/create-release@v1
81+
uses: actions/create-release@v1.1.0
7082
env:
7183
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7284
with:
7385
tag_name: v${{ env.VERSION }}
74-
release_name: Release v${{ env.VERSION }}
86+
release_name: v${{ env.VERSION }}
7587
draft: false
76-
prerelease: false
88+
prerelease: ${{ steps.check_version.outputs.prerelease }}
7789

7890
- name: Upload Release Asset
79-
uses: actions/upload-release-asset@v1
91+
uses: actions/upload-release-asset@v1.1.0
8092
env:
8193
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8294
with:

0 commit comments

Comments
 (0)