-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (85 loc) · 3.26 KB
/
release.yml
File metadata and controls
98 lines (85 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Build and Release
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> "$GITHUB_OUTPUT"
echo "command=install" >> "$GITHUB_OUTPUT"
echo "runner=yarn" >> "$GITHUB_OUTPUT"
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> "$GITHUB_OUTPUT"
echo "command=ci" >> "$GITHUB_OUTPUT"
echo "runner=npx --no-install" >> "$GITHUB_OUTPUT"
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
env:
API_SECRET_KEY: ${{ secrets.API_SECRET_KEY }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r '.version' package.json)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Check version for prerelease
id: check_version
run: |
# 從 $VERSION 取出 major 版號
major=$(echo "$VERSION" | cut -d'.' -f1)
echo "Detected major version: $major"
if [ "$major" -lt 1 ]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Prepare production package
run: |
mkdir production
cp -R .next production/
cp package.json production/
[ -f yarn.lock ] && cp yarn.lock production/ || true
[ -f package-lock.json ] && cp package-lock.json production/ || true
[ -f next.config.js ] && cp next.config.js production/ || true
[ -d public ] && cp -R public production/ || true
[ -f example.env ] && cp example.env production/ || true
- name: Compress production package
run: tar --exclude='./node_modules' --exclude='./.git' -czf production.tar.gz production
- name: Create Release
id: create_release
uses: actions/create-release@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: v${{ env.VERSION }}
draft: false
prerelease: ${{ steps.check_version.outputs.prerelease }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: production.tar.gz
asset_name: production.tar.gz
asset_content_type: application/gzip