Skip to content

Commit 12b37ca

Browse files
committed
ci: fix cache permissions
1 parent 8096f9e commit 12b37ca

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

.github/workflows/build-debug.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,36 @@ jobs:
2121
uses: actions/setup-go@v5
2222
with:
2323
go-version: '1.25.2'
24-
cache: true # 启用 Go 模块缓存
24+
cache: true
2525

2626
- name: Cache TinyGo
2727
id: cache-tinygo
2828
uses: actions/cache@v4
2929
with:
30-
path: |
31-
/usr/local/lib/tinygo
32-
/usr/local/bin/tinygo
30+
# 步骤 1: 将缓存路径指向用户目录
31+
path: ~/tinygo-cache
3332
key: ${{ runner.os }}-tinygo-0.39.0
3433

35-
- name: Install TinyGo if not cached
34+
- name: Restore TinyGo from cache
35+
if: steps.cache-tinygo.outputs.cache-hit == 'true'
36+
run: |
37+
# 步骤 2: 如果缓存命中,用 sudo 将文件复制到系统目录
38+
echo "Restoring TinyGo from cache..."
39+
sudo cp -r ~/tinygo-cache/tinygo /usr/local/bin/
40+
sudo cp -r ~/tinygo-cache/lib/tinygo /usr/local/lib/
41+
42+
- name: Install and prepare TinyGo for caching
3643
if: steps.cache-tinygo.outputs.cache-hit != 'true'
3744
run: |
45+
# 步骤 3: 如果缓存未命中,则安装,并复制到缓存目录以供保存
46+
echo "Installing TinyGo and preparing for cache..."
3847
wget https://github.com/tinygo-org/tinygo/releases/download/v0.39.0/tinygo_0.39.0_amd64.deb
3948
sudo dpkg -i tinygo_0.39.0_amd64.deb
4049
rm tinygo_0.39.0_amd64.deb
41-
50+
mkdir -p ~/tinygo-cache/lib
51+
cp /usr/local/bin/tinygo ~/tinygo-cache/
52+
cp -r /usr/local/lib/tinygo ~/tinygo-cache/lib/
53+
4254
- name: Get short commit hash
4355
id: vars
4456
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

.github/workflows/release.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build-and-release:
1010
runs-on: ubuntu-latest
1111
permissions:
12-
contents: write # <-- 添加此权限设置
12+
contents: write
1313
steps:
1414
- name: Check out code
1515
uses: actions/checkout@v4
@@ -18,23 +18,35 @@ jobs:
1818
uses: actions/setup-go@v5
1919
with:
2020
go-version: '1.25.2'
21-
cache: true # 启用 Go 模块缓存
21+
cache: true
2222

2323
- name: Cache TinyGo
2424
id: cache-tinygo
2525
uses: actions/cache@v4
2626
with:
27-
path: |
28-
/usr/local/lib/tinygo
29-
/usr/local/bin/tinygo
27+
# 步骤 1: 将缓存路径指向用户目录
28+
path: ~/tinygo-cache
3029
key: ${{ runner.os }}-tinygo-0.39.0
3130

32-
- name: Install TinyGo if not cached
31+
- name: Restore TinyGo from cache
32+
if: steps.cache-tinygo.outputs.cache-hit == 'true'
33+
run: |
34+
# 步骤 2: 如果缓存命中,用 sudo 将文件复制到系统目录
35+
echo "Restoring TinyGo from cache..."
36+
sudo cp -r ~/tinygo-cache/tinygo /usr/local/bin/
37+
sudo cp -r ~/tinygo-cache/lib/tinygo /usr/local/lib/
38+
39+
- name: Install and prepare TinyGo for caching
3340
if: steps.cache-tinygo.outputs.cache-hit != 'true'
3441
run: |
42+
# 步骤 3: 如果缓存未命中,则安装,并复制到缓存目录以供保存
43+
echo "Installing TinyGo and preparing for cache..."
3544
wget https://github.com/tinygo-org/tinygo/releases/download/v0.39.0/tinygo_0.39.0_amd64.deb
3645
sudo dpkg -i tinygo_0.39.0_amd64.deb
3746
rm tinygo_0.39.0_amd64.deb
47+
mkdir -p ~/tinygo-cache/lib
48+
cp /usr/local/bin/tinygo ~/tinygo-cache/
49+
cp -r /usr/local/lib/tinygo ~/tinygo-cache/lib/
3850
3951
- name: Build with -no-debug
4052
run: tinygo build -target=wasip1 -no-debug -buildmode=c-shared -scheduler asyncify -o plugin.wasm .

0 commit comments

Comments
 (0)