mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2025-12-06 14:59:18 +08:00
215 lines
7.8 KiB
YAML
215 lines
7.8 KiB
YAML
name: goreleaser
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
permissions:
|
|
contents: write
|
|
env:
|
|
REGISTRY: docker.io
|
|
jobs:
|
|
goreleaser:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: '1.21.4'
|
|
- name: Install dependencies for cross-compilation
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential clang llvm
|
|
|
|
# Install osxcross for macOS cross-compilation
|
|
git clone https://github.com/tpoechtrager/osxcross /tmp/osxcross
|
|
cd /tmp/osxcross
|
|
|
|
# Download macOS SDK
|
|
wget -O tarballs/MacOSX15.5.sdk.tar.xz https://github.com/joseluisq/macosx-sdks/releases/download/15.5/MacOSX15.5.sdk.tar.xz
|
|
|
|
# Build osxcross
|
|
OSX_VERSION_MIN=10.15 ./build.sh
|
|
- name: Run GoReleaser
|
|
uses: goreleaser/goreleaser-action@v4
|
|
with:
|
|
# either 'goreleaser' (default) or 'goreleaser-pro'
|
|
distribution: goreleaser
|
|
version: '2.1.0'
|
|
args: release --clean
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
CGO_ENABLED: 1
|
|
PATH: /tmp/osxcross/target/bin:${{ env.PATH }}
|
|
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
|
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
|
- name: List Folder
|
|
run: |
|
|
ls
|
|
cd dist
|
|
ls
|
|
- name: Get current tag
|
|
run: echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
|
- name: Check if the tag contains "beta"
|
|
id: check_beta
|
|
run: |
|
|
echo "Is the tag beta? ${GITHUB_REF}"
|
|
if [[ "${GITHUB_REF}" == *"beta"* ]]; then
|
|
echo "is_beta=true" >> $GITHUB_ENV
|
|
else
|
|
echo "is_beta=false" >> $GITHUB_ENV
|
|
fi
|
|
# Login to Docker Hub
|
|
- name: Login to Docker Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.DOCKER_HUB_USER }}
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
# Check if should build Docker (only for 'all' tags or non-platform-specific tags)
|
|
- name: Check if should build Docker
|
|
id: check_docker
|
|
run: |
|
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
echo "Checking tag: $TAG_NAME"
|
|
|
|
# Check if tag contains platform-specific keywords (but not 'all')
|
|
if echo "$TAG_NAME" | grep -qE "(linux|windows|win|macos|darwin|debug|arm64)" && ! echo "$TAG_NAME" | grep -q "all"; then
|
|
echo "Platform-specific tag detected, skipping Docker build"
|
|
echo "skip_docker=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Building Docker for all platforms or 'all' tag"
|
|
echo "skip_docker=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
# Set up Docker Buildx
|
|
- name: Set up Docker Buildx
|
|
if: steps.check_docker.outputs.skip_docker != 'true'
|
|
uses: docker/setup-buildx-action@v2
|
|
# Build and Push Docker Image for Multi-Arch
|
|
- name: Build and Push Docker Image for Multi-Arch
|
|
if: steps.check_docker.outputs.skip_docker != 'true'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64 # Support for both architectures
|
|
push: true # Push to Docker Hub
|
|
tags: |
|
|
samwaf/samwaf:${{ env.IMAGE_TAG }}
|
|
samwaf/samwaf:beta
|
|
${{ env.is_beta == 'false' && 'samwaf/samwaf:latest' || '' }}
|
|
# Test the Docker Image (latest)
|
|
- name: Test Docker Image (latest)
|
|
if: steps.check_docker.outputs.skip_docker != 'true'
|
|
run: |
|
|
echo "Testing Docker image with 'latest' tag..."
|
|
docker run -d --name=samwaf-latest-instance \
|
|
-p 26666:26666 \
|
|
samwaf/samwaf:latest
|
|
|
|
# 等待服务启动
|
|
sleep 5
|
|
|
|
# 测试服务是否正常运行
|
|
curl -f http://localhost:26666 || (echo "Test for 'latest' tag failed" && exit 1)
|
|
|
|
# 停止并移除容器
|
|
docker stop samwaf-latest-instance
|
|
docker rm samwaf-latest-instance
|
|
- name: Test Docker Image (current tag)
|
|
if: steps.check_docker.outputs.skip_docker != 'true'
|
|
run: |
|
|
echo "Testing Docker image with tag '${{ env.IMAGE_TAG }}'..."
|
|
docker run -d --name=samwaf-current-instance \
|
|
-p 26666:26666 \
|
|
samwaf/samwaf:${{ env.IMAGE_TAG }}
|
|
|
|
# 等待服务启动
|
|
sleep 5
|
|
|
|
# 测试服务是否正常运行
|
|
curl -f http://localhost:26666 || (echo "Test for current tag '${{ env.IMAGE_TAG }}' failed" && exit 1)
|
|
|
|
# 停止并移除容器
|
|
docker stop samwaf-current-instance
|
|
docker rm samwaf-current-instance
|
|
win7win2008r2:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.24'
|
|
|
|
- name: Install dependencies for Windows cross-compilation
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 build-essential
|
|
|
|
- name: Install UPX
|
|
run: |
|
|
sudo apt-get install -y upx
|
|
|
|
- name: DownLoad New SamWafWeb
|
|
run: |
|
|
curl -L https://github.com/samwafgo/SamWafWeb/releases/latest/download/dist.tar.gz -o dist.tar.gz
|
|
tar -zxvf dist.tar.gz
|
|
rm -rf public/dist
|
|
mv -f dist public
|
|
rm -rf dist.tar.gz
|
|
ls
|
|
ls public
|
|
ls public/dist
|
|
|
|
- name: Revert Golang1.24 commit for Windows7/8
|
|
run: |
|
|
cd $(go env GOROOT)
|
|
patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/win7patch/patch_go124/2a406dc9f1ea7323d6ca9fccb2fe9ddebb6b1cc8.diff
|
|
patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/win7patch/patch_go124/7b1fd7d39c6be0185fbe1d929578ab372ac5c632.diff
|
|
patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/win7patch/patch_go124/979d6d8bab3823ff572ace26767fd2ce3cf351ae.diff
|
|
patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/win7patch/patch_go124/ac3e93c061779dfefc0dd13a5b6e6f764a25621e.diff
|
|
|
|
- name: Get current tag
|
|
id: get_tag
|
|
run: echo "CURRENT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
|
- name: Set BUILDTIME environment variable
|
|
run: echo "BUILDTIME=$(date +'%Y%m%d')" >> $GITHUB_ENV
|
|
|
|
- name: Build Win7/Win8/Windows2008r2
|
|
env:
|
|
GOOS: windows
|
|
GOARCH: amd64
|
|
CGO_ENABLED: 1
|
|
CC: x86_64-w64-mingw32-gcc
|
|
CXX: x86_64-w64-mingw32-g++
|
|
CGO_CFLAGS: -Wno-unused-variable -Wno-implicit-function-declaration
|
|
BUILDTIME: ${{ env.BUILDTIME }}
|
|
CURRENT_TAG: ${{ env.CURRENT_TAG }}
|
|
run: |
|
|
go build -ldflags="-X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=true -X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=${BUILDTIME} -X SamWaf/global.GWAF_RELEASE_VERSION=${CURRENT_TAG} -s -w -extldflags '-static'" -o ./release/SamWaf64ForWin7Win8Win2008.exe main.go
|
|
|
|
- name: Archive artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: SamWaf64ForWin7Win8Win2008
|
|
path: release/SamWaf64ForWin7Win8Win2008.exe
|
|
- name: Release
|
|
uses: softprops/action-gh-release@v2
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
with:
|
|
files: |
|
|
release/SamWaf64ForWin7Win8Win2008.exe
|
|
needs: goreleaser
|