build-test-publish #244
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
on: | |
pull_request: | |
branches: [main] | |
push: | |
branches: [main] | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
inputs: | |
debug_enabled: | |
type: boolean | |
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)" | |
required: false | |
default: false | |
name: build-test-publish | |
jobs: | |
go: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Set up Go | |
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | |
with: | |
go-version: "1.21" | |
- run: go env | |
- name: go build | |
run: go build -v ./... | |
- uses: alexellis/setup-arkade@v3 | |
- uses: alexellis/arkade-get@master | |
with: | |
golangci-lint: latest | |
- name: Lint Go Code | |
run: | | |
make lint-go | |
e2e: | |
name: e2e tests | |
runs-on: ubuntu-latest | |
needs: [go] | |
steps: | |
- uses: ko-build/[email protected] | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: azure/setup-helm@v4 | |
# instantiate a KinD (Kubernetes in Docker) cluster, installs `kubectl` and configures the | |
# `kubeconfig` to reach the local cluster | |
- uses: helm/[email protected] | |
with: | |
cluster_name: kind | |
wait: 120s | |
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | |
with: | |
go-version: "1.21.x" | |
- uses: openshift-pipelines/setup-tektoncd@v1 | |
with: | |
pipeline_version: v0.56.1 | |
feature_flags: '{"enable-step-actions": "true"}' | |
- name: Setup tmate session | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} | |
with: | |
limit-access-to-actor: true | |
detached: true | |
- name: tests | |
env: | |
OSP_PAC_GITHUB_TOKEN: ${{ secrets.OSP_PAC_GITHUB_TOKEN }} | |
OSP_PAC_USERNAME: os-pac | |
run: | | |
set -euxfo pipefail | |
REGISTRY=registry.registry.svc.cluster.local:32222 | |
KO_DOCKER_REPO=ghcr.io/openshift-pipelines/tekton-caches | |
IMAGE_REF="${KO_DOCKER_REPO}/cache:$(git rev-parse HEAD | tr -d '\n')" | |
echo "${OSP_PAC_GITHUB_TOKEN}" | ko login ghcr.io --username ${OSP_PAC_USERNAME} --password-stdin | |
kubectl -n registry get deployment | |
kubectl -n registry port-forward deployment/registry 5000:5000 & | |
make e2e | |
ko publish --sbom=none --base-import-paths --tags=$(git rev-parse HEAD) ./cmd/cache | |
sed "s%image:.*%image: ${IMAGE_REF}%g" tekton/cache-fetch.yaml | tee | kubectl apply -f - | |
sed "s%image:.*%image: ${IMAGE_REF}%g" tekton/cache-upload.yaml | tee | kubectl apply -f - | |
kubectl apply -f tests/ -f examples/ | |
tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app \ | |
-p gitRevision=main \ | |
-p cachePatterns="**.go,**go.sum" \ | |
-p cacheURIBase=oci://${REGISTRY}/cache/go \ | |
-w name=source,emptyDir= -w name=gocache,emptyDir= \ | |
-w name=gomodcache,emptyDir= --showlog | |
tkn task start cache-upload-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="**.go,**go.sum" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog | |
tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="**.go,**go.sum" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog | |
tkn task start cache-upload-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog | |
tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog | |
tkn taskrun list | |
kubectl get taskrun -o yaml | |
publish: | |
name: publish latest | |
runs-on: ubuntu-latest | |
needs: [go] | |
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow | |
permissions: write-all | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | |
with: | |
go-version: "1.21" | |
- id: meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # 5.5.1 | |
with: | |
images: ghcr.io/${{ github.repository }}/cache | |
flavor: | | |
latest=${{ github.event_name != 'pull_request' }} | |
- uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # 3.2.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ko-build/[email protected] | |
- run: | | |
ko publish --push=${{ github.event_name != 'pull_request' }} --base-import-paths ./cmd/cache --platform linux/arm64,linux/amd64 |