diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml new file mode 100644 index 0000000..091b9f9 --- /dev/null +++ b/.github/workflows/release_build.yml @@ -0,0 +1,31 @@ +name: Release Go project + +on: + push: + tags: + - "*" # triggers only if push new tag version, like `0.8.4` or else + +jobs: + build: + name: GoReleaser build + runs-on: ubuntu-latest + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + with: + fetch-depth: 0 # See: https://goreleaser.com/ci/actions/ + + - name: Set up Go 1.15 + uses: actions/setup-go@v2 + with: + go-version: 1.15 + id: go + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@master + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }} diff --git a/main.go b/main.go index e37e2ff..b67ed8b 100644 --- a/main.go +++ b/main.go @@ -211,10 +211,10 @@ func replaceTextBetweenMarkers(sourceText string, config Config) string { paddedReplaceText := fmt.Sprintf("%s%s", strings.Repeat(" ", config.Indent), reAddSpaces.ReplaceAllString(config.Block, "\n"+strings.Repeat(" ", config.Indent))) - if !config.State { - // Remove the block + switch { + case !config.State: return removeExistingBlock(sourceText, config.BeginMarker, config.EndMarker) - } else if config.InsertBefore != "" { + case config.InsertBefore != "": sourceText = removeExistingBlock(sourceText, config.BeginMarker, config.EndMarker) var index = strings.LastIndex(sourceText, config.InsertBefore) @@ -233,7 +233,7 @@ func replaceTextBetweenMarkers(sourceText string, config Config) string { paddedReplaceText, paddedEndMarker, sourceText[index:]) - } else if config.InsertAfter != "" { + case config.InsertAfter != "": sourceText = removeExistingBlock(sourceText, config.BeginMarker, config.EndMarker) var index = strings.LastIndex(sourceText, config.InsertAfter) @@ -253,7 +253,7 @@ func replaceTextBetweenMarkers(sourceText string, config Config) string { paddedReplaceText, paddedEndMarker, sourceText[index:]) - } else if strings.Contains(sourceText, config.BeginMarker) { + case strings.Contains(sourceText, config.BeginMarker): // Remove any leading spaces before replacing the block in case indentation changed beginIndex := strings.LastIndex(sourceText, config.BeginMarker) sourceText = removeLeadingSpacesOfBlock(sourceText, beginIndex) @@ -266,7 +266,7 @@ func replaceTextBetweenMarkers(sourceText string, config Config) string { paddedReplaceText, paddedEndMarker), ) - } else { + default: // Not found, add to EOF return fmt.Sprintf("%s%s\n%s\n%s\n", sourceText,