From 29960797b2d248551783ea54002faa917b8eea4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Egyed?= Date: Sun, 1 Aug 2021 13:48:36 +0200 Subject: [PATCH] Configure go releaser and build releases for tags --- .github/workflows/go.yml | 34 ++++++++++++++++++++++++++++ .gitignore | 2 ++ .goreleaser.yml | 48 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 43 ----------------------------------- Dockerfile | 24 +++----------------- go.sum | 1 - 6 files changed, 87 insertions(+), 65 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a4021c0..b6f3663 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -3,6 +3,7 @@ name: Go on: push: branches: [ master ] + tags: ['*'] pull_request: branches: [ master ] @@ -23,3 +24,36 @@ jobs: - name: Test run: go test -v ./... + + publish: + needs: build + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Log in to Docker Hub + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.gitignore b/.gitignore index d4480e2..3d8af29 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ # misc *.tmp + +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..5dae30d --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,48 @@ +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm + - arm64 + flags: + - -trimpath + ldflags: + - -s -w +dockers: + - image_templates: + - "costela/docker-etchosts:{{ .Tag }}" + - "costela/docker-etchosts:{{ .Major }}" + - "costela/docker-etchosts:{{ .Major }}.{{ .Minor }}" + - "costela/docker-etchosts:latest" +archives: + - format_overrides: + - goos: windows + format: zip + replacements: + darwin: mac + format: binary +checksum: + algorithm: sha512 +snapshot: + name_template: "{{ incpatch .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +release: + draft: true + prerelease: auto + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7859729..0000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -language: go - -dist: xenial - -go: - - "1.13" - - "1.x" - - "master" - -matrix: - allow_failures: - - go: "master" - fast_finish: true - -script: go test -v - -env: -- GO111MODULE=on - -cache: - directories: - - /home/travis/gopath/pkg/mod - -install: true # skip, handled by "cache" stage - -stages: - - cache - - test - - deploy - -jobs: - include: - - stage: cache - script: go mod download - - stage: deploy - script: skip - env: - - secure: "FOx2FP9HJs1AupPp2yZ84z5yaPwYSRAaT2OGoRf/RAgRtzxF0qZdi9T/IBu5Kz5b1IyMWvteIjEj2PFyKjRTkn9mASzPnk0+ymtfxdxm34TM0gXfy/3WgG4W90bNeiX3ZQ8cXliwBvBIe7HYfRz9733Q1Mh2P2NVhtWi/PlPelDbvtvTVnEArrveXln/HbnDhjVN3MdPc4eCZymQT4QtcuQ89ERdFqVGaOYGevMAYaaGJ2BgsT8I41YDCs+TkuLA3cbZmDp4Q2DvRoLrPW2MJh6fwmql+3pButDvehNE+I4OL+R1d7kWEhY9ikzvsp0x5dxyEf2PBBDv2A2z8cGb0MfQFhPvwtlc5drDrv9psqGrNjBZZ38pGWJas3kMr6yGMj1au7CaVvW16W+23XFRSuwE0s4V4ls1z5a5nUTi7Yfgi1NtJiFQq3iiSRcB1SkH/FV0UKM3Gy/grQEUywR+V0p8hO8C7QD+dFRQwg822xraCaN3oLNND5EUmA6bI9knAWZTjFMXwYfiO2W3cdWoQ3YtLlULPzNBqVAjOGgkvtnZclLyAK8iq4ygnXo+VIIOZ4EK0Ze9ibsDZHwbuX06vIoG/wbAFN9HV+WwaPE1pzfcjJ9wkhERz6OPIZlA59DRDqHSpIA45kf38VEBRTA47LT5z2ThAAbuWFWTIkBOn38=" - deploy: - provider: script - script: 'curl -si -H "Content-Type: application/json" --data "{\"source_type\": \"Tag\", \"source_name\": \"${TRAVIS_TAG}\"}" -X POST https://registry.hub.docker.com/u/costela/docker-etchosts/trigger/${DOCKER_HUB_TOKEN}/' - on: - tags: true diff --git a/Dockerfile b/Dockerfile index a96e010..ac8a284 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,3 @@ -FROM golang:1.13-alpine AS build - -RUN apk add --update git - -ENV CGO_ENABLED=0 - -WORKDIR /app - -COPY go.mod go.sum ./ - -RUN go mod download - -COPY *.go /app/ - -RUN go build -v - -FROM alpine - -COPY --from=build /app/docker-etchosts /docker-etchosts - -CMD [ "/docker-etchosts" ] \ No newline at end of file +FROM scratch +ENTRYPOINT ["/docker-etchosts"] +COPY docker-etchosts / diff --git a/go.sum b/go.sum index a690e83..8be9fad 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,6 @@ github.com/Microsoft/go-winio v0.4.9 h1:3RbgqgGVqmcpbOiwrjbVtDHLlJBGF6aE+yHmNtBN github.com/Microsoft/go-winio v0.4.9/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY= github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=