Skip to content

Go Build and Release #67

Go Build and Release

Go Build and Release #67

Workflow file for this run

name: Go Build and Release
on:
push:
tags:
- 'v*' # Trigger on version tags (e.g., v1.2.3)
# branches:
# - main # Trigger on push to main branch as well
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release'
required: true
default: 'v2.0.0-beta.3' # Default tag name
permissions:
contents: write # Allow writing to GitHub releases
env:
PROJECT_NAME: ${{ github.event.repository.name }}
BUILD_DATE: ${{ github.run_id }}
VERSION: ${{ github.ref_name }} # Dynamic version based on the tag name
RELEASE_DIR: release
RELEASE_NOTICES: |
- [👏] 更新支持学习公社
- [👏] 项目规范化迁移
- [👏] 支持IP代理池文件接入(挂服务器减少封号风险,挂服务器的请务必使用ip代理池,因为服务器公网IP是固定的,很容易会被侦测到)
- [‍🔧] 修复部分BUG,提高稳定性
注:等GO版本追平Java版本功能后Java版本将不再进行维护,后续将主要针对GO版本进行维护,Java将不会更新新功能和适配新平台。
jobs:
# Linux build job
build-linux:
name: Build Linux
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full git history for versioning
# Install necessary dependencies
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev pkg-config gcc-aarch64-linux-gnu
# Set up Go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod' # Use Go version from go.mod
cache: true # Enable dependency caching
- name: Get dependencies
run: |
export GOPROXY=direct
export GONOSUMDB=*
go mod tidy
- name: Prepare Release Directory #创建压缩目录
run: mkdir -p ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release
# Build Linux AMD64
- name: Build Linux AMD64
run: |
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
-o ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release/${{ env.PROJECT_NAME }}
- name: Create release tar
run: | # 打包发布版本压缩包
cp command/config.yaml ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release
cd ${{ env.RELEASE_DIR }}
tar -czvf yatori-go-console.${{env.VERSION}}-linux-amd64-release.tar.gz yatori-go-console.${{env.VERSION}}-linux-amd64-release
rm -rf yatori-go-console.${{env.VERSION}}-linux-amd64-release
cd ..
# Create GitHub Release
- name: Create GitHub Release with custom notes
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: ${{ env.RELEASE_DIR }}/* # 文件发布目录
# generate_release_notes: true # 自动发行说明
draft: false # 不创建草稿发布
prerelease: false # 不标记为预发布
tag_name: ${{ env.VERSION }} # 从标签中使用动态版本
body: ${{env.RELEASE_NOTICES}} # 使用读取到的发布说明内容
# Windows build job
build-windows:
name: Build Windows
runs-on: windows-latest
needs: build-linux # Ensure Linux build completes first
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full git history for versioning
# Set up Go for Windows
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod' # Use Go version from go.mod
cache: true # Enable dependency caching
- name: Get dependencies
run: |
set GOPROXY=direct
set GONOSUMDB=*
go clean -modcache
del go.sum
go get -u ./...
go mod tidy
- name: Prepare Release Directory
run: mkdir -p ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release
# Build Windows AMD64
- name: Build Windows AMD64
run: |
set CGO_ENABLED=1
set GOOS=windows
set GOARCH=amd64
go build -o ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release\${{ env.PROJECT_NAME }}.exe
# tar -czvf yatori-go-console.${{env.VERSION}}-windows-amd64-release.tar.gz yatori-go-console.${{env.VERSION}}-windows-amd64-release 这个是windows打包tar.gz包的
- name: Create Release zip
run: |
copy command\config.yaml ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release
copy command\start.bat ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release
cd ${{ env.RELEASE_DIR }}
Compress-Archive -Path "yatori-go-console.${{env.VERSION}}-windows-amd64-release" -DestinationPath "yatori-go-console.${{env.VERSION}}-windows-amd64-release.zip"
Remove-Item -Recurse -Force "yatori-go-console.${{env.VERSION}}-windows-amd64-release"
cd ..
# Create GitHub Release
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: ${{ env.RELEASE_DIR }}/* # 文件发布目录
generate_release_notes: true # 自动发行说明
draft: false # 不创建草稿发布
prerelease: false # 不标记为预发布
tag_name: ${{ env.VERSION }} # 从标签中使用动态版本
# # Create release on GitHub
# release:
# name: Create Release
# runs-on: ubuntu-latest
# needs: [build-linux, build-windows]
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
#
# - name: Prepare Release Directory
# run: mkdir -p ${{ env.RELEASE_DIR }}
#
# # List files to verify the release directory contains binaries
# - name: List files in release directory
# run: |
# ls -l ${{ env.RELEASE_DIR }}
#
# # Create Source Code Tarball
# - name: Create Source Code Tarball
# run: |
# tar -czvf ${{ env.RELEASE_DIR }}/${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_source.tar.gz \
# --exclude=.git \
# --exclude=${{ env.RELEASE_DIR }} \
# .
#
# # Create Source Code Zip
# - name: Create Source Code Zip
# run: |
# zip -r ${{ env.RELEASE_DIR }}/${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_source.zip \
# . \
# -x .git\* \
# -x release\*
#
# # Generate SHA256 Checksums
# - name: Generate SHA256 Checksums
# run: |
# cd ${{ env.RELEASE_DIR }}
# sha256sum * > ${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_checksums.txt
#
# # Create GitHub Release
# - name: Create Release
# uses: softprops/action-gh-release@v2
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# files: ${{ env.RELEASE_DIR }}/* # 文件发布目录
# generate_release_notes: true # 自动发行说明
# draft: false # 不创建草稿发布
# prerelease: false # 不标记为预发布
# tag_name: ${{ env.VERSION }} # 从标签中使用动态版本