|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + name: Test |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set up Go |
| 25 | + uses: actions/setup-go@v5 |
| 26 | + with: |
| 27 | + go-version: '1.23' |
| 28 | + |
| 29 | + - name: Download dependencies |
| 30 | + run: go mod download |
| 31 | + |
| 32 | + - name: Run tests |
| 33 | + run: go test -v ./... |
| 34 | + |
| 35 | + - name: Build |
| 36 | + run: go build -v ./cmd/clockwork |
| 37 | + |
| 38 | + release: |
| 39 | + name: Release |
| 40 | + needs: test |
| 41 | + if: startsWith(github.ref, 'refs/tags/v') |
| 42 | + runs-on: ubuntu-latest |
| 43 | + strategy: |
| 44 | + matrix: |
| 45 | + goos: [linux, darwin, windows] |
| 46 | + goarch: [amd64, arm64] |
| 47 | + exclude: |
| 48 | + - goos: windows |
| 49 | + goarch: arm64 |
| 50 | + steps: |
| 51 | + - name: Checkout code |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Set up Go |
| 57 | + uses: actions/setup-go@v5 |
| 58 | + with: |
| 59 | + go-version: '1.23' |
| 60 | + |
| 61 | + - name: Get version |
| 62 | + id: version |
| 63 | + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 64 | + |
| 65 | + - name: Build binary |
| 66 | + env: |
| 67 | + GOOS: ${{ matrix.goos }} |
| 68 | + GOARCH: ${{ matrix.goarch }} |
| 69 | + run: | |
| 70 | + BINARY_NAME="clockwork-${{ steps.version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}" |
| 71 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 72 | + BINARY_NAME="${BINARY_NAME}.exe" |
| 73 | + fi |
| 74 | + go build -ldflags="-s -w" -o "${BINARY_NAME}" ./cmd/clockwork |
| 75 | +
|
| 76 | + - name: Create checksum |
| 77 | + run: | |
| 78 | + BINARY_NAME="clockwork-${{ steps.version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}" |
| 79 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 80 | + BINARY_NAME="${BINARY_NAME}.exe" |
| 81 | + fi |
| 82 | + sha256sum "${BINARY_NAME}" > "${BINARY_NAME}.sha256" |
| 83 | +
|
| 84 | + - name: Upload to release |
| 85 | + uses: softprops/action-gh-release@v2 |
| 86 | + with: |
| 87 | + files: | |
| 88 | + clockwork-${{ steps.version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}* |
| 89 | + draft: false |
| 90 | + prerelease: false |
| 91 | + generate_release_notes: true |
| 92 | + env: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments