Skip to content

Release

Release #40

Workflow file for this run

name: Release
on:
push:
tags:
- '*'
schedule:
- cron: '0 0 * * *' # 每天0点触发
workflow_dispatch:
permissions:
contents: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Goreleaser Release (Snapshot)
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --snapshot --clean # 快照发布
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete existing assets from release
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 或者使用 PAT_TOKEN
run: |
RELEASE_TAG="prerelease-nightly"
# 获取 Release ID
RELEASE_ID=$(gh api -X GET repos/${{ github.repository }}/releases --jq '.[] | select(.tag_name=="'"$RELEASE_TAG"'") | .id')
if [ -z "$RELEASE_ID" ]; then
echo "Release with tag $RELEASE_TAG does not exist. Exiting."
exit 1
fi
# 获取所有资产(artifacts)
ASSET_IDS=$(gh api -X GET repos/${{ github.repository }}/releases/$RELEASE_ID/assets --jq '.[].id')
# 删除所有资产
for ASSET_ID in $ASSET_IDS; do
echo "Deleting asset with ID $ASSET_ID"
gh api -X DELETE repos/${{ github.repository }}/releases/assets/$ASSET_ID
done
- name: Upload new assets to release
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 或者使用 PAT_TOKEN
run: |
RELEASE_TAG="prerelease-nightly"
# 上传新的构建产物
gh release upload "$RELEASE_TAG" ./dist/*.tar.gz ./dist/*_checksums.txt --clobber
- name: Goreleaser Release (Official)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') # 触发条件为 tag 的 push
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean # 正式发布
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}