Skip to content

Commit 370fac9

Browse files
caarlos0myitcv
authored andcommitted
ci: improve goreleaser workflow
* updated to latest goreleaser * build docker images as well * build from go proxy * improve version command to use build info only: * on on proxy builds (e.g. go run) it will show cue version devel just as before * on proxied builds it will show the mod version + its checksum Closes #1100 Closes #1105 Signed-off-by: Carlos Alexandro Becker <[email protected]> Change-Id: I3666b3c7b2194557483ccc8ec3e71e06bb9689ee Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/521069 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 38c8f7d commit 370fac9

File tree

7 files changed

+207
-370
lines changed

7 files changed

+207
-370
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,22 @@ jobs:
1919
- name: Install Go
2020
uses: actions/setup-go@v2
2121
with:
22-
go-version: ${{ matrix.go-version }}
23-
version: 1.15.8
22+
go-version: 1.15.8
2423
stable: false
24+
- name: Setup qemu
25+
uses: docker/setup-qemu-action@v1
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v1
28+
- name: Docker Login
29+
uses: docker/login-action@v1
30+
with:
31+
registry: docker.io
32+
username: cueckoo
33+
password: ${{ secrets.CUECKOO_DOCKER_PAT }}
2534
- name: Run GoReleaser
2635
uses: goreleaser/goreleaser-action@v2
2736
with:
2837
args: release --rm-dist
29-
version: v0.155.1
38+
version: v0.173.2
3039
env:
3140
GITHUB_TOKEN: ${{ secrets.CUECKOO_GITHUB_PAT }}
32-
docker:
33-
name: docker
34-
runs-on: ubuntu-18.04
35-
defaults:
36-
run:
37-
shell: bash
38-
steps:
39-
- name: Checkout code
40-
uses: actions/checkout@v2
41-
- name: Set version environment
42-
run: |-
43-
CUE_VERSION=$(echo ${GITHUB_REF##refs/tags/v})
44-
echo "CUE_VERSION=$CUE_VERSION"
45-
echo "CUE_VERSION=$(echo $CUE_VERSION)" >> $GITHUB_ENV
46-
- name: Push to Docker Hub
47-
uses: docker/build-push-action@v1
48-
with:
49-
tags: ${{ env.CUE_VERSION }},latest
50-
repository: cue-lang/cue
51-
username: cueckoo
52-
password: ${{ secrets.CUECKOO_DOCKER_PAT }}
53-
tag_with_ref: false
54-
tag_with_sha: false
55-
target: cue
56-
always_pull: true
57-
build_args: GOLANG_VERSION=${{ env.GOLANG_VERSION }},CUE_VERSION=v${{ env.CUE_VERSION
58-
}}
59-
add_git_labels: true
60-
env:
61-
DOCKER_BUILDKIT: 1
62-
GOLANG_VERSION: 1.14
63-
CUE_VERSION: ${{ env.CUE_VERSION }}

.goreleaser.yml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
project_name: cue
22

3-
before:
4-
hooks:
5-
- go mod download
3+
gomod:
4+
proxy: true
65

76
builds:
87
- env:
@@ -11,8 +10,8 @@ builds:
1110
binary: cue
1211
ldflags:
1312
- -s -w
14-
- -X cuelang.org/go/cmd/cue/cmd.version={{.Version}}
1513
# TODO: consider adding the following for a verbose mode
14+
# - -X cuelang.org/go/cmd/cue/cmd.version={{.Version}}
1615
# - -X cuelang.org/go/cmd/cue/cmd.commit={{.ShortCommit}}
1716
# - -X cuelang.org/go/cmd/cue/cmd.date={{.Date}}
1817
# - -X cuelang.org/cmd/cue/cmd.date={{.Env.GOVERSION}}
@@ -63,3 +62,44 @@ brews:
6362
description: "CUE is an open source data constraint language which aims to simplify tasks involving defining and using data."
6463
test: |
6564
system "#{bin}/cue version"
65+
66+
67+
dockers:
68+
- image_templates:
69+
- "docker.io/cuelang/cue:{{ .Version }}-amd64"
70+
dockerfile: Dockerfile
71+
use: buildx
72+
build_flag_templates:
73+
- --platform=linux/amd64
74+
- --label=org.opencontainers.image.title={{ .ProjectName }}
75+
- --label=org.opencontainers.image.description={{ .ProjectName }}
76+
- --label=org.opencontainers.image.url=https://github.com/cue-lang/cue
77+
- --label=org.opencontainers.image.source=https://github.com/cue-lang/cue
78+
- --label=org.opencontainers.image.version={{ .Version }}
79+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
80+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
81+
- --label=org.opencontainers.image.licenses=Apache 2.0
82+
- image_templates:
83+
- "docker.io/cuelang/cue:{{ .Version }}-arm64"
84+
dockerfile: Dockerfile
85+
use: buildx
86+
build_flag_templates:
87+
- --platform=linux/arm64/v8
88+
- --label=org.opencontainers.image.title={{ .ProjectName }}
89+
- --label=org.opencontainers.image.description={{ .ProjectName }}
90+
- --label=org.opencontainers.image.url=https://github.com/cue-lang/cue
91+
- --label=org.opencontainers.image.source=https://github.com/cue-lang/cue
92+
- --label=org.opencontainers.image.version={{ .Version }}
93+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
94+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
95+
- --label=org.opencontainers.image.licenses=Apache 2.0
96+
97+
docker_manifests:
98+
- name_template: docker.io/cuelang/cue:{{ .Version }}
99+
image_templates:
100+
- docker.io/cuelang/cue:{{ .Version }}-amd64
101+
- docker.io/cuelang/cue:{{ .Version }}-arm64v8
102+
- name_template: docker.io/cuelang/cue:latest
103+
image_templates:
104+
- docker.io/cuelang/cue:{{ .Version }}-amd64
105+
- docker.io/cuelang/cue:{{ .Version }}-arm64v8

Dockerfile

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
# target: cue-builder
2-
ARG GOLANG_VERSION
3-
FROM docker.io/golang:${GOLANG_VERSION}-alpine AS cue-builder
4-
ARG CUE_VERSION
5-
ENV \
6-
OUTDIR='/out' \
7-
GO111MODULE='on'
8-
RUN set -eux && \
9-
apk add --no-cache \
10-
git
11-
WORKDIR /go/src/cuelang.org/go
12-
COPY go.mod /go/src/cuelang.org/go/
13-
COPY go.sum /go/src/cuelang.org/go/
14-
RUN set -eux && \
15-
go mod download
16-
COPY . /go/src/cuelang.org/go/
17-
RUN set -eux && \
18-
CGO_ENABLED=0 GOBIN=${OUTDIR}/usr/bin/ go install \
19-
-a -v \
20-
-tags='osusergo,netgo' \
21-
-installsuffix='netgo' \
22-
-ldflags="-s -w -X cuelang.org/go/cmd/cue/cmd.version=${CUE_VERSION} \"-extldflags=-static\"" \
23-
./cmd/cue
24-
25-
# target: cue
26-
FROM gcr.io/distroless/static:latest AS cue
27-
COPY --from=cue-builder /out/ /
1+
FROM gcr.io/distroless/static:latest
2+
COPY cue /usr/bin/cue
283
ENTRYPOINT ["/usr/bin/cue"]

cmd/cue/cmd/testdata/script/cmd_github.txt

Lines changed: 41 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -92,48 +92,25 @@ jobs:
9292
- name: Install Go
9393
uses: actions/setup-go@v2
9494
with:
95-
go-version: ${{ matrix.go-version }}
96-
version: 1.15.8
95+
go-version: 1.15.8
9796
stable: false
97+
- name: Setup qemu
98+
uses: docker/setup-qemu-action@v1
99+
- name: Set up Docker Buildx
100+
uses: docker/setup-buildx-action@v1
101+
- name: Docker Login
102+
uses: docker/login-action@v1
103+
with:
104+
registry: docker.io
105+
username: cueckoo
106+
password: ${{ secrets.CUECKOO_DOCKER_PAT }}
98107
- name: Run GoReleaser
99108
uses: goreleaser/goreleaser-action@v2
100109
with:
101110
args: release --rm-dist
102-
version: v0.155.1
111+
version: v0.173.2
103112
env:
104113
GITHUB_TOKEN: ${{ secrets.CUECKOO_GITHUB_PAT }}
105-
docker:
106-
name: docker
107-
runs-on: ubuntu-18.04
108-
defaults:
109-
run:
110-
shell: bash
111-
steps:
112-
- name: Checkout code
113-
uses: actions/checkout@v2
114-
- name: Set version environment
115-
run: |-
116-
CUE_VERSION=$(echo ${GITHUB_REF##refs/tags/v})
117-
echo "CUE_VERSION=$CUE_VERSION"
118-
echo "CUE_VERSION=$(echo $CUE_VERSION)" >> $GITHUB_ENV
119-
- name: Push to Docker Hub
120-
uses: docker/build-push-action@v1
121-
with:
122-
tags: ${{ env.CUE_VERSION }},latest
123-
repository: cue-lang/cue
124-
username: cueckoo
125-
password: ${{ secrets.CUECKOO_DOCKER_PAT }}
126-
tag_with_ref: false
127-
tag_with_sha: false
128-
target: cue
129-
always_pull: true
130-
build_args: GOLANG_VERSION=${{ env.GOLANG_VERSION }},CUE_VERSION=v${{ env.CUE_VERSION
131-
}}
132-
add_git_labels: true
133-
env:
134-
DOCKER_BUILDKIT: 1
135-
GOLANG_VERSION: 1.14
136-
CUE_VERSION: ${{ env.CUE_VERSION }}
137114
-- .github/workflows/repository_dispatch.yml.golden --
138115
# Generated by internal/ci/ci_tool.cue; do not edit
139116

@@ -1298,55 +1275,35 @@ repository_dispatch: _#bashWorkflow & {
12981275
release: _#bashWorkflow & {
12991276
name: "Release"
13001277
on: push: tags: [_#releaseTagPattern]
1301-
jobs: {
1302-
goreleaser: {
1303-
"runs-on": _#linuxMachine
1304-
steps: [_#checkoutCode & {
1305-
with: "fetch-depth": 0
1306-
}, _#installGo & {
1307-
with: version: _#latestStableGo
1308-
}, _#step & {
1309-
name: "Run GoReleaser"
1310-
env: GITHUB_TOKEN: "${{ secrets.CUECKOO_GITHUB_PAT }}"
1311-
uses: "goreleaser/goreleaser-action@v2"
1312-
with: {
1313-
args: "release --rm-dist"
1314-
version: "v0.155.1"
1315-
}
1316-
}]
1317-
}
1318-
docker: {
1319-
name: "docker"
1320-
"runs-on": _#linuxMachine
1321-
steps: [_#checkoutCode, _#step & {
1322-
name: "Set version environment"
1323-
run: """
1324-
CUE_VERSION=$(echo ${GITHUB_REF##refs/tags/v})
1325-
echo \"CUE_VERSION=$CUE_VERSION\"
1326-
echo \"CUE_VERSION=$(echo $CUE_VERSION)\" >> $GITHUB_ENV
1327-
"""
1328-
}, _#step & {
1329-
name: "Push to Docker Hub"
1330-
env: {
1331-
DOCKER_BUILDKIT: 1
1332-
GOLANG_VERSION: 1.14
1333-
CUE_VERSION: "${{ env.CUE_VERSION }}"
1334-
}
1335-
uses: "docker/build-push-action@v1"
1336-
with: {
1337-
tags: "${{ env.CUE_VERSION }},latest"
1338-
repository: "cue-lang/cue"
1339-
username: "cueckoo"
1340-
password: "${{ secrets.CUECKOO_DOCKER_PAT }}"
1341-
tag_with_ref: false
1342-
tag_with_sha: false
1343-
target: "cue"
1344-
always_pull: true
1345-
build_args: "GOLANG_VERSION=${{ env.GOLANG_VERSION }},CUE_VERSION=v${{ env.CUE_VERSION }}"
1346-
add_git_labels: true
1347-
}
1348-
}]
1349-
}
1278+
jobs: goreleaser: {
1279+
"runs-on": _#linuxMachine
1280+
steps: [_#checkoutCode & {
1281+
with: "fetch-depth": 0
1282+
}, _#installGo & {
1283+
with: "go-version": _#latestStableGo
1284+
}, _#step & {
1285+
name: "Setup qemu"
1286+
uses: "docker/setup-qemu-action@v1"
1287+
}, _#step & {
1288+
name: "Set up Docker Buildx"
1289+
uses: "docker/setup-buildx-action@v1"
1290+
}, _#step & {
1291+
name: "Docker Login"
1292+
uses: "docker/login-action@v1"
1293+
with: {
1294+
registry: "docker.io"
1295+
username: "cueckoo"
1296+
password: "${{ secrets.CUECKOO_DOCKER_PAT }}"
1297+
}
1298+
}, _#step & {
1299+
name: "Run GoReleaser"
1300+
env: GITHUB_TOKEN: "${{ secrets.CUECKOO_GITHUB_PAT }}"
1301+
uses: "goreleaser/goreleaser-action@v2"
1302+
with: {
1303+
args: "release --rm-dist"
1304+
version: "v0.173.2"
1305+
}
1306+
}]
13501307
}
13511308
}
13521309
tip_triggers: _#bashWorkflow & {

cmd/cue/cmd/version.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,11 @@ func newVersionCmd(c *Command) *cobra.Command {
3232
return cmd
3333
}
3434

35-
const (
36-
defaultVersion = "devel"
37-
)
38-
39-
// set by goreleaser or other builder using
40-
// -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>'
41-
var (
42-
version = defaultVersion
43-
)
44-
4535
func runVersion(cmd *Command, args []string) error {
4636
w := cmd.OutOrStdout()
47-
if bi, ok := debug.ReadBuildInfo(); ok && version == defaultVersion {
48-
// No specific version provided via version
49-
version = bi.Main.Version
37+
var version = "devel"
38+
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Sum != "" {
39+
version = fmt.Sprintf("%s (%s)", bi.Main.Version, bi.Main.Sum)
5040
}
5141
fmt.Fprintf(w, "cue version %v %s/%s\n",
5242
version,

0 commit comments

Comments
 (0)