|
| 1 | +name: Go Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Trigger on version tags (e.g., v1.2.3) |
| 7 | +# branches: |
| 8 | +# - main # Trigger on push to main branch as well |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + tag_name: |
| 12 | + description: 'Tag name for the release' |
| 13 | + required: true |
| 14 | + default: 'v1.2.3' # Default tag name |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write # Allow writing to GitHub releases |
| 18 | + |
| 19 | +env: |
| 20 | + PROJECT_NAME: ${{ github.event.repository.name }} |
| 21 | + BUILD_DATE: ${{ github.run_id }} |
| 22 | + VERSION: ${{ github.ref_name }} # Dynamic version based on the tag name |
| 23 | + RELEASE_DIR: release |
| 24 | + RELEASE_NOTICES: | |
| 25 | + - [👏] 更新支持学习公社 |
| 26 | + - [👏] 项目规范化迁移 |
| 27 | + - [👏] 支持IP代理池文件接入(挂服务器减少封号风险,挂服务器的请务必使用ip代理池,因为服务器公网IP是固定的,很容易会被侦测到) |
| 28 | + - [🔧] 修复部分BUG,提高稳定性 |
| 29 | + |
| 30 | + 注:等GO版本追平Java版本功能后Java版本将不再进行维护,后续将主要针对GO版本进行维护,Java将不会更新新功能和适配新平台。 |
| 31 | +jobs: |
| 32 | + # Linux build job |
| 33 | + build-linux: |
| 34 | + name: Build Linux |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 # Fetch full git history for versioning |
| 41 | + |
| 42 | + # Install necessary dependencies |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y libasound2-dev pkg-config gcc-aarch64-linux-gnu |
| 47 | +
|
| 48 | + # Set up Go |
| 49 | + - name: Set up Go |
| 50 | + uses: actions/setup-go@v5 |
| 51 | + with: |
| 52 | + go-version-file: 'go.mod' # Use Go version from go.mod |
| 53 | + cache: true # Enable dependency caching |
| 54 | + |
| 55 | + - name: Get dependencies |
| 56 | + run: | |
| 57 | + export GOPROXY=direct |
| 58 | + export GONOSUMDB=* |
| 59 | + go mod tidy |
| 60 | +
|
| 61 | + - name: Prepare Release Directory #创建压缩目录 |
| 62 | + run: mkdir -p ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release |
| 63 | + |
| 64 | + # Build Linux AMD64 |
| 65 | + - name: Build Linux AMD64 |
| 66 | + run: | |
| 67 | + CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \ |
| 68 | + -o ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release/${{ env.PROJECT_NAME }} |
| 69 | + - name: Create release tar |
| 70 | + run: | # 打包发布版本压缩包 |
| 71 | + cp command/config.yaml ${{ env.RELEASE_DIR }}/yatori-go-console.${{env.VERSION}}-linux-amd64-release |
| 72 | + cd ${{ env.RELEASE_DIR }} |
| 73 | + tar -czvf yatori-go-console.${{env.VERSION}}-linux-amd64-release.tar.gz yatori-go-console.${{env.VERSION}}-linux-amd64-release |
| 74 | + rm -rf yatori-go-console.${{env.VERSION}}-linux-amd64-release |
| 75 | + cd .. |
| 76 | + # Create GitHub Release |
| 77 | + - name: Create GitHub Release with custom notes |
| 78 | + uses: softprops/action-gh-release@v2 |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + with: |
| 82 | + files: ${{ env.RELEASE_DIR }}/* # 文件发布目录 |
| 83 | + # generate_release_notes: true # 自动发行说明 |
| 84 | + draft: false # 不创建草稿发布 |
| 85 | + prerelease: false # 不标记为预发布 |
| 86 | + tag_name: ${{ env.VERSION }} # 从标签中使用动态版本 |
| 87 | + body: ${{env.RELEASE_NOTICES}} # 使用读取到的发布说明内容 |
| 88 | + |
| 89 | + # Windows build job |
| 90 | + build-windows: |
| 91 | + name: Build Windows |
| 92 | + runs-on: windows-latest |
| 93 | + needs: build-linux # Ensure Linux build completes first |
| 94 | + steps: |
| 95 | + - name: Checkout code |
| 96 | + uses: actions/checkout@v4 |
| 97 | + with: |
| 98 | + fetch-depth: 0 # Fetch full git history for versioning |
| 99 | + |
| 100 | + # Set up Go for Windows |
| 101 | + - name: Set up Go |
| 102 | + uses: actions/setup-go@v5 |
| 103 | + with: |
| 104 | + go-version-file: 'go.mod' # Use Go version from go.mod |
| 105 | + cache: true # Enable dependency caching |
| 106 | + |
| 107 | + - name: Get dependencies |
| 108 | + run: | |
| 109 | + set GOPROXY=direct |
| 110 | + set GONOSUMDB=* |
| 111 | + go clean -modcache |
| 112 | + del go.sum |
| 113 | + go get -u ./... |
| 114 | + go mod tidy |
| 115 | +
|
| 116 | + - name: Prepare Release Directory |
| 117 | + run: mkdir -p ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release |
| 118 | + |
| 119 | + # Build Windows AMD64 |
| 120 | + - name: Build Windows AMD64 |
| 121 | + run: | |
| 122 | + set CGO_ENABLED=1 |
| 123 | + set GOOS=windows |
| 124 | + set GOARCH=amd64 |
| 125 | + go build -o ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release\${{ env.PROJECT_NAME }}.exe |
| 126 | + # tar -czvf yatori-go-console.${{env.VERSION}}-windows-amd64-release.tar.gz yatori-go-console.${{env.VERSION}}-windows-amd64-release 这个是windows打包tar.gz包的 |
| 127 | + - name: Create Release zip |
| 128 | + run: | |
| 129 | + copy command\config.yaml ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release |
| 130 | + copy command\start.bat ${{ env.RELEASE_DIR }}\yatori-go-console.${{env.VERSION}}-windows-amd64-release |
| 131 | + cd ${{ env.RELEASE_DIR }} |
| 132 | + Compress-Archive -Path "yatori-go-console.${{env.VERSION}}-windows-amd64-release" -DestinationPath "yatori-go-console.${{env.VERSION}}-windows-amd64-release.zip" |
| 133 | + Remove-Item -Recurse -Force "yatori-go-console.${{env.VERSION}}-windows-amd64-release" |
| 134 | + cd .. |
| 135 | + # Create GitHub Release |
| 136 | + - name: Create Release |
| 137 | + uses: softprops/action-gh-release@v2 |
| 138 | + env: |
| 139 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + with: |
| 141 | + files: ${{ env.RELEASE_DIR }}/* # 文件发布目录 |
| 142 | + generate_release_notes: true # 自动发行说明 |
| 143 | + draft: false # 不创建草稿发布 |
| 144 | + prerelease: false # 不标记为预发布 |
| 145 | + tag_name: ${{ env.VERSION }} # 从标签中使用动态版本 |
| 146 | +# # Create release on GitHub |
| 147 | +# release: |
| 148 | +# name: Create Release |
| 149 | +# runs-on: ubuntu-latest |
| 150 | +# needs: [build-linux, build-windows] |
| 151 | +# steps: |
| 152 | +# - name: Checkout code |
| 153 | +# uses: actions/checkout@v4 |
| 154 | +# with: |
| 155 | +# fetch-depth: 0 |
| 156 | +# |
| 157 | +# - name: Prepare Release Directory |
| 158 | +# run: mkdir -p ${{ env.RELEASE_DIR }} |
| 159 | +# |
| 160 | +# # List files to verify the release directory contains binaries |
| 161 | +# - name: List files in release directory |
| 162 | +# run: | |
| 163 | +# ls -l ${{ env.RELEASE_DIR }} |
| 164 | +# |
| 165 | +# # Create Source Code Tarball |
| 166 | +# - name: Create Source Code Tarball |
| 167 | +# run: | |
| 168 | +# tar -czvf ${{ env.RELEASE_DIR }}/${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_source.tar.gz \ |
| 169 | +# --exclude=.git \ |
| 170 | +# --exclude=${{ env.RELEASE_DIR }} \ |
| 171 | +# . |
| 172 | +# |
| 173 | +# # Create Source Code Zip |
| 174 | +# - name: Create Source Code Zip |
| 175 | +# run: | |
| 176 | +# zip -r ${{ env.RELEASE_DIR }}/${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_source.zip \ |
| 177 | +# . \ |
| 178 | +# -x .git\* \ |
| 179 | +# -x release\* |
| 180 | +# |
| 181 | +# # Generate SHA256 Checksums |
| 182 | +# - name: Generate SHA256 Checksums |
| 183 | +# run: | |
| 184 | +# cd ${{ env.RELEASE_DIR }} |
| 185 | +# sha256sum * > ${{ env.PROJECT_NAME }}_${{ env.BUILD_DATE }}_checksums.txt |
| 186 | +# |
| 187 | +# # Create GitHub Release |
| 188 | +# - name: Create Release |
| 189 | +# uses: softprops/action-gh-release@v2 |
| 190 | +# env: |
| 191 | +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 192 | +# with: |
| 193 | +# files: ${{ env.RELEASE_DIR }}/* # 文件发布目录 |
| 194 | +# generate_release_notes: true # 自动发行说明 |
| 195 | +# draft: false # 不创建草稿发布 |
| 196 | +# prerelease: false # 不标记为预发布 |
| 197 | +# tag_name: ${{ env.VERSION }} # 从标签中使用动态版本 |
0 commit comments