From 59561aa48b41361cf23084dda9f621ab5c5dcef1 Mon Sep 17 00:00:00 2001 From: Zinovii Dmytriv Date: Tue, 18 Apr 2023 19:56:56 +0300 Subject: [PATCH] Releasing with `goreleaser` (#21) * Releasing with goreleaser * Releasing with goreleaser * Releasing with goreleaser * addressed comments and removed sources from being attached to release via goreleaser because they are attached anyway so no need to do it twice * Addressed comments * splitted build.yml workflow into and build.yml and build-snapshot.yml * update --------- Co-authored-by: Your Name --- .github/workflows/feature-branch.yml | 38 ++++++++++++++++++++ .github/workflows/go.yml | 52 ---------------------------- .github/workflows/release.yml | 34 ++++++++++++++++++ .gitignore | 3 +- .goreleaser.yaml | 39 +++++++++++++++++++++ Dockerfile | 4 +-- go.mod | 4 +-- go.sum | 23 ++---------- 8 files changed, 118 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/feature-branch.yml delete mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml new file mode 100644 index 0000000..f94fa98 --- /dev/null +++ b/.github/workflows/feature-branch.yml @@ -0,0 +1,38 @@ +name: Feature Branch + +on: + workflow_dispatch: + + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.20' + + - name: Test Snapshot Release + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean --snapshot + + - name: Upload Test Release Assets + uses: actions/upload-artifact@v3 + with: + name: github-status-updater + path: dist/* + retention-days: 3 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 22713b9..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: 'go' - -on: - release: - types: [published] - - pull_request: - types: [opened, synchronize, reopened] - -jobs: - build: - runs-on: ubuntu-latest - steps: - # Checkout the repo - - name: 'Checkout' - uses: actions/checkout@v2 - # Build Go binaries - - name: 'Build Go binaries' - uses: cloudposse/actions/go/build@0.15.0 - env: - GO111MODULE: on - # Architectures to build for - GOX_OSARCH: >- - windows/386 - windows/amd64 - freebsd/arm - netbsd/386 - netbsd/amd64 - netbsd/arm - linux/s390x - linux/arm - darwin/386 - darwin/amd64 - linux/386 - linux/amd64 - freebsd/amd64 - freebsd/386 - openbsd/386 - openbsd/amd64 - OUTPUT_PATH: ${{ github.workspace }}/release/${{ github.event.repository.name }}_ - - name: 'Upload artifacts' - uses: actions/upload-artifact@v2 - with: - name: ${{ github.event.repository.name }} - path: ${{ github.workspace }}/release/* - # Attach Go binaries to GitHub Release - - name: 'Attach artifacts to GitHub Release' - if: ${{ github.event_name == 'release' }} - uses: cloudposse/actions/github/release-assets@0.15.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - INPUT_PATH: ${{ github.workspace }}/release/${{ github.event.repository.name }}_* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7e1a769 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release + +on: + workflow_dispatch: + + release: + types: + - published + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.20' + + - name: Public Release + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 24fc2e5..6d80d51 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,4 @@ build-harness # Output of the go coverage tool, specifically when used with LiteIDE *.out -# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..ea08b30 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,39 @@ +builds: + - env: + # goreleaser does not work with CGO, it could also complicate + # usage by users in CI/CD systems like Terraform Cloud where + # they are unable to install libraries. + - CGO_ENABLED=0 + mod_timestamp: '{{ .CommitTimestamp }}' + goos: + - darwin + - freebsd + - windows + - linux + goarch: + - amd64 + - '386' + - arm + - arm64 + ldflags: + # -s Omit the symbol table and debug information + # -w Omit the DWARF symbol table + # -X importpath.name=value # set the value of the string variable in importpath named name to value + # Someday we could implement a "version" command and set the version like this: + # - '-s -w -X "github.com/cloudposse/github-status-updater/cmd.Version={{.Env.GORELEASER_CURRENT_TAG}}"' + - '-s -w' + +archives: + - format: binary + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' + +checksum: + name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + algorithm: sha256 + +release: +# If you want to manually examine the release before it is live, uncomment this line: +# draft: true + +changelog: + skip: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index daf4834..13ca5a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM golang:1.13.3-buster as builder +FROM golang:1.20.3-bullseye as builder ENV GO111MODULE=on ENV CGO_ENABLED=0 WORKDIR /usr/src/ COPY . /usr/src RUN go build -v -o "bin/github-status-updater" *.go -FROM alpine:3.12 +FROM alpine:3.17 RUN apk add --no-cache ca-certificates COPY --from=builder /usr/src/bin/* /usr/bin/ ENV PATH $PATH:/usr/bin diff --git a/go.mod b/go.mod index a15f88e..860371e 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/cloudposse/github-status-updater -go 1.17 +go 1.20 require github.com/google/go-github/v42 v42.0.0 require ( github.com/google/go-querystring v1.1.0 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/crypto v0.8.0 // indirect ) diff --git a/go.sum b/go.sum index 763175a..04720c4 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,9 @@ -github.com/bradleyfalzon/ghinstallation/v2 v2.0.3/go.mod h1:tlgi+JWCXnKFx/Y4WtnDbZEINo31N5bcvnCoqieefmk= -github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-github/v39 v39.0.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE= github.com/google/go-github/v42 v42.0.0 h1:YNT0FwjPrEysRkLIiKuEfSvBPCGKphW5aS5PxwaoLec= github.com/google/go-github/v42 v42.0.0/go.mod h1:jgg/jvyI0YlDOM1/ps6XYh04HNQ3vKf0CVko62/EhRg= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=