Skip to content

Commit 9600279

Browse files
authored
chore: Add Github actions to build
1 parent 2fcfb5f commit 9600279

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main # main 分支触发
7+
- master # master 分支触发
8+
workflow_dispatch: # 手动触发
9+
10+
jobs:
11+
build-and-release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout source
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # 检查已有tag
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
24+
- name: Install dependencies
25+
run: npm install
26+
27+
- name: Build project
28+
run: npm run build
29+
30+
- name: Get version & extension name from extension.json
31+
id: meta
32+
run: |
33+
echo "VERSION=$(jq -r .version extension.json)" >> $GITHUB_ENV
34+
echo "EEXTNAME=$(jq -r .name extension.json)" >> $GITHUB_ENV
35+
36+
- name: Check and create tag
37+
id: check_tag
38+
run: |
39+
VERSION=${{ env.VERSION }}
40+
TAG="v${VERSION}"
41+
42+
echo "🔎 检查 tag $TAG 是否存在..."
43+
if git rev-parse "$TAG" >/dev/null 2>&1; then
44+
echo "⚠️ Tag $TAG 已存在,跳过发布。"
45+
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
46+
else
47+
echo "✅ Tag $TAG 不存在,创建并推送。"
48+
git config user.name "github-actions[bot]"
49+
git config user.email "github-actions[bot]@users.noreply.github.com"
50+
git tag -a "$TAG" -m "Release $TAG"
51+
git push origin "$TAG"
52+
echo "SKIP_RELEASE=false" >> $GITHUB_ENV
53+
fi
54+
55+
- name: Extract changelog for version
56+
if: env.SKIP_RELEASE == 'false'
57+
id: changelog
58+
run: |
59+
VERSION=${{ env.VERSION }}
60+
EEXTNAME=${{ env.EEXTNAME }}
61+
echo "🔎 Extracting changelog for version $VERSION from CHANGELOG.md"
62+
NOTES=$(awk "/^# ${VERSION}/ {flag=1; next} /^#/ {if(flag) exit} flag" CHANGELOG.md)
63+
if [ -z "$NOTES" ]; then
64+
NOTES=$(awk "/^# ${VERSION}/ {flag=1; next} flag" CHANGELOG.md)
65+
fi
66+
NOTES="$NOTES\n\n---\n由GitHub Actions自动构建并发布\nBuilt and released automatically by GitHub Actions\n\n也可前往[嘉立创EDA扩展广场](https://extensions.oshwhub.com/item/oshwhub/${EEXTNAME})下载\nAlso available at [JLCEDA Extension Plaza](https://extensions.oshwhub.com/item/oshwhub/${EEXTNAME})"
67+
68+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
69+
echo -e "$NOTES" >> $GITHUB_ENV
70+
echo "EOF" >> $GITHUB_ENV
71+
echo "------ Release Notes ------"
72+
echo -e "$NOTES"
73+
echo "---------------------------"
74+
75+
- name: Debug check artifact
76+
if: env.SKIP_RELEASE == 'false'
77+
run: |
78+
VERSION=${{ env.VERSION }}
79+
EEXTNAME=${{ env.EEXTNAME }}
80+
FILE="build/dist/${EEXTNAME}_v${VERSION}.eext"
81+
if [ -f "$FILE" ]; then
82+
echo "✅ 产物存在: $FILE"
83+
else
84+
echo "❌ 未发现产物: $FILE"
85+
ls -R build || true
86+
exit 1
87+
fi
88+
89+
- name: Upload Release
90+
if: env.SKIP_RELEASE == 'false'
91+
uses: softprops/action-gh-release@v2
92+
with:
93+
tag_name: v${{ env.VERSION }}
94+
name: Release v${{ env.VERSION }}
95+
body: ${{ env.RELEASE_NOTES }}
96+
files: build/dist/${{ env.EEXTNAME }}_v${{ env.VERSION }}.eext
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)