Skip to content

Commit

Permalink
Update composeImage.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Aicnal authored Nov 5, 2024
1 parent 28cd2b2 commit ce101a3
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions .github/workflows/composeImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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

0 comments on commit ce101a3

Please sign in to comment.