|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + strategy: |
| 11 | + matrix: |
| 12 | + include: |
| 13 | + - goos: linux |
| 14 | + goarch: amd64 |
| 15 | + runner: ubuntu-latest |
| 16 | + - goos: linux |
| 17 | + goarch: arm64 |
| 18 | + runner: ubuntu-24.04-arm |
| 19 | + - goos: darwin |
| 20 | + goarch: amd64 |
| 21 | + runner: macos-13 |
| 22 | + - goos: darwin |
| 23 | + goarch: arm64 |
| 24 | + runner: macos-latest |
| 25 | + |
| 26 | + runs-on: ${{ matrix.runner }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Set up Go |
| 35 | + uses: actions/setup-go@v5 |
| 36 | + with: |
| 37 | + go-version: '1.24' # Adjust to your Go version |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: go mod download |
| 41 | + |
| 42 | + |
| 43 | + - name: Install CGO dependencies for Linux |
| 44 | + if: matrix.goos == 'linux' |
| 45 | + run: | |
| 46 | + sudo apt-get update |
| 47 | + sudo apt-get install -y pkg-config |
| 48 | + sudo apt update && \ |
| 49 | + sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config libssl-dev libssh2-1-dev zlib1g-dev libhttp-parser-dev python3 wget tar git && \ |
| 50 | + wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \ |
| 51 | + tar -xzf libgit2-v1.5.1.tar.gz && \ |
| 52 | + cd libgit2-1.5.1 && \ |
| 53 | + mkdir build && \ |
| 54 | + cd build && \ |
| 55 | + cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \ |
| 56 | + make -j$(nproc) && \ |
| 57 | + sudo make install && \ |
| 58 | + sudo ldconfig |
| 59 | +
|
| 60 | + - name: Install CGO dependencies for macOS |
| 61 | + if: matrix.goos == 'darwin' |
| 62 | + run: | |
| 63 | + brew install cmake wget zlib libiconv && \ |
| 64 | + wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \ |
| 65 | + tar -xzf libgit2-v1.5.1.tar.gz && \ |
| 66 | + cd libgit2-1.5.1 && \ |
| 67 | + mkdir build && \ |
| 68 | + cd build && \ |
| 69 | + cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \ |
| 70 | + make -j$(nproc) && \ |
| 71 | + sudo make install |
| 72 | +
|
| 73 | + - name: Build binary for linux |
| 74 | + if: matrix.goos == 'linux' |
| 75 | + env: |
| 76 | + CGO_ENABLED: 1 |
| 77 | + GOOS: ${{ matrix.goos }} |
| 78 | + GOARCH: ${{ matrix.goarch }} |
| 79 | + run: | |
| 80 | + go build \ |
| 81 | + -tags "static system_libgit2" \ |
| 82 | + -ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \ |
| 83 | + -X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \ |
| 84 | + -X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ |
| 85 | + -extldflags '-static'" \ |
| 86 | + -o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \ |
| 87 | + main.go |
| 88 | +
|
| 89 | + # - name: Setup tmate session |
| 90 | + # uses: mxschmitt/action-tmate@v3 |
| 91 | + # with: |
| 92 | + # limit-access-to-actor: false |
| 93 | + |
| 94 | + - name: Build binary for macOS |
| 95 | + if: matrix.goos == 'darwin' |
| 96 | + env: |
| 97 | + CGO_ENABLED: 1 |
| 98 | + GOOS: ${{ matrix.goos }} |
| 99 | + GOARCH: ${{ matrix.goarch }} |
| 100 | + CGO_LDFLAGS: "-lgit2 -lz -liconv -Wl,-rpath,/Users/runner/work/modctl/modctl/libgit2-1.5.1/build" |
| 101 | + run: | |
| 102 | + go build \ |
| 103 | + -tags "static system_libgit2" \ |
| 104 | + -ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \ |
| 105 | + -X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \ |
| 106 | + -X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ |
| 107 | + -o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \ |
| 108 | + main.go |
| 109 | +
|
| 110 | + - name: Create archive |
| 111 | + run: | |
| 112 | + mkdir -p dist |
| 113 | + tar -czf dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \ |
| 114 | + LICENSE README.md build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} |
| 115 | +
|
| 116 | + - name: Build deb/rpm packages |
| 117 | + if: matrix.goos == 'linux' |
| 118 | + run: | |
| 119 | + echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list |
| 120 | + sudo apt update |
| 121 | + sudo apt install nfpm |
| 122 | + export VERSION=${{ github.ref_name }} |
| 123 | + nfpm pkg \ |
| 124 | + --config hack/nfpm.yaml \ |
| 125 | + --target dist/ |
| 126 | +
|
| 127 | + - name: Generate checksums |
| 128 | + run: | |
| 129 | + cd dist |
| 130 | + shasum -a 256 *.tar.gz *.deb *.rpm > checksums.txt |
| 131 | + continue-on-error: true # In case no deb/rpm files exist for macOS |
| 132 | + |
| 133 | + - name: Upload artifacts |
| 134 | + uses: actions/upload-artifact@v4 |
| 135 | + with: |
| 136 | + name: modctl-${{ matrix.goos }}-${{ matrix.goarch }} |
| 137 | + path: dist/ |
| 138 | + |
| 139 | + create-release: |
| 140 | + needs: release |
| 141 | + runs-on: ubuntu-latest |
| 142 | + steps: |
| 143 | + - name: Download all artifacts |
| 144 | + uses: actions/download-artifact@v4 |
| 145 | + with: |
| 146 | + path: artifacts |
| 147 | + |
| 148 | + - name: Create draft release |
| 149 | + uses: softprops/action-gh-release@v2 |
| 150 | + with: |
| 151 | + draft: true |
| 152 | + files: | |
| 153 | + artifacts/**/modctl-*.tar.gz |
| 154 | + artifacts/**/modctl-*.deb |
| 155 | + artifacts/**/modctl-*.rpm |
| 156 | + artifacts/**/checksums.txt |
| 157 | + generate_release_notes: true |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} |
0 commit comments