Go Build and Release #173
Workflow file for this run
This file contains hidden or 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: Go Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # 触发条件:推送 tag | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: 'Tag name for the release' | |
| required: true | |
| default: 'v2.5.9-Beta.7' | |
| permissions: | |
| contents: write | |
| # - [👏] | |
| # - [🔧] | |
| # - [☠️] | |
| env: | |
| PROJECT_NAME: ${{ github.event.repository.name }} | |
| BUILD_DATE: ${{ github.run_id }} | |
| VERSION: ${{ github.ref_name }} | |
| RELEASE_DIR: release | |
| RELEASE_NOTICES: | | |
| - [🔧] 修复英华填空题和简答题报错问题 | |
| - [🔧] 优化学习通部分账号做题报错问题 | |
| 注:智慧职教刚上线,可能并不稳定,若有bug可发送issue或者加群反馈。(智慧职教仅支持Windows系统) | |
| jobs: | |
| build: | |
| name: Build (${{ matrix.os }}-${{ matrix.arch }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| arch: amd64 | |
| goos: linux | |
| - os: windows-latest | |
| arch: amd64 | |
| goos: windows | |
| - os: macos-latest | |
| arch: amd64 | |
| goos: darwin | |
| - os: macos-latest | |
| arch: arm64 | |
| goos: darwin | |
| # 如果需要 armv7 (32位) 交叉编译,加下面一行 | |
| # - os: ubuntu-latest | |
| # arch: arm | |
| # goos: linux | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install dependencies (Linux) | |
| if: runner.os == 'Linux' && matrix.arch=='amd64' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libasound2-dev pkg-config gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf | |
| - name: Install dependencies (Linux) | |
| if: runner.os == 'Linux' && matrix.arch=='arm64' | |
| run: | | |
| sudo dpkg --add-architecture arm64 | |
| sudo apt-get update | |
| sudo apt-get install -y libc6:arm64 libc6-dev:arm64 | |
| sudo apt-get install -y libasound2-dev:arm64 pkg-config gcc-aarch64-linux-gnu g++-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(Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| export GOPROXY=direct | |
| export GONOSUMDB=* | |
| rm -rf go.sum | |
| go clean -modcache | |
| go env -w GOSUMDB=off | |
| go mod tidy | |
| - name: Get dependencies(MacOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| export GOPROXY=direct | |
| export GONOSUMDB=* | |
| rm -rf go.sum | |
| go clean -modcache | |
| go env -w GOSUMDB=off | |
| go mod tidy | |
| - name: Get dependencies(Windows) | |
| if: runner.os=='Windows' | |
| 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}}-linux-${{matrix.arch}}-release | |
| # Build Linux | |
| - name: Build Linux | |
| if: runner.os=='Linux' && matrix.arch=='amd64' | |
| run: | | |
| CGO_ENABLED=1 GOOS=linux GOARCH=${{matrix.arch}} go build \ | |
| -o ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release/${{ env.PROJECT_NAME }} | |
| # Build Linux | |
| - name: Build Linux | |
| if: runner.os=='Linux' && matrix.arch=='arm64' | |
| run: | | |
| CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=${{matrix.arch}} go build \ | |
| -o ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release/${{ env.PROJECT_NAME }} | |
| # Build Windows | |
| - name: Build Windows | |
| if: runner.os == 'Windows' | |
| run: | | |
| set CGO_ENABLED=1 | |
| set GOOS=windows | |
| set GOARCH=${{matrix.arch}} | |
| go build -o ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release\${{ env.PROJECT_NAME }}.exe | |
| # 🧱 构建 Macos | |
| - name: Build macOS | |
| if: matrix.goos == 'darwin' | |
| run: | | |
| CGO_ENABLED=1 GOOS=darwin GOARCH=${{ matrix.arch }} go build \ | |
| -o ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-${{ matrix.goos }}-${{ matrix.arch }}-release/${{ env.PROJECT_NAME }} | |
| - name: Create release tar | |
| if: runner.os=='Linux' | |
| run: | # 打包发布版本压缩包 | |
| cp command/config.yaml ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release | |
| cd ${{ env.RELEASE_DIR }} | |
| tar -czvf yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release.tar.gz yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release | |
| rm -rf yatori-go-console.${{env.VERSION}}-linux-${{matrix.arch}}-release | |
| cd .. | |
| - name: Create Release zip | |
| if: runner.os=='Windows' | |
| run: | | |
| copy command\config.yaml ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release | |
| copy command\start.bat ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release | |
| cd ${{ env.RELEASE_DIR }} | |
| Compress-Archive -Path "yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release" -DestinationPath "yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release.zip" | |
| Remove-Item -Recurse -Force "yatori-go-console.${{env.VERSION}}-windows-${{matrix.arch}}-release" | |
| cd .. | |
| # 📦 打包 macOS (amd64+arm64) | |
| - name: Create macOS Release tar | |
| if: matrix.goos == 'darwin' | |
| run: | | |
| cp command/config.yaml ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-${{ matrix.goos }}-${{ matrix.arch }}-release | |
| cd ${{ env.RELEASE_DIR }} | |
| tar -czvf yatori-go-console.${{env.VERSION}}-${{ matrix.goos }}-${{ matrix.arch }}-release.tar.gz yatori-go-console.${{env.VERSION}}-${{ matrix.goos }}-${{ matrix.arch }}-release | |
| rm -rf yatori-go-console.${{env.VERSION}}-${{ matrix.goos }}-${{ matrix.arch }}-release | |
| cd .. | |
| - name: Upload Release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| files: ${{ env.RELEASE_DIR }}/* # 文件发布目录 | |
| tag_name: ${{ env.VERSION }} | |
| body: ${{ env.RELEASE_NOTICES }} | |
| draft: false | |
| prerelease: false |