diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1b2a7f2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Run tests + run: go test -v -race ./... + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 8a75912..be9d7e1 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ go.work.sum releaseo + +# GoReleaser +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..c41adf8 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,62 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj +version: 2 + +project_name: releaseo + +before: + hooks: + - go mod tidy + +builds: + - id: releaseo + binary: releaseo + main: . + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} + +archives: + - id: releaseo + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- .Os }}_ + {{- .Arch }} + files: + - LICENSE + - README.md + +checksum: + name_template: 'checksums.txt' + algorithm: sha256 + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^ci:' + - '^chore:' + - Merge pull request + - Merge branch + +release: + github: + owner: stacklok + name: releaseo + draft: false + prerelease: auto + name_template: "{{.Tag}}" diff --git a/action.yml b/action.yml index 0317fcf..ca33f47 100644 --- a/action.yml +++ b/action.yml @@ -54,6 +54,50 @@ outputs: runs: using: 'composite' steps: + - name: Download releaseo binary + id: download + shell: bash + run: | + VERSION="${{ github.action_ref }}" + + # Validate version is specified and is a tag (not a branch) + if [ -z "$VERSION" ]; then + echo "::error::No version specified. Please reference this action with a version tag (e.g., @v1.0.0)" + exit 1 + fi + + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then + echo "::error::Invalid version '$VERSION'. Please use a semantic version tag (e.g., @v1.0.0). Using @main or @branch-name is not supported." + exit 1 + fi + + # Determine OS and architecture + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + case "$ARCH" in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + *) echo "::error::Unsupported architecture: $ARCH"; exit 1 ;; + esac + + # Download the binary + ASSET_NAME="releaseo_${VERSION#v}_${OS}_${ARCH}.tar.gz" + ASSET_URL="https://github.com/stacklok/releaseo/releases/download/${VERSION}/${ASSET_NAME}" + + echo "Downloading releaseo ${VERSION} for ${OS}/${ARCH}..." + echo "URL: ${ASSET_URL}" + + if ! curl -sSL --fail -o releaseo.tar.gz "$ASSET_URL"; then + echo "::error::Failed to download releaseo ${VERSION}. Make sure the release exists at: https://github.com/stacklok/releaseo/releases/tag/${VERSION}" + exit 1 + fi + + tar xzf releaseo.tar.gz + chmod +x releaseo + rm releaseo.tar.gz + + echo "Successfully downloaded releaseo ${VERSION}" + - name: Run releaseo id: releaseo shell: bash @@ -76,4 +120,4 @@ runs: ARGS+=(--version-files="$VERSION_FILES_JSON") fi - go run github.com/stacklok/releaseo@v1.0.11 "${ARGS[@]}" + ./releaseo "${ARGS[@]}"