Merge pull request #1 from myxo/master #1
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: CI | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Run tests | |
| run: go test ./... | |
| - name: Cross-compile binaries | |
| run: | | |
| set -euo pipefail | |
| mkdir -p dist | |
| for GOOS in linux darwin windows; do | |
| for GOARCH in amd64 arm64; do | |
| ext="" | |
| if [ "$GOOS" = "windows" ]; then | |
| ext=".exe" | |
| fi | |
| bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}" | |
| GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" . | |
| done | |
| done | |
| release: | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Build release binaries | |
| run: | | |
| set -euo pipefail | |
| mkdir -p dist | |
| for GOOS in linux darwin windows; do | |
| for GOARCH in amd64 arm64; do | |
| ext="" | |
| if [ "$GOOS" = "windows" ]; then | |
| ext=".exe" | |
| fi | |
| bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}" | |
| GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" . | |
| done | |
| done | |
| - name: Create or fetch release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| gh release view "$TAG_NAME" >/dev/null 2>&1 || gh release create "$TAG_NAME" --title "$TAG_NAME" --notes "" | |
| - name: Upload release assets | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| gh release upload "$TAG_NAME" dist/* --clobber |