add github action build #5
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: Build | |
| on: | |
| workflow_dispatch: | |
| push: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| strategy: | |
| matrix: | |
| target: | |
| - windows-amd64 | |
| - windows-arm64 | |
| - windows-386 | |
| - darwin-amd64 | |
| - darwin-arm64 | |
| - linux-amd64 | |
| - linux-arm64 | |
| - linux-arm | |
| - linux-386 | |
| version: | |
| - { name: '1.26', tag: '1.26.1'} | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: golang/go | |
| ref: go${{ matrix.version.tag }} | |
| path: go | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: "go/src/go.mod" | |
| cache: false | |
| - name: Apply patch | |
| if: ${{ matrix.version.name != '1.20' }} | |
| run: | | |
| cd go | |
| patch --verbose -p 1 < $GITHUB_WORKSPACE/go${{matrix.version.name}}.patch | |
| - name: Set execute permissions | |
| run: | | |
| chmod +x go/src/make.bash | |
| - name: Build Go toolchain | |
| env: | |
| GOOS: ${{ startsWith(matrix.target, 'windows-') && 'windows' || startsWith(matrix.target, 'darwin-') && 'darwin' || 'linux' }} | |
| GOARCH: ${{ endsWith(matrix.target, '-386') && '386' || endsWith(matrix.target, '-amd64') && 'amd64' || endsWith(matrix.target, '-arm64') && 'arm64' || 'arm' }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| cd go/src | |
| ./make.bash | |
| - name: Create release directory | |
| run: | | |
| mkdir -p release | |
| cp -r go release/ | |
| cd release/go | |
| # Remove development files | |
| rm -rf .git* | |
| - name: Package | |
| run: | | |
| mkdir -p artifact | |
| cd release | |
| if [[ "${{ matrix.target }}" == windows_* ]]; then | |
| zip -r ../artifact/go${{ matrix.version.name }}.${{ matrix.target }}.zip . | |
| else | |
| tar -czf ../artifact/go${{ matrix.version.name }}.${{ matrix.target }}.tar.gz . | |
| fi | |
| - name: Update Artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: go${{ matrix.version.name }}.${{ matrix.target }} | |
| path: artifact/* | |
| archive: false | |
| merge: | |
| permissions: write-all | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download All Artifacts | |
| uses: actions/download-artifact@v8 | |
| with: | |
| path: bin | |
| pattern: go* | |
| merge-multiple: true | |
| - name: Add patch files | |
| run: | | |
| cp go*.patch bin/ | |
| - name: Upload Release | |
| uses: softprops/action-gh-release@v2 | |
| if: ${{ success() }} | |
| with: | |
| tag_name: build | |
| files: bin/* |