release: Test workflow build #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: "The tag version you want to build" | |
push: | |
branches: | |
- dev-next | |
jobs: | |
build: | |
name: Build binary | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- name: linux_386 | |
goos: linux | |
goarch: 386 | |
- name: linux_amd64 | |
goos: linux | |
goarch: amd64 | |
- name: linux_arm64 | |
goos: linux | |
goarch: arm64 | |
- name: linux_arm | |
goos: linux | |
goarch: arm | |
- name: linux_s390x | |
goos: linux | |
goarch: s390x | |
- name: linux_riscv64 | |
goos: linux | |
goarch: riscv64 | |
- name: linux_mips64le | |
goos: linux | |
goarch: mips64le | |
- name: windows_amd64 | |
goos: windows | |
goarch: amd64 | |
require_legacy_go: true | |
- name: windows_386 | |
goos: windows | |
goarch: 386 | |
require_legacy_go: true | |
- name: windows_arm64 | |
goos: windows | |
goarch: arm64 | |
- name: darwin_amd64 | |
goos: darwin | |
goarch: amd64 | |
require_legacy_go: true | |
- name: android_arm64 | |
goos: android | |
goarch: arm64 | |
- name: android_arm | |
goos: android | |
goarch: arm | |
- name: android_amd64 | |
goos: android | |
goarch: amd64 | |
- name: android_386 | |
goos: android | |
goarch: 386 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Cache legacy Go | |
if: matrix.require_legacy_go | |
id: cache-legacy-go | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/go/go1.20.14 | |
key: go120 | |
- name: Setup legacy Go | |
if: matrix.require_legacy_go == 'true' && steps.cache-legacy-go.outputs.cache-hit != 'true' | |
run: |- | |
wget https://dl.google.com/go/go1.20.14.linux-amd64.tar.gz | |
tar -xzf go1.20.14.linux-amd64.tar.gz | |
mv go $HOME/go/go1.20.14 | |
- name: Setup Android NDK | |
if: matrix.goos == 'android' | |
uses: nttld/setup-ndk@v1 | |
with: | |
ndk-version: r28-beta2 | |
local-cache: true | |
- name: Setup Goreleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser-pro | |
version: latest | |
install-only: true | |
- name: Extract signing key | |
run: |- | |
mkdir -p $HOME/.gnupg | |
cat > $HOME/.gnupg/sagernet.key <<EOF | |
${{ secrets.GPG_KEY }} | |
EOF | |
echo "HOME=$HOME" >> "$GITHUB_ENV" | |
- name: Set tag | |
if: github.event_name == 'workflow_dispatch' | |
run: |- | |
git tag ${{ github.event.inputs.tag }} | |
- name: Build | |
if: matrix.goos != 'android' | |
run: |- | |
goreleaser release --clean --split | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | |
NFPM_KEY_PATH: ${{ env.HOME }}/.gnupg/sagernet.key | |
NFPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Build Android | |
if: matrix.goos == 'android' | |
run: |- | |
go run -v ./cmd/internal/build goreleaser release --clean --split | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | |
NFPM_KEY_PATH: ${{ env.HOME }}/.gnupg/sagernet.key | |
NFPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: binary_${{ matrix.name }} | |
path: 'dist/*' | |
calculate_tag: | |
name: Calculate version | |
if: github.event_name != 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.build.calculate.tag }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Calculate version | |
id: calculate | |
run: |- | |
TAG=$(go run -v ./cmd/internal/read_tag --nightly) | |
echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
upload_build: | |
name: Upload builds | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- calculate_tag | |
steps: | |
- name: Checkout | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Goreleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser-pro | |
version: latest | |
install-only: true | |
- name: Cache ghr | |
uses: actions/cache@v4 | |
id: cache-ghr | |
with: | |
path: | | |
~/go/bin/ghr | |
key: ghr | |
- name: Setup ghr | |
if: steps.cache-ghr.outputs.cache-hit != 'true' | |
run: |- | |
git clone https://github.com/nekohasekai/ghr $HOME/ghr | |
cd $HOME/ghr && go install -v . | |
- name: Download builds | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
pattern: binary_* | |
merge-multiple: true | |
- name: Set tag | |
if: github.event_name == 'workflow_dispatch' | |
run: |- | |
git tag ${{ github.event.inputs.tag }} | |
echo "TAG=${{ github.event.inputs.tag }}" >> "$GITHUB_ENV" | |
- name: Calculate tag | |
if: github.event_name != 'workflow_dispatch' | |
run: |- | |
git tag ${{ needs.calculate_tag.outputs.tag }} | |
echo "TAG=${{ needs.calculate_tag.outputs.tag }}" >> "$GITHUB_ENV" | |
- name: Upload builds | |
run: |- | |
goreleaser continue --merge --skip publish | |
mkdir dist/release | |
mv dist/*.tar.gz \ | |
dist/*.zip \ | |
dist/*.deb \ | |
dist/*.rpm \ | |
dist/*_amd64.pkg.tar.zst \ | |
dist/*_arm64.pkg.tar.zst \ | |
dist/release | |
ghr --replace --draft --prerelease -p 5 "$TAG" dist/release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |