diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 46c2618..ae21af6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,12 +2,10 @@ name: Release on: - push: - tags: - - "v*" + pull_request: branches: - main - pull_request: + push: branches: - main @@ -15,7 +13,9 @@ permissions: contents: write jobs: - goreleaser: + # Test and build snapshot for PRs + test-build: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -26,21 +26,62 @@ jobs: with: go-version: "1.25" - - name: Set version + - name: Run tests + run: go test -v ./... + + - name: Set version from VERSION file id: version run: | - if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then - echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT + VERSION=$(cat VERSION) + echo "version=v${VERSION}" >> $GITHUB_OUTPUT + + - uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: v1.26.2 + args: build --snapshot --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.version }} + + # Create tag and release when PR is merged to main + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v4 + with: + go-version: "1.25" + + - name: Read version and create tag + id: version + run: | + VERSION=$(cat VERSION) + TAG="v${VERSION}" + echo "version=${TAG}" >> $GITHUB_OUTPUT + + # Check if tag already exists + if git rev-parse "${TAG}" >/dev/null 2>&1; then + echo "Tag ${TAG} already exists, skipping release" + echo "skip=true" >> $GITHUB_OUTPUT else - VERSION=$(cat VERSION) - echo "version=v${VERSION}" >> $GITHUB_OUTPUT + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "${TAG}" -m "Release ${TAG}" + git push origin "${TAG}" + echo "skip=false" >> $GITHUB_OUTPUT fi - uses: goreleaser/goreleaser-action@v5 + if: steps.version.outputs.skip != 'true' with: distribution: goreleaser version: v1.26.2 - args: ${{ startsWith(github.ref, 'refs/tags/') && 'release' || 'build --snapshot' }} --clean + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.version }} diff --git a/README.md b/README.md index 2da9f60..cb17123 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ These Go-template tags are indented: - Control blocks: `range`, `with`, `define`, `block` - Branching: `if`, `else`, `else if`, `end` - Vars: `{{ $var := ... }}` -- Some functions: `include`, `fail`, `printf` etc. +- Some functions: `fail`, `printf` etc. - Comments: `{{/* ... */}}` These are not indented by default but can be [configured](https://github.com/digitalstudium/helmfmt?tab=readme-ov-file#configuration): -- `tpl`, `template` and `toYaml` because they can break YAML indentation +- `tpl`, `template`, `include` and `toYaml` because they can break YAML indentation --- @@ -108,8 +108,7 @@ Download it from [releases](https://github.com/digitalstudium/helmfmt/releases) helmfmt helmfmt --files ... helmfmt --files ... --stdout -helmfmt --disable-indent=template,include -helmfmt --enable-indent=toYaml --files ... +helmfmt --enable-indent=toYaml,include --files ... ``` Example run: @@ -154,14 +153,14 @@ Processed: 2, Updated: 1, Errors: 0 "exclude": [] }, "template": { - "disabled": false, - "exclude": [] - }, - "printf": { - "disabled": false, + "disabled": true, "exclude": [] }, "include": { + "disabled": true, + "exclude": [] + }, + "printf": { "disabled": false, "exclude": [] }, @@ -207,6 +206,7 @@ Each rule can be configured with: "rules": { "indent": { "include": { + "disabled": false, "exclude": ["tests/*", "**/test-*.yaml"] } } @@ -227,9 +227,6 @@ Each rule can be configured with: You can override configuration rules using command-line flags: ```bash -# Disable specific rules -helmfmt --disable-indent=template,include - # Enable specific rules (overrides config file) helmfmt --enable-indent=tpl,toYaml ``` @@ -243,7 +240,7 @@ To use `helmfmt` as a pre-commit hook, add the following to your `.pre-commit-co ```yaml repos: - repo: https://github.com/digitalstudium/helmfmt - rev: v0.3.0 + rev: v0.4.0 hooks: - id: helmfmt ``` diff --git a/VERSION b/VERSION index 0d91a54..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 diff --git a/main.go b/main.go index e1d64fe..a4fbf33 100644 --- a/main.go +++ b/main.go @@ -39,9 +39,9 @@ func loadConfig() *Config { Indent: map[string]RuleConfig{ "tpl": {Disabled: true, Exclude: []string{}}, "toYaml": {Disabled: true, Exclude: []string{}}, - "template": {Disabled: false, Exclude: []string{}}, + "template": {Disabled: true, Exclude: []string{}}, + "include": {Disabled: true, Exclude: []string{}}, "printf": {Disabled: false, Exclude: []string{}}, - "include": {Disabled: false, Exclude: []string{}}, "fail": {Disabled: false, Exclude: []string{}}, }, },