Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance workflow #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

crazy-max
Copy link

@crazy-max crazy-max commented Sep 4, 2021

@psampaz First of all thank you for this great project! Really useful!

As a modest gift, here is a PR that offers some enhancements for the current workflow:

  • Use buildx bake and goreleaser
  • Create artifacts with artifact (current platform) or artifact-all target for cross-compilation:
    • darwin/amd64
    • darwin/arm64
    • linux/amd64
    • linux/arm/v6
    • linux/arm/v7
    • linux/arm64
    • windows/amd64
  • Sandboxed vendor and lint validation with bake targets
  • Fix go.sum
  • Mutualize tests and handle them through bake and GitHub Actions with coverage
  • Update codecov/codecov-action to v2
  • Support Docker multi-platform image
  • GitHub Actions
    • On git push tag event semver like v0.9.0:
      • Artifacts will be available in the pipeline through actions/upload-artifact
      • Will create the GitHub Release and push artifacts
      • Will create and push Docker tags psampaz/go-mod-outdated:0.9.0 / psampaz/go-mod-outdated:latest
    • On git push (master branch)
      • Artifacts will be available in the pipeline through actions/upload-artifact
      • Will push Docker tag psampaz/go-mod-outdated:edge
    • On git pull_request event

Everything is already in place and tested on https://github.com/crazy-max/go-mod-outdated as well as the GitHub Actions pipeline if you want to take a look.

image

https://github.com/crazy-max/go-mod-outdated/releases/tag/v0.9.0

image

https://hub.docker.com/r/crazymax/go-mod-outdated/tags?page=1&ordering=last_updated

Comment on lines +123 to +124
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Before merging:

@@ -0,0 +1,96 @@
// Go version
variable "GO_VERSION" {
default = "1.16.3"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one place to change Go version for your project that will be used across all targets (_common)

RUN apk add --no-cache gcc linux-headers musl-dev
WORKDIR /src

FROM golangci/golangci-lint:v1.37.1-alpine AS golangci-lint
Copy link
Author

@crazy-max crazy-max Sep 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to change the golangci-lint version it's here with their official Docker image.

Comment on lines +17 to +18
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic -race ./... && \
go tool cover -func=/tmp/coverage.txt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test and coverage is done here

go tool cover -func=/tmp/coverage.txt

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage.txt /coverage.txt
Copy link
Author

@crazy-max crazy-max Sep 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use a special scratch stage to export coverage result back to the host (output = ["."] in docker-bake.hcl).

Comment on lines +20 to +24
if [ -n "$(git status --porcelain -- go.mod go.sum)" ]; then \
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
git status --porcelain -- go.mod go.sum; \
exit 1; \
fi
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make sure go.mod|sum is valid.

@crazy-max crazy-max marked this pull request as ready for review September 5, 2021 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant