Skip to content

Commit 0b008de

Browse files
authored
consolidate binary builds and release uploads into goreleaser build configs (#914)
Signed-off-by: Joe Lanford <[email protected]>
1 parent 00dbb12 commit 0b008de

File tree

8 files changed

+184
-100
lines changed

8 files changed

+184
-100
lines changed

.github/workflows/goreleaser.yaml

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,107 @@ defaults:
1010
run:
1111
shell: bash
1212
jobs:
13-
goreleaser:
13+
release:
14+
needs:
15+
- build-windows
16+
- build-darwin
17+
- build-linux
18+
1419
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: actions/download-artifact@v2
23+
24+
- run: |
25+
for dist in dist-*; do
26+
tar -C "${dist}" -xf "${dist}/${dist}.tar"
27+
done
28+
29+
- name: Create assets
30+
run: |
31+
set -xe
32+
mkdir -p assets
33+
cat dist-*/dist/checksums.txt > assets/checksums.txt
34+
for asset in dist-*/dist/*_*/*; do
35+
base=$(basename "${asset}")
36+
variant=$(basename $(dirname "${asset}") | cut -d_ -f1)
37+
cp "${asset}" "assets/${variant}-${base}"
38+
done
39+
find assets -ls
40+
cat assets/checksums.txt
41+
42+
- name: Upload Release Assets
43+
if: github.ref_type == 'tag'
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: gh release create "${{ github.ref_name }}" --generate-notes ./assets/*
47+
48+
build-windows:
49+
runs-on: windows-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
with:
53+
# GoReleaser requires fetch-depth: 0 to correctly
54+
# run git describe
55+
fetch-depth: 0
56+
- uses: actions/setup-go@v2
57+
with:
58+
go-version: '~1.16'
59+
60+
- name: "Run GoReleaser"
61+
run: make release
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
RELEASE_ARGS: release --rm-dist -f release/goreleaser.windows.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }}
65+
66+
- run: tar -cvf dist-windows.tar dist
67+
- uses: actions/upload-artifact@v2
68+
with:
69+
name: dist-windows
70+
path: dist-windows.tar
71+
72+
build-darwin:
73+
runs-on: macos-latest
1574
steps:
1675
- uses: actions/checkout@v2
1776
with:
18-
# GoReleaser requires fetch-depth: 0 for
19-
# changelog generation to work correctly.
77+
# GoReleaser requires fetch-depth: 0 to correctly
78+
# run git describe
2079
fetch-depth: 0
2180

2281
- uses: actions/setup-go@v2
2382
with:
2483
go-version: '~1.16'
2584

26-
- name: "Install linux cross-compilers"
27-
run: |
28-
sudo apt-get update
29-
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-s390x-linux-gnu gcc-powerpc64le-linux-gnu gcc-mingw-w64-x86-64
85+
- name: "Run GoReleaser"
86+
run: make release
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
RELEASE_ARGS: release --rm-dist -f release/goreleaser.darwin.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }}
3090

31-
- name: "Install yq"
32-
run: |
33-
sudo wget https://github.com/mikefarah/yq/releases/download/v4.10.0/yq_linux_amd64 -O /usr/local/bin/yq
34-
sudo chmod +x /usr/local/bin/yq
91+
- run: tar -cvf dist-darwin.tar dist
92+
- uses: actions/upload-artifact@v2
93+
with:
94+
name: dist-darwin
95+
path: dist-darwin.tar
3596

36-
- name: "Disable image pushes for pull requests"
37-
if: github.event_name == 'pull_request'
38-
run: |
39-
yq eval '.dockers[].skip_push=true' -i .goreleaser.yaml
40-
yq eval '.docker_manifests[].skip_push=true' -i .goreleaser.yaml
97+
build-linux:
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v2
101+
with:
102+
# GoReleaser requires fetch-depth: 0 to correctly
103+
# run git describe
104+
fetch-depth: 0
105+
106+
- uses: actions/setup-go@v2
107+
with:
108+
go-version: '~1.16'
41109

42-
- name: "Disable the Github release upload for non-tag builds"
43-
if: startsWith(github.ref, 'refs/tags') != true
110+
- name: "Install linux cross-compilers"
44111
run: |
45-
yq eval '.release.disable=true' -i .goreleaser.yaml
112+
sudo apt-get update
113+
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-s390x-linux-gnu gcc-powerpc64le-linux-gnu
46114
47115
- name: "Set the image tag"
48116
run: |
@@ -74,4 +142,10 @@ jobs:
74142
run: make release
75143
env:
76144
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
RELEASE_ARGS: release --rm-dist ${{ !startsWith(github.ref, 'refs/tags') && '--skip-validate' || '' }}
145+
RELEASE_ARGS: release --rm-dist -f release/goreleaser.linux.yaml --skip-validate ${{ github.event_name == 'pull_request' && '--snapshot' || '' }}
146+
147+
- run: tar -cvf dist-linux.tar dist
148+
- uses: actions/upload-artifact@v2
149+
with:
150+
name: dist-linux
151+
path: dist-linux.tar

.github/workflows/release.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ export LATEST_IMAGE_OR_EMPTY ?= $(shell \
137137
echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
138138
&& [ "$(shell echo -e "$(OPM_VERSION)\n$(LATEST_TAG)" | sort -rV | head -n1)" == "$(OPM_VERSION)" ] \
139139
&& echo "$(OPM_IMAGE_REPO):latest" || echo "")
140-
release: RELEASE_ARGS ?= release --rm-dist --snapshot
140+
release: RELEASE_ARGS ?= release --rm-dist --snapshot -f release/goreleaser.$(shell go env GOOS).yaml
141141
release:
142-
./scripts/fetch goreleaser 0.177.0 && ./bin/goreleaser $(RELEASE_ARGS)
142+
./scripts/fetch goreleaser 1.4.1 && ./bin/goreleaser $(RELEASE_ARGS)
143143

144144
# tagged-or-empty returns $(OPM_IMAGE_REPO):$(1) when HEAD is assigned a non-prerelease semver tag,
145145
# otherwise the empty string. An empty string causes goreleaser to skip building

release/goreleaser.darwin.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
builds:
2+
- id: darwin-amd64
3+
main: ./cmd/opm
4+
binary: opm
5+
goos:
6+
- darwin
7+
goarch:
8+
- amd64
9+
env:
10+
- CGO_ENABLED=1
11+
mod_timestamp: "{{ .CommitTimestamp }}"
12+
flags: &build-flags
13+
- -tags=json1
14+
asmflags: &build-asmflags
15+
- all=-trimpath={{ .Env.PWD }}
16+
gcflags: &build-gcflags
17+
- all=-trimpath={{ .Env.PWD }}
18+
ldflags: &build-ldflags
19+
- -s -w
20+
- -X {{ .Env.PKG }}/cmd/opm/version.gitCommit={{ .Env.GIT_COMMIT }}
21+
- -X {{ .Env.PKG }}/cmd/opm/version.opmVersion={{ .Env.OPM_VERSION }}
22+
- -X {{ .Env.PKG }}/cmd/opm/version.buildDate={{ .Env.BUILD_DATE }}
23+
- id: darwin-arm64
24+
main: ./cmd/opm
25+
binary: opm
26+
goos:
27+
- darwin
28+
goarch:
29+
- arm64
30+
env:
31+
- CGO_ENABLED=1
32+
mod_timestamp: "{{ .CommitTimestamp }}"
33+
flags: *build-flags
34+
asmflags: *build-asmflags
35+
gcflags: *build-gcflags
36+
ldflags: *build-ldflags
37+
archives:
38+
- id: opm
39+
builds:
40+
- darwin-amd64
41+
- darwin-arm64
42+
format: binary
43+
name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}"
44+
checksum:
45+
name_template: 'checksums.txt'
46+
snapshot:
47+
name_template: "{{ .Env.OPM_VERSION }}"
48+
release:
49+
disable: true

.goreleaser.yaml renamed to release/goreleaser.linux.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,15 @@ builds:
6767
asmflags: *build-asmflags
6868
gcflags: *build-gcflags
6969
ldflags: *build-ldflags
70-
- id: windows-amd64
71-
main: ./cmd/opm
72-
binary: opm
73-
goos:
74-
- windows
75-
goarch:
76-
- amd64
77-
env:
78-
- CC=x86_64-w64-mingw32-gcc-posix
79-
- CGO_ENABLED=1
80-
mod_timestamp: "{{ .CommitTimestamp }}"
81-
flags: *build-flags
82-
asmflags: *build-asmflags
83-
gcflags: *build-gcflags
84-
ldflags: *build-ldflags
8570
archives:
8671
- id: opm
8772
builds:
8873
- linux-amd64
8974
- linux-arm64
9075
- linux-ppc64le
9176
- linux-s390x
92-
- windows-amd64
93-
name_template: "{{ .Binary }}_{{ .Env.OPM_VERSION }}_{{ .Os }}_{{ .Arch }}"
9477
format: binary
78+
name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}"
9579
dockers:
9680
- image_templates:
9781
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
@@ -167,8 +151,4 @@ checksum:
167151
snapshot:
168152
name_template: "{{ .Env.OPM_VERSION }}"
169153
release:
170-
name_template: "{{ .Env.OPM_VERSION }}"
171-
draft: true
172-
## Disable release steps, since a separate GitHub Action job
173-
## handles binary builds and release uploads
174154
disable: true

release/goreleaser.opm.Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
# build opm images. See the configurations in .goreleaser.yaml
33
# and .github/workflows/release.yaml.
44

5-
FROM alpine as grpc_health_probe
6-
ARG TARGETARCH
7-
RUN apk update && \
8-
apk add curl && \
9-
curl --silent --show-error --location --output /grpc_health_probe \
10-
https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.5/grpc_health_probe-linux-$TARGETARCH && \
11-
chmod 755 /grpc_health_probe
5+
FROM ghcr.io/grpc-ecosystem/grpc-health-probe:v0.4.6 as grpc_health_probe
126
FROM gcr.io/distroless/static:debug
13-
COPY --from=grpc_health_probe /grpc_health_probe /bin/grpc_health_probe
7+
COPY --from=grpc_health_probe /ko-app/grpc-health-probe /bin/grpc_health_probe
148
COPY ["nsswitch.conf", "/etc/nsswitch.conf"]
159
COPY opm /bin/opm
1610
ENTRYPOINT ["/bin/opm"]

release/goreleaser.windows.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
builds:
2+
- id: windows-amd64
3+
main: ./cmd/opm
4+
binary: opm
5+
goos:
6+
- windows
7+
goarch:
8+
- amd64
9+
env:
10+
- CGO_ENABLED=1
11+
mod_timestamp: "{{ .CommitTimestamp }}"
12+
flags: &build-flags
13+
- -tags=json1,netgo,osusergo
14+
asmflags: &build-asmflags
15+
- all=-trimpath={{ .Env.PWD }}
16+
gcflags: &build-gcflags
17+
- all=-trimpath={{ .Env.PWD }}
18+
ldflags: &build-ldflags
19+
- -s -w
20+
- -extldflags=-static
21+
- -X {{ .Env.PKG }}/cmd/opm/version.gitCommit={{ .Env.GIT_COMMIT }}
22+
- -X {{ .Env.PKG }}/cmd/opm/version.opmVersion={{ .Env.OPM_VERSION }}
23+
- -X {{ .Env.PKG }}/cmd/opm/version.buildDate={{ .Env.BUILD_DATE }}
24+
archives:
25+
- id: opm
26+
builds:
27+
- windows-amd64
28+
format: binary
29+
name_template: "{{ .Os }}-{{ .Arch }}-{{ .Binary }}"
30+
checksum:
31+
name_template: 'checksums.txt'
32+
snapshot:
33+
name_template: "{{ .Env.OPM_VERSION }}"
34+
release:
35+
disable: true

scripts/fetch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fetch() {
1515
;;
1616
"goreleaser")
1717
ver_cmd="${ROOT}/bin/goreleaser --version 2>/dev/null | grep 'goreleaser version' | cut -d' ' -f3"
18-
fetch_cmd="curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b \"${ROOT}/bin\" -d \"v${ver}\""
18+
fetch_cmd="GOBIN=${ROOT}/bin go install github.com/goreleaser/goreleaser@v${ver}"
1919
;;
2020
*)
2121
echo "unknown tool $tool"

0 commit comments

Comments
 (0)