Files

118 lines
3.8 KiB
YAML

name: Release
# 推送 v* 标签时构建并发布;手动触发时只构建、上传 artifact,不发布
on:
push:
tags: ['v*']
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
binaries:
name: Server & agent archives
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build
run: make release VERSION=${GITHUB_REF_NAME#v}
- uses: actions/upload-artifact@v4
with:
name: binaries
path: |
dist/*.tar.gz
dist/*.zip
macos-app:
name: macOS app (dmg)
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build universal dmg
run: |
VERSION=${GITHUB_REF_NAME#v}
case "$VERSION" in [0-9]*) ;; *) VERSION=0.0.0-${GITHUB_SHA::7} ;; esac
UNIVERSAL=1 make dmg VERSION=$VERSION
- uses: actions/upload-artifact@v4
with:
name: macos-app
path: dist/*.dmg
docker:
name: Docker image
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Image name (lowercase)
run: echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/portrelay-server" >> "$GITHUB_ENV"
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: VERSION=${{ steps.meta.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
publish:
name: GitHub release
needs: [binaries, macos-app]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
# 只取安装包;docker 任务还会上传构建记录,不能一并下载
- uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- uses: actions/download-artifact@v4
with:
name: macos-app
path: dist
- name: Checksums
run: cd dist && sha256sum * > SHA256SUMS
# 说明 = 标签注释正文(本次更新)+ 下载说明(区分客户端与服务端)+ 自动生成的变更列表
- name: Release notes
run: |
git fetch --force origin "refs/tags/$GITHUB_REF_NAME:refs/tags/$GITHUB_REF_NAME"
body=$(git tag -l --format='%(contents:body)' "$GITHUB_REF_NAME")
{
if [ -n "$body" ]; then printf "## 本次更新 · What's new\n\n%s\n\n" "$body"; fi
sed -e "s|{{VERSION}}|${GITHUB_REF_NAME#v}|g" \
-e "s|{{DOWNLOAD}}|https://github.com/$GITHUB_REPOSITORY/releases/download/$GITHUB_REF_NAME|g" \
-e "s|{{IMAGE}}|ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/portrelay-server|g" \
.github/release-notes.md
} > "$RUNNER_TEMP/notes.md"
cat "$RUNNER_TEMP/notes.md"
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --title "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" --generate-notes