Skip to content

Commit

Permalink
Merge pull request #26 from elisasre/feature/gotidy
Browse files Browse the repository at this point in the history
Feature/gotidy
  • Loading branch information
kraashen authored Oct 14, 2023
2 parents 01f296a + 91d8333 commit 0ba5de6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# all-encompassing default settings unless otherwise specified
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[*.{json}]
indent_size = 2

[*.{yml,yaml}]
indent_size = 2

[{go.mod,go.sum,*.go}]
indent_style = tab
indent_size = 4
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ jobs:
working-directory: ./godemo
env:
GOLANGCI_LINT_FLAGS: --out-format=github-actions
# backwards compatibility check
- run: mage ensure
working-directory: ./godemo
# backwards compatibility check
- run: mage ensureInSync
working-directory: ./godemo
- run: mage tidy
working-directory: ./godemo
- run: mage tidyAndVerifyNoChanges
working-directory: ./godemo
- run: mage vulncheck
continue-on-error: true
working-directory: ./godemo
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ jobs:
working-directory: ./godemo
env:
GOLANGCI_LINT_FLAGS: --out-format=github-actions
# backwards compatibility check
- run: mage ensure
working-directory: ./godemo
# backwards compatibility check
- run: mage ensureInSync
working-directory: ./godemo
- run: mage tidy
working-directory: ./godemo
- run: mage tidyAndVerifyNoChanges
working-directory: ./godemo
- run: mage vulncheck
continue-on-error: true
working-directory: ./godemo
Expand Down Expand Up @@ -104,8 +110,7 @@ jobs:
run: go tool cover -func target/reports/merged-test-coverage.out | grep LoadSpec | grep '100.0%'
- run: docker images | grep 'quay.io/elisaoyj/sre-godemo'
- name: Notify failure
if: github.event.pull_request.draft == false &&
failure()
if: github.event.pull_request.draft == false && failure()
env:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
MATTERMOST_TEXT: "${{ github.repository }} PR build. Please check [here](${{ github.event.pull_request.html_url }}/checks)."
Expand Down
25 changes: 19 additions & 6 deletions go.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package mageutil
import (
"context"
"fmt"
"log"
"os"
"path"
"strings"
Expand Down Expand Up @@ -207,18 +208,30 @@ func BinDir() (string, error) {
return path.Join(TargetDir, "bin", goos, goarch), nil
}

// Ensure checks that all dependencies are up to date
// Ensure runs Tidy checks that all dependencies are up to date
// Deprecated: use Tidy instead
func Ensure(ctx context.Context) error {
if err := Go(ctx, "mod", "tidy"); err != nil {
return err
}
return nil
log.Println("WARNING: Ensure is deprecated, use Tidy instead")
return Tidy(ctx)
}

// EnsureInSync checks that all dependencies are up to date
// useful in CI/CD pipelines to validate that dependencies match go.mod
// Deprecated: use TidyAndVerifyNoChanges instead
func EnsureInSync(ctx context.Context) error {
if err := Ensure(ctx); err != nil {
log.Println("WARNING: EnsureInSync is deprecated, use TidyAndVerifyNoChanges instead")
return TidyAndVerifyNoChanges(ctx)
}

// Tidy runs go mod tidy
func Tidy(ctx context.Context) error {
return Go(ctx, "mod", "tidy")
}

// TidyAndVerifyNoChanges runs go mod tidy and verifies that there are no changes to go.mod or go.sum
// useful in CI/CD pipelines to validate that dependencies match go.mod
func TidyAndVerifyNoChanges(ctx context.Context) error {
if err := Tidy(ctx); err != nil {
return err
}
if err := Git(ctx, "diff", "--exit-code", "--", "go.mod", "go.sum"); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions godemo/magefiles/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,27 @@ func SwaggerDocs(ctx context.Context) error {
}

// Ensure dependencies
// Deprecated: run for verifying backward compatibility
func Ensure(ctx context.Context) error {
return mageutil.Ensure(ctx)
}

// Ensure dependencies are in sync (CI)
// Deprecated: run for verifying backward compatibility
func EnsureInSync(ctx context.Context) error {
return mageutil.EnsureInSync(ctx)
}

// Tidy dependencies
func Tidy(ctx context.Context) error {
return mageutil.Tidy(ctx)
}

// TidyAndVerifyNoChanges dependencies
func TidyAndVerifyNoChanges(ctx context.Context) error {
return mageutil.TidyAndVerifyNoChanges(ctx)
}

// YamlLint some.yaml file
func YamlLint(ctx context.Context) error {
return mageutil.YamlLint(ctx, "some.yaml")
Expand Down

0 comments on commit 0ba5de6

Please sign in to comment.