name: Release # 推送 v* 标签时构建并发布;手动触发时只构建、上传 artifact,不发布 on: push: tags: ['v*'] workflow_dispatch: permissions: contents: write packages: write jobs: binaries: name: Server & agent binaries 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 runs-on: macos-15 steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: go.mod - name: Build universal app run: | VERSION=${GITHUB_REF_NAME#v} case "$VERSION" in [0-9]*) ;; *) VERSION=0.0.0-${GITHUB_SHA::7} ;; esac UNIVERSAL=1 VERSION=$VERSION ./build-app.sh mkdir -p dist ditto -c -k --sequesterRsrc --keepParent PortRelay.app "dist/PortRelay-$VERSION-macos-universal.zip" - uses: actions/upload-artifact@v4 with: name: macos-app path: dist/*.zip 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/download-artifact@v4 with: path: dist merge-multiple: true - name: Checksums run: cd dist && sha256sum * > SHA256SUMS - name: Create release env: GH_TOKEN: ${{ github.token }} run: gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --title "$GITHUB_REF_NAME" --generate-notes