first #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ifile_package | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: write # 允许创建 release | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- goos: linux | |
goarch: amd64 | |
os: ubuntu-latest | |
- goos: darwin | |
goarch: arm64 | |
os: macos-latest | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 设置 Node.js 环境 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '22' | |
- name: 安装 pnpm | |
run: npm install -g pnpm | |
- name: 安装 web 依赖 | |
working-directory: ./ifile_frontend | |
run: pnpm install | |
- name: 构建前端项目 | |
working-directory: ./ifile_frontend | |
run: pnpm run build | |
- name: 安装 Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.23' | |
- name: 编译 Go 项目 | |
working-directory: ./ | |
shell: bash | |
run: | | |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then | |
go build -o ifile_aarch64 . | |
else | |
go build -o ifile_amd64 . | |
export CGO_ENABLED=0 | |
export GOARCH=amd64 | |
export GOOS=windows | |
go build -o ifile.exe . | |
fi | |
- name: 打包为 zip | |
working-directory: ./ | |
shell: bash | |
run: | | |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then | |
zip -r ifile_macos.zip ifile_aarch64 static | |
else | |
zip -r ifile_linux.zip ifile_amd64 static | |
zip -r ifile_windows.zip ifile.exe static | |
fi | |
- name: 设置压缩文件名称 | |
shell: bash | |
working-directory: ./ | |
run: | | |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then | |
echo "ARTIFACT_NAME=ifile_macos" >> $GITHUB_ENV | |
else | |
echo "ARTIFACT_NAME=ifile_linux_windows" >> $GITHUB_ENV | |
fi | |
- name: 上传打包产物 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: "ifile*.zip" | |
release: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: 下载 Windows、Linux 产物 | |
uses: actions/download-artifact@v4 | |
with: | |
name: ifile_linux_windows | |
path: ./release | |
- name: 下载 macOS 产物 | |
uses: actions/download-artifact@v4 | |
with: | |
name: ifile_macos | |
path: ./release | |
- name: 设置短 SHA | |
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: 设置动态版本号 | |
run: echo "RELEASE_TAG=v0.${{ github.run_number }}" >> $GITHUB_ENV | |
- name: 创建 Release 并上传 zip | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: "v0-${{ github.run_number }}-${{ env.SHORT_SHA }}" | |
name: "Release v0-${{ github.run_number }}-${{ env.SHORT_SHA }}" | |
files: | | |
./release/ifile_windows.zip | |
./release/ifile_macos.zip | |
./release/ifile_linux.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |