diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index acce943..7e574ff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,6 +5,7 @@ on: branches: [main] pull_request: branches: [main] + workflow_call: jobs: ci: diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..8de84f4 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,92 @@ +name: Publish + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + validate-tag: + runs-on: ubuntu-latest + steps: + - name: Validate semver format + run: | + TAG="${GITHUB_REF#refs/tags/}" + VERSION="${TAG#v}" + if ! npx semver "$VERSION" > /dev/null 2>&1; then + echo "Error: Tag '$TAG' is not a valid semver format" + echo "Expected format: vMAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]" + exit 1 + fi + echo "Tag '$TAG' is valid semver" + + ci: + uses: ./.github/workflows/ci.yaml + + build: + needs: [validate-tag, ci] + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: darwin + goarch: amd64 + - goos: darwin + goarch: arm64 + - goos: linux + goarch: amd64 + - goos: linux + goarch: arm64 + - goos: windows + goarch: amd64 + - goos: windows + goarch: arm64 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.6" + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + BINARY_NAME="goanywhere-${{ matrix.goos }}-${{ matrix.goarch }}" + if [ "${{ matrix.goos }}" = "windows" ]; then + BINARY_NAME="${BINARY_NAME}.exe" + fi + go build -ldflags="-s -w" -o "${BINARY_NAME}" ./cmd/goanywhere + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: goanywhere-${{ matrix.goos }}-${{ matrix.goarch }} + path: goanywhere-${{ matrix.goos }}-${{ matrix.goarch }}* + + release: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + files: artifacts/*