125 lines
3.6 KiB
YAML
125 lines
3.6 KiB
YAML
name: Build and Publish Docker Image
|
|
|
|
on:
|
|
# release:
|
|
# types: [published]
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-docker:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
IMAGE_NAME: ppanel-server
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Extract version from pkg/constant/types.go
|
|
id: version
|
|
run: |
|
|
# 提取版本号 0.1.3
|
|
VERSION=$(grep -oP '(?<=const Version = ")[0-9]+\.[0-9]+\.[0-9]+' pkg/constant/version.go)
|
|
echo "VERSION=$VERSION"
|
|
|
|
# 提取构建号 01300
|
|
BUILD_NUMBER=$(grep -oP 'const Version = "[0-9]+\.[0-9]+\.[0-9]+\(\K[0-9]+' pkg/constant/version.go)
|
|
echo "BUILD_NUMBER=$BUILD_NUMBER"
|
|
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
|
|
|
|
- name: Get short SHA
|
|
id: sha
|
|
run: echo "GIT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
|
|
|
|
- name: Build and push Docker image for main release
|
|
if: "!contains(github.ref_name, 'beta')"
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.BUILD_NUMBER }}
|
|
|
|
- name: Build and push Docker image for beta release
|
|
if: contains(github.ref_name, 'beta')
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:beta
|
|
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.BUILD_NUMBER }}-beta
|
|
|
|
|
|
|
|
release-notes:
|
|
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: 1.23
|
|
|
|
- name: Install GoReleaser
|
|
run: |
|
|
go install github.com/goreleaser/goreleaser@latest
|
|
|
|
- name: Run GoReleaser
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
run: |
|
|
goreleaser check
|
|
goreleaser release --clean
|
|
releases-matrix:
|
|
name: Release ppanel-server binary
|
|
runs-on: ubuntu-latest
|
|
needs: release-notes # wait for release-notes job to finish
|
|
strategy:
|
|
matrix:
|
|
# build and publish in parallel: linux/386, linux/amd64, linux/arm64,
|
|
# windows/386, windows/amd64, windows/arm64, darwin/amd64, darwin/arm64
|
|
goos: [ linux, windows, darwin ]
|
|
goarch: [ '386', amd64, arm64 ]
|
|
exclude:
|
|
- goarch: '386'
|
|
goos: darwin
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: wangyoucao577/go-release-action@v1
|
|
with:
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
goos: ${{ matrix.goos }}
|
|
goarch: ${{ matrix.goarch }}
|
|
asset_name: "ppanel-server-${{ matrix.goos }}-${{ matrix.goarch }}"
|
|
goversion: "https://dl.google.com/go/go1.23.3.linux-amd64.tar.gz"
|
|
project_path: "."
|
|
binary_name: "ppanel-server"
|
|
extra_files: LICENSE etc
|
|
|