Skip to content

Commit 235473c

Browse files
authored
CI: Travis -> GitHub Actions; Create Release Binaries and Container Images (#444)
[![Checks](https://github.com/fastly/pebble/actions/workflows/checks.yml/badge.svg)](https://github.com/fastly/pebble/actions/workflows/checks.yml) [![Tests](https://github.com/fastly/pebble/actions/workflows/tests.yml/badge.svg)](https://github.com/fastly/pebble/actions/workflows/tests.yml) As a follow-on to #439 this change request implements the first step of building a new CI system for Pebble. As this is a testbed environment for Boulder, some of these changes may prove to be useful in the latter context. Per #434 (comment), GitHub Actions is a reasonable choice for a new CI implementation to supersede Travis. Much, but not all, of the existing functionality is present in this initial set of changes. Items currently implemented include: - Binary production of `pebble` and `challtestsrv` for platforms: - AMD64 - darwin - linux - windows - ARM64 - darwin - linux - windows - Multiplatform docker images published on the GitHub Container Registry for platforms: - linux/amd64 - linux/arm64 - windows/amd64 - Golang linting. - Golang coverage. - Local test scripts for Go and Docker: - `./build.sh` - `./docker.sh` - `./test.sh` This PR also adds a `-version` flag to Pebble, which is set during release build to the Git commit ref. This change builds on earlier work done in #379 and #442.
1 parent c449dc1 commit 235473c

File tree

17 files changed

+307
-320
lines changed

17 files changed

+307
-320
lines changed

.ci/publish_linux.sh

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

.ci/publish_windows.ps1

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

.dockerignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
.git
2-
pebble.exe
3-
pebble
1+
/pebble
2+
/pebble.exe

.github/workflows/checks.yml

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,48 @@
11
name: Checks
2-
2+
# Run on push to main and any pull request.
33
on:
44
push:
55
branches:
66
- main
77
pull_request:
8-
98
permissions:
9+
checks: write # Allow write access to checks to allow annotation of code in the PR.
1010
contents: read
1111
pull-requests: read
12-
12+
env:
13+
CGO_ENABLED: 0
14+
GO_VERSION: stable
15+
GOLANGCI_LINT_VERSION: v1.56.2
16+
SHELLCHECK_SCRIPTS: ./*.sh
1317
jobs:
14-
15-
checks:
16-
name: Check Process
18+
go-lint-checks:
1719
runs-on: ubuntu-latest
18-
env:
19-
GO_VERSION: oldstable
20-
GOLANGCI_LINT_VERSION: v1.56.2
21-
CGO_ENABLED: 0
22-
2320
steps:
24-
25-
- name: Check out code
26-
uses: actions/checkout@v4
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-go@v5
2723
with:
28-
fetch-depth: 0
29-
30-
- name: Set up Go
31-
uses: actions/setup-go@v5
24+
go-version: ${{ env.GO_VERSION }}
25+
- name: Run GolangCI-Lint
26+
uses: golangci/golangci-lint-action@v4
27+
with:
28+
# skip cache because of flaky behaviors
29+
skip-build-cache: true
30+
skip-pkg-cache: true
31+
version: ${{ env.GOLANGCI_LINT_VERSION }}
32+
go-mod-checks:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
3237
with:
3338
go-version: ${{ env.GO_VERSION }}
34-
35-
- name: Check and get dependencies
39+
- name: Check if go.mod is tidy
3640
run: |
3741
go mod tidy
38-
git diff --exit-code go.mod
39-
git diff --exit-code go.sum
40-
41-
- name: vendoring
42-
run: go mod vendor
43-
44-
- name: vendoring diff
45-
run: git diff --exit-code vendor/
46-
47-
# https://golangci-lint.run/usage/install#other-ci
48-
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
42+
git diff --exit-code go.mod go.sum ||
43+
(echo "::error::go.mod and go.sum need to be tidy" && exit 1)
44+
- name: Check if vendor directory is up to date
4945
run: |
50-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
51-
golangci-lint run
52-
53-
46+
go mod vendor
47+
git diff --exit-code vendor ||
48+
(echo "::error::vendor directory needs to be updated" && exit 1)

.github/workflows/go-cross.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1-
name: Go Matrix
1+
name: Go Build Matrix
22
on:
33
push:
44
branches:
55
- main
66
pull_request:
7-
87
permissions:
98
contents: read
109
pull-requests: read
11-
1210
jobs:
13-
1411
cross:
15-
name: Build
12+
name: Build on ${{ matrix.os }} with Go ${{ matrix.go-version }}
1613
runs-on: ${{ matrix.os }}
1714
env:
1815
CGO_ENABLED: 0
19-
2016
strategy:
2117
matrix:
22-
go-version: [ oldstable, stable ]
23-
os: [ubuntu-latest, macos-latest, windows-latest]
24-
18+
go-version:
19+
- oldstable
20+
- stable
21+
os:
22+
- ubuntu-latest
23+
- macos-14 # M1 runners
24+
- macos-latest
25+
- windows-latest
2526
steps:
2627
- name: Checkout code
2728
uses: actions/checkout@v4
28-
2929
- name: Set up Go
3030
uses: actions/setup-go@v5
3131
with:
3232
go-version: ${{ matrix.go-version }}
33-
34-
- name: Build pebble
35-
run: go build -v -ldflags "-s -w" -trimpath -o pebble ./cmd/pebble
36-
37-
- name: Build pebble-challtestsrv
38-
run: go build -v -ldflags "-s -w" -trimpath -o pebble-challtestsrv ./cmd/pebble-challtestsrv
33+
- name: Build the module
34+
run: go build -v ./...

.github/workflows/release.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: Build Release
2+
# Run on semver tags.
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+"
7+
permissions:
8+
contents: read
9+
packages: write # Allow docker/build-push-action to publish to GitHub Container Registry
10+
env:
11+
DOCKER_PLATFORMS: linux/amd64, linux/arm64, windows/amd64
12+
DOCKER_IMAGE_BASENAME: ghcr.io/${{ github.repository_owner }}
13+
jobs:
14+
go-build:
15+
env:
16+
CGO_ENABLED: 0
17+
GOARCH: ${{ matrix.go-arch }}
18+
GOOS: ${{ matrix.go-os }}
19+
LDFLAGS: -s -w -X 'main.version=${{ github.ref_name }} (${{ github.sha }})'
20+
OUTPUTDIR: /tmp/dist/${{ matrix.go-os }}/${{ matrix.go-arch }}
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
app:
25+
- pebble
26+
- pebble-challtestsrv
27+
go-arch:
28+
- amd64
29+
- arm64
30+
go-os:
31+
- darwin
32+
- linux
33+
- windows
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
37+
with:
38+
check-latest: true
39+
go-version-file: go.mod
40+
- name: Build ${{ matrix.app }} for ${{ matrix.go-os }}/${{ matrix.go-arch }}
41+
run: |
42+
go build \
43+
-ldflags="${LDFLAGS}" \
44+
-o "${OUTPUTDIR}/" \
45+
-trimpath \
46+
-v \
47+
./cmd/${{ matrix.app }}
48+
- name: Display ${{ matrix.app }} artifacts
49+
run: tree /tmp/dist
50+
- name: Store ${{ matrix.app }} artifacts
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: ${{ matrix.app }}-${{ matrix.go-os }}-${{ matrix.go-arch }}
54+
path: /tmp/dist
55+
docker-build:
56+
needs:
57+
- go-build
58+
runs-on: ubuntu-latest
59+
strategy:
60+
matrix:
61+
app:
62+
- pebble
63+
- pebble-challtestsrv
64+
steps:
65+
- uses: actions/checkout@v4
66+
- name: Download ${{ matrix.app }} artifacts
67+
uses: actions/download-artifact@v4
68+
with:
69+
merge-multiple: true
70+
path: /tmp/dist
71+
pattern: ${{ matrix.app }}-*-*
72+
- name: Display ${{ matrix.app }} artifacts
73+
run: tree /tmp/dist
74+
- name: Docker meta
75+
id: meta
76+
uses: docker/metadata-action@v5
77+
with:
78+
images: ${{ env.DOCKER_IMAGE_BASENAME }}/${{ matrix.app }}
79+
# generate Docker tags based on the following events/attributes
80+
tags: |
81+
type=semver,pattern={{major}}
82+
type=semver,pattern={{major}}.{{minor}}
83+
type=semver,pattern={{version}}
84+
type=sha
85+
type=raw,value=latest
86+
- name: Set up QEMU
87+
uses: docker/setup-qemu-action@v3
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v3
90+
- name: Login to GitHub Container Registry
91+
uses: docker/login-action@v3
92+
with:
93+
registry: ghcr.io
94+
username: ${{ github.actor }}
95+
password: ${{ secrets.GITHUB_TOKEN }}
96+
- name: Build and push ${{ github.repository }}/${{ matrix.app }} for ${{ env.DOCKER_PLATFORMS }}
97+
uses: docker/build-push-action@v5
98+
with:
99+
build-args: APP=${{ matrix.app }}
100+
build-contexts: dist-files=/tmp/dist
101+
cache-from: type=gha
102+
cache-to: type=gha,mode=max
103+
file: Dockerfile.release
104+
labels: ${{ steps.meta.outputs.labels }}
105+
platforms: ${{ env.DOCKER_PLATFORMS }}
106+
push: true
107+
tags: ${{ steps.meta.outputs.tags }}
108+
docker-version:
109+
needs:
110+
- docker-build
111+
runs-on: ${{ matrix.docker-os }}
112+
strategy:
113+
matrix:
114+
docker-os:
115+
- ubuntu-latest
116+
- windows-latest
117+
steps:
118+
- name: Login to GitHub Container Registry
119+
uses: docker/login-action@v3
120+
with:
121+
registry: ghcr.io
122+
username: ${{ github.actor }}
123+
password: ${{ secrets.GITHUB_TOKEN }}
124+
- name: Display pebble version in container image
125+
run: docker run ${{ env.DOCKER_IMAGE_BASENAME }}/pebble:latest -version
126+
create-release:
127+
needs:
128+
- go-build
129+
permissions:
130+
contents: write # Allow creation of a release
131+
runs-on: ubuntu-latest
132+
steps:
133+
- name: Download build artifacts
134+
uses: actions/download-artifact@v4
135+
- name: Display build artifacts
136+
run: tree .
137+
- name: Create release
138+
# https://cli.github.com/manual/gh_release_create
139+
env:
140+
GITHUB_TOKEN: ${{ github.token }}
141+
run: |
142+
gh release create ${{ github.ref_name }} \
143+
--repo ${{ github.repository }} \
144+
--title "${{ github.ref_name }}" \
145+
--verify-tag
146+
continue-on-error: true
147+
- name: Upload release files
148+
# https://cli.github.com/manual/gh_release_upload
149+
env:
150+
GITHUB_TOKEN: ${{ github.token }}
151+
run: |
152+
for artifact in *; do
153+
tar czf ${artifact}.tar.gz ${artifact}
154+
zip -r ${artifact}.zip ${artifact}
155+
gh release upload ${{ github.ref_name }} ${artifact}.* \
156+
--repo ${{ github.repository }};
157+
done

0 commit comments

Comments
 (0)