From 7ccd2996e6fbbbe305653bdef135a500db395f1b Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Wed, 2 Feb 2022 13:27:31 -0500 Subject: [PATCH] consolidate binary builds and release uploads into goreleaser build configs Signed-off-by: Joe Lanford --- .github/workflows/goreleaser.yaml | 114 +++++++++++++++--- .github/workflows/release.yaml | 48 -------- Makefile | 4 +- release/goreleaser.darwin.yaml | 49 ++++++++ .../goreleaser.linux.yaml | 22 +--- release/goreleaser.opm.Dockerfile | 10 +- release/goreleaser.windows.yaml | 35 ++++++ scripts/fetch | 2 +- 8 files changed, 184 insertions(+), 100 deletions(-) delete mode 100644 .github/workflows/release.yaml create mode 100644 release/goreleaser.darwin.yaml rename .goreleaser.yaml => release/goreleaser.linux.yaml (88%) create mode 100644 release/goreleaser.windows.yaml diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index 1267e452c..71eade988 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -10,39 +10,107 @@ defaults: run: shell: bash jobs: - goreleaser: + release: + needs: + - build-windows + - build-darwin + - build-linux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/download-artifact@v2 + + - run: | + for dist in dist-*; do + tar -C "${dist}" -xf "${dist}/${dist}.tar" + done + + - name: Create assets + run: | + set -xe + mkdir -p assets + cat dist-*/dist/checksums.txt > assets/checksums.txt + for asset in dist-*/dist/*_*/*; do + base=$(basename "${asset}") + variant=$(basename $(dirname "${asset}") | cut -d_ -f1) + cp "${asset}" "assets/${variant}-${base}" + done + find assets -ls + cat assets/checksums.txt + + - name: Upload Release Assets + if: github.ref_type == 'tag' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release create "${{ github.ref_name }}" --generate-notes ./assets/* + + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + with: + # GoReleaser requires fetch-depth: 0 to correctly + # run git describe + fetch-depth: 0 + - uses: actions/setup-go@v2 + with: + go-version: '~1.16' + + - name: "Run GoReleaser" + run: make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_ARGS: release --rm-dist -f release/goreleaser.windows.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }} + + - run: tar -cvf dist-windows.tar dist + - uses: actions/upload-artifact@v2 + with: + name: dist-windows + path: dist-windows.tar + + build-darwin: + runs-on: macos-latest steps: - uses: actions/checkout@v2 with: - # GoReleaser requires fetch-depth: 0 for - # changelog generation to work correctly. + # GoReleaser requires fetch-depth: 0 to correctly + # run git describe fetch-depth: 0 - uses: actions/setup-go@v2 with: go-version: '~1.16' - - name: "Install linux cross-compilers" - run: | - sudo apt-get update - sudo apt-get install -y gcc-aarch64-linux-gnu gcc-s390x-linux-gnu gcc-powerpc64le-linux-gnu gcc-mingw-w64-x86-64 + - name: "Run GoReleaser" + run: make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_ARGS: release --rm-dist -f release/goreleaser.darwin.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }} - - name: "Install yq" - run: | - sudo wget https://github.com/mikefarah/yq/releases/download/v4.10.0/yq_linux_amd64 -O /usr/local/bin/yq - sudo chmod +x /usr/local/bin/yq + - run: tar -cvf dist-darwin.tar dist + - uses: actions/upload-artifact@v2 + with: + name: dist-darwin + path: dist-darwin.tar - - name: "Disable image pushes for pull requests" - if: github.event_name == 'pull_request' - run: | - yq eval '.dockers[].skip_push=true' -i .goreleaser.yaml - yq eval '.docker_manifests[].skip_push=true' -i .goreleaser.yaml + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # GoReleaser requires fetch-depth: 0 to correctly + # run git describe + fetch-depth: 0 + + - uses: actions/setup-go@v2 + with: + go-version: '~1.16' - - name: "Disable the Github release upload for non-tag builds" - if: startsWith(github.ref, 'refs/tags') != true + - name: "Install linux cross-compilers" run: | - yq eval '.release.disable=true' -i .goreleaser.yaml + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu gcc-s390x-linux-gnu gcc-powerpc64le-linux-gnu - name: "Set the image tag" run: | @@ -74,4 +142,10 @@ jobs: run: make release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_ARGS: release --rm-dist ${{ !startsWith(github.ref, 'refs/tags') && '--skip-validate' || '' }} + RELEASE_ARGS: release --rm-dist -f release/goreleaser.linux.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }} + + - run: tar -cvf dist-linux.tar dist + - uses: actions/upload-artifact@v2 + with: + name: dist-linux + path: dist-linux.tar diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 6d05f2f7d..000000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: release -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' -defaults: - run: - shell: bash -jobs: - create: - runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.release.outputs.upload_url }} - steps: - - uses: actions/create-release@v1 - id: release - env: - GITHUB_TOKEN: ${{ github.token }} - with: - draft: true - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - assets: - needs: create - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: '~1.16' - - run: | - echo "asset_path=bin/opm" >> $GITHUB_ENV - echo "asset_name=$(go env GOOS)-$(go env GOARCH)-opm$(go env GOEXE)" >> $GITHUB_ENV - - run: make ${{ env.asset_path }} - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ needs.create.outputs.upload_url }} - asset_path: ${{ env.asset_path }} - asset_name: ${{ env.asset_name }} - asset_content_type: application/octet-stream diff --git a/Makefile b/Makefile index e9743efa7..996613bee 100644 --- a/Makefile +++ b/Makefile @@ -137,9 +137,9 @@ export LATEST_IMAGE_OR_EMPTY ?= $(shell \ echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \ && [ "$(shell echo -e "$(OPM_VERSION)\n$(LATEST_TAG)" | sort -rV | head -n1)" == "$(OPM_VERSION)" ] \ && echo "$(OPM_IMAGE_REPO):latest" || echo "") -release: RELEASE_ARGS ?= release --rm-dist --snapshot +release: RELEASE_ARGS ?= release --rm-dist --snapshot -f release/goreleaser.$(shell go env GOOS).yaml release: - ./scripts/fetch goreleaser 0.177.0 && ./bin/goreleaser $(RELEASE_ARGS) + ./scripts/fetch goreleaser 1.4.1 && ./bin/goreleaser $(RELEASE_ARGS) # tagged-or-empty returns $(OPM_IMAGE_REPO):$(1) when HEAD is assigned a non-prerelease semver tag, # otherwise the empty string. An empty string causes goreleaser to skip building diff --git a/release/goreleaser.darwin.yaml b/release/goreleaser.darwin.yaml new file mode 100644 index 000000000..b60071040 --- /dev/null +++ b/release/goreleaser.darwin.yaml @@ -0,0 +1,49 @@ +builds: + - id: darwin-amd64 + main: ./cmd/opm + binary: opm + goos: + - darwin + goarch: + - amd64 + env: + - CGO_ENABLED=1 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: &build-flags + - -tags=json1 + asmflags: &build-asmflags + - all=-trimpath={{ .Env.PWD }} + gcflags: &build-gcflags + - all=-trimpath={{ .Env.PWD }} + ldflags: &build-ldflags + - -s -w + - -X {{ .Env.PKG }}/cmd/opm/version.gitCommit={{ .Env.GIT_COMMIT }} + - -X {{ .Env.PKG }}/cmd/opm/version.opmVersion={{ .Env.OPM_VERSION }} + - -X {{ .Env.PKG }}/cmd/opm/version.buildDate={{ .Env.BUILD_DATE }} + - id: darwin-arm64 + main: ./cmd/opm + binary: opm + goos: + - darwin + goarch: + - arm64 + env: + - CGO_ENABLED=1 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: *build-flags + asmflags: *build-asmflags + gcflags: *build-gcflags + ldflags: *build-ldflags +archives: + - id: opm + builds: + - darwin-amd64 + - darwin-arm64 + format: binary + name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}" +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Env.OPM_VERSION }}" +release: + disable: true diff --git a/.goreleaser.yaml b/release/goreleaser.linux.yaml similarity index 88% rename from .goreleaser.yaml rename to release/goreleaser.linux.yaml index 8049d451c..2f69f8dd5 100644 --- a/.goreleaser.yaml +++ b/release/goreleaser.linux.yaml @@ -67,21 +67,6 @@ builds: asmflags: *build-asmflags gcflags: *build-gcflags ldflags: *build-ldflags - - id: windows-amd64 - main: ./cmd/opm - binary: opm - goos: - - windows - goarch: - - amd64 - env: - - CC=x86_64-w64-mingw32-gcc-posix - - CGO_ENABLED=1 - mod_timestamp: "{{ .CommitTimestamp }}" - flags: *build-flags - asmflags: *build-asmflags - gcflags: *build-gcflags - ldflags: *build-ldflags archives: - id: opm builds: @@ -89,9 +74,8 @@ archives: - linux-arm64 - linux-ppc64le - linux-s390x - - windows-amd64 - name_template: "{{ .Binary }}_{{ .Env.OPM_VERSION }}_{{ .Os }}_{{ .Arch }}" format: binary + name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}" dockers: - image_templates: - "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64" @@ -167,8 +151,4 @@ checksum: snapshot: name_template: "{{ .Env.OPM_VERSION }}" release: - name_template: "{{ .Env.OPM_VERSION }}" - draft: true - ## Disable release steps, since a separate GitHub Action job - ## handles binary builds and release uploads disable: true diff --git a/release/goreleaser.opm.Dockerfile b/release/goreleaser.opm.Dockerfile index 51637d34b..50e90df28 100644 --- a/release/goreleaser.opm.Dockerfile +++ b/release/goreleaser.opm.Dockerfile @@ -2,15 +2,9 @@ # build opm images. See the configurations in .goreleaser.yaml # and .github/workflows/release.yaml. -FROM alpine as grpc_health_probe -ARG TARGETARCH -RUN apk update && \ - apk add curl && \ - curl --silent --show-error --location --output /grpc_health_probe \ - https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.5/grpc_health_probe-linux-$TARGETARCH && \ - chmod 755 /grpc_health_probe +FROM ghcr.io/grpc-ecosystem/grpc-health-probe:v0.4.6 as grpc_health_probe FROM gcr.io/distroless/static:debug -COPY --from=grpc_health_probe /grpc_health_probe /bin/grpc_health_probe +COPY --from=grpc_health_probe /ko-app/grpc-health-probe /bin/grpc_health_probe COPY ["nsswitch.conf", "/etc/nsswitch.conf"] COPY opm /bin/opm ENTRYPOINT ["/bin/opm"] diff --git a/release/goreleaser.windows.yaml b/release/goreleaser.windows.yaml new file mode 100644 index 000000000..4232f5eea --- /dev/null +++ b/release/goreleaser.windows.yaml @@ -0,0 +1,35 @@ +builds: + - id: windows-amd64 + main: ./cmd/opm + binary: opm + goos: + - windows + goarch: + - amd64 + env: + - CGO_ENABLED=1 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: &build-flags + - -tags=json1,netgo,osusergo + asmflags: &build-asmflags + - all=-trimpath={{ .Env.PWD }} + gcflags: &build-gcflags + - all=-trimpath={{ .Env.PWD }} + ldflags: &build-ldflags + - -s -w + - -extldflags=-static + - -X {{ .Env.PKG }}/cmd/opm/version.gitCommit={{ .Env.GIT_COMMIT }} + - -X {{ .Env.PKG }}/cmd/opm/version.opmVersion={{ .Env.OPM_VERSION }} + - -X {{ .Env.PKG }}/cmd/opm/version.buildDate={{ .Env.BUILD_DATE }} +archives: + - id: opm + builds: + - windows-amd64 + format: binary + name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}" +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Env.OPM_VERSION }}" +release: + disable: true diff --git a/scripts/fetch b/scripts/fetch index ac383f67d..3a5b8daba 100755 --- a/scripts/fetch +++ b/scripts/fetch @@ -15,7 +15,7 @@ fetch() { ;; "goreleaser") ver_cmd="${ROOT}/bin/goreleaser --version 2>/dev/null | grep 'goreleaser version' | cut -d' ' -f3" - fetch_cmd="curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b \"${ROOT}/bin\" -d \"v${ver}\"" + fetch_cmd="GOBIN=${ROOT}/bin go install github.com/goreleaser/goreleaser@v${ver}" ;; *) echo "unknown tool $tool"