From ce101a36a18e4a6453135519c2d5784ab58060c6 Mon Sep 17 00:00:00 2001 From: Aicnal <69223323+Aicnal@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:58:47 +0800 Subject: [PATCH] Update composeImage.yml --- .github/workflows/composeImage.yml | 96 +++++++++++++++--------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/workflows/composeImage.yml b/.github/workflows/composeImage.yml index 708265b..4ae9bf2 100644 --- a/.github/workflows/composeImage.yml +++ b/.github/workflows/composeImage.yml @@ -2,59 +2,59 @@ name: Build and Release Go Binary on: push: - branches: - - 'main' + branches: + - 'main' jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + os: [linux, windows, darwin] permissions: contents: write steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' # 指定需要的 Go 版本 - - - name: Build the binary - run: | - mkdir -p bin - go build -v -o bin/composeImage ./... - - - name: Create tar.gz archive - run: | - tar -czvf bin/composeImage.tar.gz -C bin composeImage - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref_name }} # 使用推送的 tag 作为发布的 tag 名称 - release_name: Release ${{ github.ref_name }} - draft: false - prerelease: false - - - name: Upload Release asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: bin/composeImage.tar.gz - asset_name: composeImage.tar.gz - asset_content_type: application/gzip \ No newline at end of file + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 设置 Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: 设置环境变量 + run: | + echo "GOOS=${{ matrix.os }}" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + + - name: 编译程序 + run: | + mkdir -p build + go build -o build/myapp-${{ matrix.os }}-amd64 + + - name: 上传构建产物 + uses: actions/upload-artifact@v3 + with: + name: myapp-${{ matrix.os }}-amd64 + path: build/ + + release: + needs: build + runs-on: ubuntu-latest + steps: + - name: 下载构建产物 + uses: actions/download-artifact@v3 + with: + path: ./artifacts + + - name: 创建 Release 并上传资产 + uses: ncipollo/release-action@v1 + with: + artifacts: './artifacts/**' + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref }} + name: Release ${{ github.ref }} + body: 自动生成的发布 + draft: false + prerelease: false