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