-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): refactor ci/cd to avoid code duplication (#353)
- Loading branch information
1 parent
88bf379
commit 5e2aafd
Showing
9 changed files
with
253 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
name: Build and Push | ||
|
||
on: | ||
workflow_call: | ||
|
||
env: | ||
REGISTRY_IMAGE: ghcr.io/${{ github.repository }} | ||
|
||
permissions: | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Prepare | ||
run: | | ||
platform=${{ matrix.platform }} | ||
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | ||
- name: Get Build timestamp and branch name | ||
run: | | ||
echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV | ||
echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV | ||
- name: Docker tags & labels | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY_IMAGE }} | ||
# generate Docker tags: | ||
# - type=raw,VERSION -> branch name | ||
# - type=ref,event=tag -> tag name | ||
# - type=sha,format=long,prefix= -> commit sha | ||
tags: | | ||
type=raw,${{ env.VERSION }} | ||
type=ref,event=tag | ||
type=sha,format=long,prefix= | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v6 | ||
with: | ||
platforms: ${{ matrix.platform }} | ||
build-args: | | ||
VERSION=${{ env.VERSION }} | ||
BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} | ||
COMMIT_HASH=${{ github.sha }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | ||
|
||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests-${{ env.PLATFORM_PAIR }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
merge: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-* | ||
merge-multiple: true | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Get branch name | ||
run: | | ||
echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV | ||
- name: Docker tags & labels | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY_IMAGE }} | ||
# generate Docker tags: | ||
# - type=raw,VERSION -> branch name | ||
# - type=ref,event=tag -> tag name | ||
# - type=sha,format=long,prefix= -> commit sha | ||
tags: | | ||
type=raw,${{ env.VERSION }} | ||
type=ref,event=tag | ||
type=sha,format=long,prefix= | ||
- name: Login to GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
packages: write | ||
id-token: write # Required for Codecov | ||
|
||
env: | ||
GO_VERSION: 1.22 | ||
|
||
jobs: | ||
unit-tests: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Cache envtest binaries | ||
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4 | ||
with: | ||
path: ./bin/ | ||
key: binaries | ||
- name: Setup Golang | ||
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 | ||
with: | ||
go-version: "${{ env.GO_VERSION }}" | ||
- name: Install envtest | ||
run: make envtest | ||
- name: Setup envtest | ||
run: ./bin/setup-envtest use | ||
- name: Run tests | ||
run: make test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4 | ||
with: | ||
use_oidc: true | ||
|
||
check-codegen: | ||
name: Check Codegen | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Golang | ||
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 | ||
with: | ||
go-version: "${{ env.GO_VERSION }}" | ||
- name: Generate manifests | ||
run: make manifests | ||
- name: Check nothing has changed | ||
run: | | ||
git diff --exit-code ./manifests | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 | ||
with: | ||
go-version: "${{ env.GO_VERSION }}" | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6 | ||
with: | ||
version: v1.55 | ||
args: --timeout=5m | ||
|
||
build-and-push: | ||
uses: ./.github/workflows/build-and-push.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.