Skip to content

Commit c816690

Browse files
committed
ci: publish zip and crx release artifacts
1 parent c86e346 commit c816690

1 file changed

Lines changed: 73 additions & 24 deletions

File tree

.github/workflows/release.yml

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,89 @@ name: Build and Release Extension
33
on:
44
push:
55
tags:
6-
- 'v*' # 只在推送到带有 v 前缀的 tag 时触发,例如 v1.0.0
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
710

811
jobs:
912
build-and-release:
1013
runs-on: ubuntu-latest
11-
permissions:
12-
contents: write # 允许创建 release 和上传资产
1314

1415
steps:
15-
- name: Checkout Code
16+
- name: Checkout repository
1617
uses: actions/checkout@v4
1718

18-
- name: Get Version from Tag
19-
id: get_version
20-
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
19+
- name: Get version from tag
20+
run: echo "VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_ENV"
21+
22+
- name: Prepare extension directory
23+
run: |
24+
rm -rf dist release
25+
mkdir -p dist release
26+
27+
cp manifest.json dist/
28+
cp background.js dist/
29+
cp content.js dist/
30+
cp content.css dist/
31+
cp popup.html dist/
32+
cp popup.js dist/
33+
cp popup.css dist/
34+
cp page-debug-bridge.js dist/
35+
cp LICENSE dist/
36+
cp -R icons dist/icons
37+
38+
- name: Validate extension files
39+
run: |
40+
python3 -m json.tool dist/manifest.json > /dev/null
41+
node --check dist/background.js
42+
node --check dist/content.js
43+
node --check dist/popup.js
44+
node --check dist/page-debug-bridge.js
45+
46+
- name: Create ZIP package
47+
run: |
48+
cd dist
49+
zip -r "../release/BilibiliFeedHistory-${VERSION}.zip" . -x "*.DS_Store"
50+
51+
- name: Restore CRX private key
52+
env:
53+
CRX_PRIVATE_KEY_BASE64: ${{ secrets.CRX_PRIVATE_KEY_BASE64 }}
54+
run: |
55+
if [ -z "$CRX_PRIVATE_KEY_BASE64" ]; then
56+
echo "CRX_PRIVATE_KEY_BASE64 is not configured. Add it in GitHub repository Actions secrets."
57+
exit 1
58+
fi
59+
60+
echo "$CRX_PRIVATE_KEY_BASE64" | base64 --decode > release/key.pem
61+
chmod 600 release/key.pem
62+
63+
- name: Set up Chrome
64+
id: setup-chrome
65+
uses: browser-actions/setup-chrome@v1
2166

22-
- name: Package Extension (ZIP)
67+
- name: Install virtual display
2368
run: |
24-
zip -r "BilibiliFeedHistory-${{ env.VERSION }}.zip" \
25-
manifest.json \
26-
background.js \
27-
content.js \
28-
content.css \
29-
popup.html \
30-
popup.js \
31-
popup.css \
32-
icons/ \
33-
README.md \
34-
LICENSE \
35-
-x "*.DS_Store" -x ".git/*" -x ".github/*"
36-
37-
- name: Create Release and Upload Asset
69+
sudo apt-get update
70+
sudo apt-get install -y xvfb
71+
72+
- name: Create CRX package
73+
run: |
74+
xvfb-run -a "${{ steps.setup-chrome.outputs.chrome-path }}" \
75+
--no-sandbox \
76+
--disable-gpu \
77+
--disable-dev-shm-usage \
78+
--pack-extension="$PWD/dist" \
79+
--pack-extension-key="$PWD/release/key.pem"
80+
81+
mv dist.crx "release/BilibiliFeedHistory-${VERSION}.crx"
82+
rm -f release/key.pem
83+
84+
- name: Create GitHub Release and upload packages
3885
uses: softprops/action-gh-release@v2
3986
with:
4087
name: "Bilibili Feed History ${{ env.VERSION }}"
41-
generate_release_notes: true # 自动生成 release notes(基于 PR)
42-
files: "BilibiliFeedHistory-${{ env.VERSION }}.zip"
88+
generate_release_notes: true
89+
files: |
90+
release/BilibiliFeedHistory-${{ env.VERSION }}.zip
91+
release/BilibiliFeedHistory-${{ env.VERSION }}.crx

0 commit comments

Comments
 (0)