diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 4a87121..5aca72f 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -1,4 +1,4 @@ -name: Auto Tag +name: Auto Tag and Release on: push: @@ -9,14 +9,17 @@ permissions: contents: write jobs: - auto-tag: + auto-tag-and-release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Calculate and create tag + - name: Calculate version + id: version + env: + GITHUB_TOKEN: ${{ github.token }} run: | # Get latest tag or default to v0.0.0 LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") @@ -34,22 +37,55 @@ jobs: fi # Determine bump type + SHOULD_RELEASE="false" if echo "$COMMITS" | grep -qE '^(feat|\\[feat\\])'; then MINOR=$((MINOR + 1)) PATCH=0 echo "Found feat → minor bump" + SHOULD_RELEASE="true" elif echo "$COMMITS" | grep -qE '^(fix|\\[fix\\])'; then PATCH=$((PATCH + 1)) echo "Found fix → patch bump" + SHOULD_RELEASE="true" else echo "No feat/fix commits. Skipping release." - exit 0 fi - # Create and push tag + # Set output NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" - echo "Creating tag: $NEW_TAG" + echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT + echo "should_release=$SHOULD_RELEASE" >> $GITHUB_OUTPUT + echo "Calculated version: $NEW_TAG" + + # Check if tag already exists + if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then + echo "Tag $NEW_TAG already exists. Skipping." + echo "should_release=false" >> $GITHUB_OUTPUT + fi + + - name: Set up Go + if: steps.version.outputs.should_release == 'true' + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Create tag and release + if: steps.version.outputs.should_release == 'true' + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + NEW_TAG="${{ steps.version.outputs.new_tag }}" + git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git tag -a "$NEW_TAG" -m "Release $NEW_TAG" - git push origin "$NEW_TAG" + + - name: Run GoReleaser + if: steps.version.outputs.should_release == 'true' + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..3974c87 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,42 @@ +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/README.md b/README.md index f2d0835..202b244 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ # coba-bump Just update the feature -update readme -again \ No newline at end of file +update \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cbf2347 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/yusufmalikul/coba-bump + +go 1.25 diff --git a/main.go b/main.go new file mode 100644 index 0000000..a3dd973 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, World!") +}