Skip to content

Update relese.yml

Update relese.yml #14

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*.*.*' # 触发条件:推送的标签匹配版本号模式,例如 v1.0.0
workflow_dispatch:
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false
build:
needs: create-release
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, darwin, windows ]
goarch: [ amd64, arm64 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21.4' # 替换为你的Go版本
- name: Build the project
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o anki-card-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/anki-card/main.go
- name: Archive the build output
run: |
zip anki-card-${{ matrix.goos }}-${{ matrix.goarch }}.zip anki-card-${{ matrix.goos }}-${{ matrix.goarch }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./anki-card-${{ matrix.goos }}-${{ matrix.goarch }}.zip
asset_name: anki-card-${{ matrix.goos }}-${{ matrix.goarch }}.zip
asset_content_type: application/zip
docker:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: git pull
- uses: docker/login-action@v3.2.0
name: Docker Login
with:
# Server address of Docker registry. If not set then will default to Docker Hub
# registry: ${{ vars.REGISTRY }}
# Username used to log against the Docker registry
username: ${{ secrets.DOCKER_HUB_ACCOUNT }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.DOCKER_HUB_PWD }}
- name: Build and push the Docker image
run: |
tag=${GITHUB_REF#refs/tags/}
docker build -t ${{ vars.SPACE_HUB_NAME }}/anki-card:${tag} .
docker push ${{ vars.SPACE_HUB_NAME }}/anki-card:${tag}
- name: Tag Docker image as latest
if: startsWith(github.ref, 'refs/tags/')
run: |
tag=${GITHUB_REF#refs/tags/}
docker tag ${{ vars.SPACE_HUB_NAME }}/anki-card:${tag} ${{ vars.SPACE_HUB_NAME }}/anki-card:latest
docker push ${{ vars.SPACE_HUB_NAME }}/anki-card:latest