refactor: simplify release workflow

This commit is contained in:
Chang lue Tsen 2025-04-25 16:40:57 +09:00
parent 579e32abd9
commit 5cccb1f8e3
2 changed files with 32 additions and 84 deletions

View File

@ -15,7 +15,7 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 # Required for git describe --tags fetch-depth: 0
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
@ -32,10 +32,10 @@ jobs:
- name: Extract version from git tag - name: Extract version from git tag
id: version id: version
run: | run: |
# Extract version from git tag (e.g., v1.2.3)
VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//') VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')
echo "VERSION=$VERSION" echo "VERSION=$VERSION"
BUILD_NUMBER=$(echo $VERSION | tr -d '.' | sed 's/^0*//')
echo "BUILD_NUMBER=$BUILD_NUMBER"
echo "VERSION=$VERSION" >> $GITHUB_ENV echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
@ -54,7 +54,7 @@ jobs:
tags: | tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }} ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.BUILD_NUMBER }}
- name: Build and push Docker image for beta release - name: Build and push Docker image for beta release
if: contains(github.ref_name, 'beta') if: contains(github.ref_name, 'beta')
@ -67,21 +67,21 @@ jobs:
tags: | tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:beta ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:beta
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-beta ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-beta
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}-beta ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.BUILD_NUMBER }}-beta
release-notes: release-notes:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build-docker # Ensure Docker image is built first needs: build-docker
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 # Required for changelog generation fetch-depth: 0
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.21' # Match Dockerfile go-version: '1.21'
- name: Install GoReleaser - name: Install GoReleaser
run: | run: |
@ -97,49 +97,43 @@ jobs:
releases-matrix: releases-matrix:
name: Release ppanel-server binary name: Release ppanel-server binary
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: release-notes # Wait for release-notes job needs: release-notes
strategy: strategy:
matrix: matrix:
goos: [ linux, windows, darwin, freebsd ] goos: [ linux, windows, darwin ]
goarch: [ '386', amd64, arm64 ] goarch: [ '386', amd64, arm64 ]
exclude: exclude:
- goos: darwin - goos: darwin
goarch: '386' goarch: '386'
- goos: freebsd
goarch: '386' # FreeBSD 386 not in Makefile
include: include:
- goos: linux - goos: linux
goarch: arm goarch: arm
goarm: 5 goarm: 5
target: linux-armv5
- goos: linux - goos: linux
goarch: arm goarch: arm
goarm: 6 goarm: 6
target: linux-armv6
- goos: linux - goos: linux
goarch: arm goarch: arm
goarm: 7 goarm: 7
target: linux-armv7
- goos: windows - goos: windows
goarch: arm goarch: arm
goarm: 7 goarm: 7
target: windows-armv7
- goos: linux - goos: linux
goarch: mips goarch: amd64
gomips: softfloat goamd64: v3
- goos: linux target: linux-amd64-v3
goarch: mips - goos: windows
gomips: hardfloat goarch: amd64
- goos: linux goamd64: v3
goarch: mipsle target: windows-amd64-v3
gomips: softfloat - goos: darwin
- goos: linux goarch: amd64
goarch: mipsle goamd64: v3
gomips: hardfloat target: darwin-amd64-v3
- goos: linux
goarch: mips64
- goos: linux
goarch: mips64le
- goos: linux
goarch: riscv64
- goos: linux
goarch: loong64
steps: steps:
- name: Checkout repository - name: Checkout repository
@ -148,7 +142,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.21' # Match Dockerfile go-version: '1.21'
- name: Build binary with Makefile - name: Build binary with Makefile
env: env:
@ -157,8 +151,10 @@ jobs:
GOARM: ${{ matrix.goarm }} GOARM: ${{ matrix.goarm }}
GOMIPS: ${{ matrix.gomips }} GOMIPS: ${{ matrix.gomips }}
run: | run: |
make BINDIR=bin ${GOOS}-${GOARCH}${GOARM}${GOMIPS} # Use default target for non-special architectures, otherwise use matrix.target
mv bin/ppanel-server-${GOOS}-${GOARCH}${GOARM}${GOMIPS}* ppanel-server${GOOS}-${GOARCH}${GOARM}${GOMIPS} TARGET=${{ matrix.target != '' && matrix.target || format('{0}-{1}', matrix.goos, matrix.goarch) }}
make BINDIR=bin $TARGET
mv bin/ppanel-server-$TARGET* ppanel-server-$TARGET
- name: Upload release asset - name: Upload release asset
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
@ -166,8 +162,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ github.event.release.upload_url }} upload_url: ${{ github.event.release.upload_url }}
asset_path: ppanel-server${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm }}${{ matrix.gomips }} asset_path: ppanel-server-${{ matrix.target != '' && matrix.target || format('{0}-{1}', matrix.goos, matrix.goarch) }}
asset_name: ppanel-server-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm }}${{ matrix.gomips }}${{ matrix.goos == 'windows' && '.exe' || '' }} asset_name: ppanel-server-${{ matrix.target != '' && matrix.target || format('{0}-{1}', matrix.goos, matrix.goarch) }}${{ matrix.goos == 'windows' && '.exe' || '' }}
asset_content_type: application/octet-stream asset_content_type: application/octet-stream
- name: Upload additional files - name: Upload additional files

View File

@ -17,18 +17,6 @@ PLATFORM_LIST = \
linux-armv6 \ linux-armv6 \
linux-armv7 \ linux-armv7 \
linux-arm64 \ linux-arm64 \
linux-mips-softfloat \
linux-mips-hardfloat \
linux-mipsle-softfloat \
linux-mipsle-hardfloat \
linux-mips64 \
linux-mips64le \
linux-riscv64 \
linux-loong64 \
freebsd-386 \
freebsd-amd64 \
freebsd-amd64-v3 \
freebsd-arm64
WINDOWS_ARCH_LIST = \ WINDOWS_ARCH_LIST = \
windows-386 \ windows-386 \
@ -69,42 +57,6 @@ linux-armv7:
linux-arm64: linux-arm64:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mips-softfloat:
GOARCH=mips GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mips-hardfloat:
GOARCH=mips GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mipsle-softfloat:
GOARCH=mipsle GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mipsle-hardfloat:
GOARCH=mipsle GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mips64:
GOARCH=mips64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-mips64le:
GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-riscv64:
GOARCH=riscv64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-loong64:
GOARCH=loong64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
freebsd-386:
GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
freebsd-amd64:
GOARCH=amd64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
freebsd-amd64-v3:
GOARCH=amd64 GOOS=freebsd GOAMD64=v3 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
freebsd-arm64:
GOARCH=arm64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
windows-386: windows-386:
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe