From fceb85eade320b9fc8f09b310daa668174c76913 Mon Sep 17 00:00:00 2001 From: Tao Li Date: Mon, 17 Aug 2026 19:07:33 +0800 Subject: [PATCH] ci(dept): refactor tast file Signed-off-by: Tao Li --- .github/workflows/ci.yml | 6 +- .github/workflows/release-please.yml | 4 +- .github/workflows/release-publish.yml | 6 +- Taskfile.yml | 827 ++++++++++++++------------ 4 files changed, 454 insertions(+), 389 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 576628a..da6c70c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh - name: Run CI task run: | - task ci + task all:ci publish: runs-on: ${{ vars.CI_RUNNERS || 'ubuntu-latest' }} @@ -76,7 +76,7 @@ jobs: curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh - name: Write manifest run: | - task manifest + task core:manifest - name: Publish images if: | github.event_name == 'workflow_dispatch' || @@ -85,7 +85,7 @@ jobs: REGISTRY_USER: ${{ github.actor }} REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} run: | - task publish + task core:publish - name: Attach manifest to workflow run uses: actions/upload-artifact@v7 with: diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 24f62d3..1de77b6 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -39,8 +39,8 @@ jobs: REGISTRY_USER: ${{ github.actor }} REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} run: | - task publish - task manifest + task core:publish + task core:manifest - name: Attach manifest to workflow run uses: actions/upload-artifact@v7 with: diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index ddae857..9366089 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -29,10 +29,10 @@ jobs: REGISTRY_USER: ${{ github.actor }} REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} run: | - task publish - task manifest + task core:publish + task core:manifest - name: Attach manifest to release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - task upload-manifest-to-release + task core:upload-manifest-to-release diff --git a/Taskfile.yml b/Taskfile.yml index 16859d5..ee7dc71 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -17,279 +17,136 @@ vars: DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine tasks: - lint: - desc: Run golangci-lint - env: - # renovate: datasource=git-refs depName=golangci-lint lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main - DAGGER_GOLANGCI_LINT_SHA: ff27cd50f6b4eed2e3753c520632cd6099e1ce52 - # renovate: datasource=docker depName=golangci/golangci-lint versioning=semver - GOLANGCI_LINT_VERSION: v2.12.2 - cmds: - - > - GITHUB_REF= dagger -sc "github.com/sagikazarmark/daggerverse/golangci-lint@${DAGGER_GOLANGCI_LINT_SHA} - --version ${GOLANGCI_LINT_VERSION} | - run . --config .golangci.yml | stdout" - sources: - - ./**/*.go - wordlist-ordered: - desc: Order the word list file - cmds: - - LANG=C LC_ALL=C sort .wordlist.txt > .wordlist.txt.new - - mv -f .wordlist.txt.new .wordlist.txt - sources: - - .wordlist.txt + #################################### + ## ALL + #################################### - spellcheck: - desc: Run spellcheck + all:ci: + desc: Run the CI pipeline deps: - - wordlist-ordered - env: - # renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_SPELLCHECK_SHA: 7174b66d283da487638a98b431b7707b311a9a32 - cmds: - - > - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA} - spellcheck --source . with-exec --use-entrypoint --args="" stdout - sources: - - ./**/*.md - - .spellcheck.yaml - - .wordlist.txt + - core:ci + - core:e2e-ephemeral - commitlint: - desc: Check for conventional commits - env: - # renovate: datasource=git-refs depName=commitlint lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_COMMITLINT_SHA: 7174b66d283da487638a98b431b7707b311a9a32 - cmds: - - > - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA} - lint --source . --args "--from=origin/main" stdout + #################################### + ## CORE + #################################### - uncommitted: - desc: Check for uncommitted changes + core:ci: + desc: Run the CI core pipeline deps: - - manifest-main - - apidoc - - wordlist-ordered - env: - # renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_UNCOMMITTED_SHA: 7174b66d283da487638a98b431b7707b311a9a32 - cmds: - - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA} check-uncommitted --source . stdout - sources: - - ./** + - internal:spellcheck + - internal:commitlint + - internal:uncommitted + - internal:lint + - internal:go-test + - internal:docusaurus-build-test + - internal:docusaurus-version-is-aligned - apidoc: - desc: Update the API Reference section of the documentation + # run the go linters + core:lint: + desc: Run the linters deps: - - controller-gen - env: - # renovate: datasource=git-refs depName=crd-gen-refs lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_CRDGENREF_SHA: 7174b66d283da487638a98b431b7707b311a9a32 - # renovate: datasource=go depName=github.com/elastic/crd-ref-docs - CRDREFDOCS_VERSION: v0.3.0 - cmds: - - > - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/crd-ref-docs@${DAGGER_CRDGENREF_SHA} - --version ${CRDREFDOCS_VERSION} - generate - --src . - --source-path api/v1 - --config-file hack/crd-gen-refs/config.yaml - --renderer markdown - --templates-dir hack/crd-gen-refs/markdown - file --path out.md - export --path web/docs/plugin-barman-cloud.v1.md - sources: - - ./api/**/*.go - - ./hack/docs/crd-gen-refs/**/* - - ./Taskfile.yml + - internal:lint - docusaurus-build-test: - desc: Check that the documentation builds + # run the spellcheck + core:spellcheck: + desc: Run the spellcheck deps: - - apidoc - env: - # renovate: datasource=git-refs depName=docusaurus lookupName=https://github.com/levlaz/daggerverse currentValue=main - DAGGER_DOCUSAURUS_SHA: 93f57fccbd5afd22fa917107ab7697f3e7db0e5a - cmds: - - GITHUB_REF= dagger -s call -m github.com/levlaz/daggerverse/docusaurus@${DAGGER_DOCUSAURUS_SHA} - --src web --yarn build - src: - - ./web/**/* + - internal:wordlist-ordered + - internal:spellcheck - docusaurus-version-is-aligned: - desc: Verify that a documentation version exists for the current version of the plugin - cmds: - - $(GITHUB_REF= dagger -s call -m dagger/check-doc-version has-version-documentation --src .) - src: - - .release-please-manifest.json - - ./web/versions.json - - go-test: - desc: Run go test - env: - # renovate: datasource=git-refs depname=kubernetes packageName=https://github.com/kubernetes/kubernetes versioning=semver - K8S_VERSION: 1.31.0 - # renovate: datasource=git-refs depName=controller-runtime packageName=https://github.com/kubernetes-sigs/controller-runtime versioning=semver - SETUP_ENVTEST_VERSION: 0.24.1 - cmds: - - > - GITHUB_REF= dagger -s call -m ./dagger/gotest - --go-version {{.GO_VERSION}} - --kube-version ${K8S_VERSION} - --setup-envtest-version ${SETUP_ENVTEST_VERSION} - unit-test --src . - stdout - sources: - - ./**/*.go - - generate-certs: - desc: Generate certificates for the local registry - run: once - cmds: - - > - mkdir -p certs && - docker volume create certs && - docker run -v certs:/certs -w /certs --name certs --entrypoint=/bin/sh alpine/openssl -c ' - openssl genrsa -out ca-key.pem 4096 && - openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \ - -subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" && - openssl genrsa -out server-key.pem 4096 && - openssl req -subj "/CN={{ .REGISTRY_NAME }}" -sha256 -new -key server-key.pem -out server.csr && - echo subjectAltName = DNS:{{ .REGISTRY_NAME }},IP:127.0.0.1 >> extfile.cnf && - echo extendedKeyUsage = serverAuth >> extfile.cnf && - openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \ - -CAcreateserial -out server-cert.pem -extfile extfile.cnf' - docker cp certs:/certs/ca.pem certs/ca.pem && - docker rm certs - status: - - docker volume inspect certs - - test -f certs/ca.pem - - start-build-network: - desc: Create a docker network for image building used by the dagger engine and the registry - run: once - cmds: - - docker network create {{ .REGISTRY_NETWORK}} - status: - - docker network inspect {{ .REGISTRY_NETWORK }} - - start-registry: - desc: Start a container registry - run: once + core:manifest: + desc: Generate the manifest to be uploaded to the release or as a workflow artifact deps: - - generate-certs - - start-build-network - env: - # renovate: datasource=docker depName=registry versioning=semver - REGISTRY_VERSION: 2 - cmds: - - > - docker run -d --name {{ .REGISTRY_NAME }} - -p {{ .REGISTRY_PORT }}:5000 - --network {{ .REGISTRY_NETWORK }} - -v certs:/certs - -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem - registry:${REGISTRY_VERSION} - status: - - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .REGISTRY_NAME }}" 2> /dev/null )" == 'true' \] - - - # Start a dagger engine that mounts the CA certificate for the local registry. - start-dagger-engine-for-local-builds: - desc: Start a dagger engine mounting the CA - run: once - deps: - - generate-certs - - start-build-network + - internal:controller-gen + requires: + # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here + # to prevent running this task locally by accident. + vars: + - CI + - GITHUB_REPOSITORY vars: - # renovate: datasource=github-tags depName=dagger/dagger versioning=semver - DAGGER_VERSION: 0.21.8 - DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }} + CURRENT_BRANCH: + sh: git rev-parse --abbrev-ref HEAD + GITHUB_REF: '{{.GITHUB_REF | default (printf "refs/heads/%s" .CURRENT_BRANCH)}}' + GITHUB_REF_NAME: '{{.GITHUB_REF_NAME | default .CURRENT_BRANCH}}' cmds: - - > - docker run -d -v /var/lib/dagger --name "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" - --network={{ .REGISTRY_NETWORK }} - -v certs:/usr/local/share/ca-certificates/ - --privileged {{ .DAGGER_ENGINE_IMAGE }} - status: - - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" 2> /dev/null )" == 'true' \] + - task: internal:manifest + vars: + GITHUB_REPOSITORY: '{{.GITHUB_REPOSITORY}}' + GITHUB_REF: '{{.GITHUB_REF}}' + GITHUB_REF_NAME: '{{.GITHUB_REF_NAME}}' - # We build an image and push it to a local registry. - # The name is always `plugin-barman-cloud:testing`. - build-plugin-image: - desc: Build the operator container image for the plugin - deps: - - start-registry - - start-dagger-engine-for-local-builds + core:publish: + desc: Publish the container images + requires: + # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here + # to prevent running this task locally by accident. + vars: + - CI + - GITHUB_REPOSITORY + - GITHUB_REF + - GITHUB_REF_NAME + - REGISTRY_USER + - REGISTRY_PASSWORD + vars: + CURRENT_BRANCH: + sh: git rev-parse --abbrev-ref HEAD + GITHUB_REF: '{{.GITHUB_REF | default (printf "refs/heads/%s" .CURRENT_BRANCH)}}' + GITHUB_REF_NAME: '{{.GITHUB_REF_NAME | default .CURRENT_BRANCH}}' + cmds: + - task: internal:publish + vars: + GITHUB_REPOSITORY: '{{.GITHUB_REPOSITORY}}' + GITHUB_REF: '{{.GITHUB_REF}}' + GITHUB_REF_NAME: '{{.GITHUB_REF_NAME}}' + REGISTRY_USER: '{{.REGISTRY_USER}}' + REGISTRY_PASSWORD: '{{.REGISTRY_PASSWORD}}' + + core:upload-manifest-to-release: + desc: Upload the manifest to the release + requires: + # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here + # to prevent running this task locally by accident. + vars: + - CI + - GITHUB_REPOSITORY + - GITHUB_REF + - GITHUB_REF_NAME + - GITHUB_TOKEN env: - # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main - DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 - _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} + # renovate: datasource=git-refs depName=gh lookupName=https://github.com/sagikazarmark/daggerverse + DAGGER_GH_SHA: ff27cd50f6b4eed2e3753c520632cd6099e1ce52 + preconditions: + - sh: "[[ {{.GITHUB_REF}} =~ 'refs/tags/v.*' ]]" + msg: not a tag, failing cmds: - - > - GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} - build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 - publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing + - > + GITHUB_REF= dagger -s call -m github.com/sagikazarmark/daggerverse/gh@${DAGGER_GH_SHA} + with-source --source . + run --repo {{.GITHUB_REPOSITORY}} --token env:GITHUB_TOKEN + --cmd "release upload {{.GITHUB_REF_NAME}} manifest.yaml" - # We build an image and push it to a local registry. - # The name is always `sidecar-barman-cloud:testing`. - build-sidecar-image: - desc: Build the sidecar container image for the plugin - deps: - - start-registry - - start-dagger-engine-for-local-builds - env: - # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main - DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 - _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} - cmds: - - > - GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} - build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 - publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing - - build-images: + core:build-images: desc: Build the container images for the plugin deps: - - build-plugin-image - - build-sidecar-image + - internal:build-plugin-image + - internal:build-sidecar-image - # Install kind if not at the expected version. - install-kind: - desc: Install kind - run: once - vars: - # renovate: datasource=git-refs depName=kind lookupName=https://github.com/kubernetes-sigs/kind versioning=semver - KIND_VERSION: v0.32.0 - cmds: - - go install sigs.k8s.io/kind@{{.KIND_VERSION}} - - kind version | grep -q {{.KIND_VERSION}} - status: - - kind version | grep -q {{.KIND_VERSION}} - - start-kind-cluster: - desc: Start a kind cluster + core:e2e-ephemeral: + desc: Run e2e tests in an ephemeral k3s cluster deps: - - install-kind - - start-build-network - - generate-certs - run: once + - core:build-images + env: + _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} cmds: - > - kind create cluster --name {{ .E2E_CLUSTER_NAME }} - --image kindest/node:{{ .E2E_KUBERNETES_VERSION }} - --config hack/kind-config.yaml - --wait 5m - - > - for node in $(kind get nodes --name {{ .E2E_CLUSTER_NAME }} ); do - docker network connect {{ .REGISTRY_NETWORK }} $node; - docker exec $node sh -c "update-ca-certificates"; - done - status: - - kind get clusters | grep -q {{ .E2E_CLUSTER_NAME }} + GITHUB_REF= dagger call -m dagger/e2e/ run-ephemeral + --source . + --ca certs/ca.pem + --registry {{.REGISTRY_NAME}}:{{.REGISTRY_PORT}} + --go-version {{.GO_VERSION}} # TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work. # TODO: add a task to clean up the kind cluster for new test runs. @@ -299,11 +156,11 @@ tasks: # * The registry to be in the same network of the dagger-engine. # * The dagger-engine to mount the CA. # * The kind cluster to mount the CA. - e2e-external-kind: + core:e2e-external-kind: desc: Run e2e tests in a local kind cluster deps: - - build-images - - start-kind-cluster + - core:build-images + - internal:start-kind-cluster vars: KUBECONFIG_PATH: sh: mktemp -t kubeconfig-XXXXX @@ -317,128 +174,98 @@ tasks: --kubeconfig {{.KUBECONFIG_PATH}} --go-version {{.GO_VERSION}} - e2e-ephemeral: - desc: Run e2e tests in an ephemeral k3s cluster - deps: - - build-images + #################################### + ## INTERNAL + #################################### + + internal:lint: + desc: Run golangci-lint env: - _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} + # renovate: datasource=git-refs depName=golangci-lint lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main + DAGGER_GOLANGCI_LINT_SHA: ff27cd50f6b4eed2e3753c520632cd6099e1ce52 + # renovate: datasource=docker depName=golangci/golangci-lint versioning=docker + GOLANGCI_LINT_VERSION: v2.12.2@sha256:5cceeef04e53efe1470638d4b4b4f5ceefd574955ab3941b2d9a68a8c9ad5240 + internal: true cmds: - > - GITHUB_REF= dagger call -m dagger/e2e/ run-ephemeral - --source . - --ca certs/ca.pem - --registry {{.REGISTRY_NAME}}:{{.REGISTRY_PORT}} - --go-version {{.GO_VERSION}} - - ci: - desc: Run the CI pipeline - deps: - - spellcheck - - commitlint - - uncommitted - - lint - - go-test - - e2e-ephemeral - - docusaurus-build-test - - docusaurus-version-is-aligned - - publish: - desc: Build and publish a container image for the plugin - requires: - # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here - # to prevent running this task locally by accident. - vars: - - CI - - GITHUB_REPOSITORY - - GITHUB_REF - - GITHUB_REF_NAME - - REGISTRY_USER - - REGISTRY_PASSWORD - vars: - PLUGIN_IMAGE_NAME: ghcr.io/{{.GITHUB_REPOSITORY}}{{if not (hasPrefix "refs/tags/v" .GITHUB_REF)}}-testing{{end}} - SIDECAR_IMAGE_NAME: ghcr.io/{{.GITHUB_REPOSITORY}}-sidecar{{if not (hasPrefix "refs/tags/v" .GITHUB_REF)}}-testing{{end}} - # remove /merge suffix from the branch name. This is a workaround for the GitHub workflow on PRs, - # where the branch name is suffixed with /merge. Prepend pr- to the branch name on PRs. - # Any remaining "/" (e.g. from namespaced branches like "dev/foo") is replaced with "-" since - # "/" is not a valid character in a Docker tag. - IMAGE_VERSION: '{{replace "/" "-" (regexReplaceAll "(\\d+)/merge" .GITHUB_REF_NAME "pr-${1}")}}' - env: - # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main - DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 - cmds: - - > - GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} - --registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD - build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64 - publish --ref {{.PLUGIN_IMAGE_NAME}} --tags {{.IMAGE_VERSION}} - - > - GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} - --registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD - build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64 - publish --ref {{.SIDECAR_IMAGE_NAME}} --tags {{.IMAGE_VERSION}} - - controller-gen: - desc: Run controller-gen - run: once - env: - # renovate: datasource=git-refs depName=controller-gen lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_CONTROLLER_GEN_SHA: 7174b66d283da487638a98b431b7707b311a9a32 - cmds: - - > - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA} - controller-gen --source . --args object:headerFile=hack/boilerplate.go.txt --args paths=./api/... - file --path api/v1/zz_generated.deepcopy.go export --path api/v1/zz_generated.deepcopy.go - - > - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA} - controller-gen --source . --args rbac:roleName=plugin-barman-cloud --args crd --args webhook - --args paths=./api/... --args paths=./internal/... --args output:crd:artifacts:config=config/crd/bases - directory --path config/ - filter --include crd/bases/,rbac/ - export --path config/ + GITHUB_REF= dagger -sc "github.com/sagikazarmark/daggerverse/golangci-lint@${DAGGER_GOLANGCI_LINT_SHA} + --version ${GOLANGCI_LINT_VERSION} | + run . --config .golangci.yml | stdout" sources: - - ./api/**/*.go - - ./internal/**/*.go - generates: - - ./api/v1/zz_generated.deepcopy.go - - ./config/rbac/role.yaml - - ./config/crd/bases/*.yaml + - ./**/*.go - manifest-main: - deps: - - controller-gen - desc: Generate the manifest for the main branch - vars: - GITHUB_REPOSITORY: cloudnative-pg/plugin-barman-cloud - GITHUB_REF: main - GITHUB_REF_NAME: main + internal:wordlist-ordered: + desc: Order the word list file + internal: true cmds: - - task: manifest-internal - vars: - GITHUB_REPOSITORY: '{{.GITHUB_REPOSITORY}}' - GITHUB_REF: '{{.GITHUB_REF}}' - GITHUB_REF_NAME: '{{.GITHUB_REF_NAME}}' + - LANG=C LC_ALL=C sort .wordlist.txt > .wordlist.txt.new + - mv -f .wordlist.txt.new .wordlist.txt + sources: + - .wordlist.txt - manifest: - desc: Generate the manifest to be uploaded to the release or as a workflow artifact + internal:spellcheck: + desc: Run spellcheck deps: - - controller-gen - requires: - # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here - # to prevent running this task locally by accident. - vars: - - CI - - GITHUB_REPOSITORY - - GITHUB_REF - - GITHUB_REF_NAME + - internal:wordlist-ordered + env: + # renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main + DAGGER_SPELLCHECK_SHA: 7174b66d283da487638a98b431b7707b311a9a32 + internal: true cmds: - - task: manifest-internal - vars: - GITHUB_REPOSITORY: '{{.GITHUB_REPOSITORY}}' - GITHUB_REF: '{{.GITHUB_REF}}' - GITHUB_REF_NAME: '{{.GITHUB_REF_NAME}}' + - > + GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA} + spellcheck --source . with-exec --use-entrypoint --args="" stdout + sources: + - ./**/*.md + - .spellcheck.yaml + - .wordlist.txt - manifest-internal: + internal:commitlint: + desc: Check for conventional commits + env: + # renovate: datasource=git-refs depName=commitlint lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main + DAGGER_COMMITLINT_SHA: 7174b66d283da487638a98b431b7707b311a9a32 + internal: true + cmds: + - > + GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA} + lint --source . --args "--from=origin/main" stdout + + internal:uncommitted: + desc: Check for uncommitted changes + deps: + - internal:manifest + - documentation:apidoc + - internal:wordlist-ordered + env: + # renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main + DAGGER_UNCOMMITTED_SHA: 7174b66d283da487638a98b431b7707b311a9a32 + internal: true + cmds: + - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA} check-uncommitted --source . stdout + sources: + - ./** + + internal:go-test: + desc: Run go test + env: + # renovate: datasource=git-refs depname=kubernetes packageName=https://github.com/kubernetes/kubernetes versioning=semver + K8S_VERSION: 1.31.0 + # renovate: datasource=git-refs depName=controller-runtime packageName=https://github.com/kubernetes-sigs/controller-runtime versioning=semver + SETUP_ENVTEST_VERSION: 0.24.1 + internal: true + cmds: + - > + GITHUB_REF= dagger -s call -m ./dagger/gotest + --go-version {{.GO_VERSION}} + --kube-version ${K8S_VERSION} + --setup-envtest-version ${SETUP_ENVTEST_VERSION} + unit-test --src . + stdout + sources: + - ./**/*.go + + internal:manifest: desc: Update the image in the Kustomization label: manifest-internal-{{.GITHUB_REF_NAME}} internal: true @@ -474,31 +301,269 @@ tasks: generates: - ./manifest.yaml - upload-manifest-to-release: - desc: Upload the manifest to the release + internal:generate-certs: + desc: Generate certificates for the local registry + internal: true + run: once + cmds: + - > + mkdir -p certs && + docker volume create certs && + docker run -v certs:/certs -w /certs --name certs --entrypoint=/bin/sh alpine/openssl -c ' + openssl genrsa -out ca-key.pem 4096 && + openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \ + -subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" && + openssl genrsa -out server-key.pem 4096 && + openssl req -subj "/CN={{ .REGISTRY_NAME }}" -sha256 -new -key server-key.pem -out server.csr && + echo subjectAltName = DNS:{{ .REGISTRY_NAME }},IP:127.0.0.1 >> extfile.cnf && + echo extendedKeyUsage = serverAuth >> extfile.cnf && + openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \ + -CAcreateserial -out server-cert.pem -extfile extfile.cnf' + docker cp certs:/certs/ca.pem certs/ca.pem && + docker rm certs + status: + - docker volume inspect certs + - test -f certs/ca.pem + + internal:controller-gen: + desc: Run controller-gen + run: once + env: + # renovate: datasource=git-refs depName=controller-gen lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main + DAGGER_CONTROLLER_GEN_SHA: 7174b66d283da487638a98b431b7707b311a9a32 + internal: true + cmds: + - > + GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA} + controller-gen --source . --args object:headerFile=hack/boilerplate.go.txt --args paths=./api/... + file --path api/v1/zz_generated.deepcopy.go export --path api/v1/zz_generated.deepcopy.go + - > + GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA} + controller-gen --source . --args rbac:roleName=plugin-barman-cloud --args crd --args webhook + --args paths=./api/... --args paths=./internal/... --args output:crd:artifacts:config=config/crd/bases + directory --path config/ + filter --include crd/bases/,rbac/ + export --path config/ + sources: + - ./api/**/*.go + - ./internal/**/*.go + generates: + - ./api/v1/zz_generated.deepcopy.go + - ./config/rbac/role.yaml + - ./config/crd/bases/*.yaml + + internal:publish: + desc: Build and publish a container image for the plugin requires: - # We expect this to run in a GitHub workflow, so we put a few GitHub-specific vars here - # to prevent running this task locally by accident. vars: - - CI - GITHUB_REPOSITORY - GITHUB_REF - GITHUB_REF_NAME - - GITHUB_TOKEN + - REGISTRY_USER + - REGISTRY_PASSWORD + vars: + PLUGIN_IMAGE_NAME: ghcr.io/{{.GITHUB_REPOSITORY}}{{if not (hasPrefix "refs/tags/v" .GITHUB_REF)}}-testing{{end}} + SIDECAR_IMAGE_NAME: ghcr.io/{{.GITHUB_REPOSITORY}}-sidecar{{if not (hasPrefix "refs/tags/v" .GITHUB_REF)}}-testing{{end}} + # remove /merge suffix from the branch name. This is a workaround for the GitHub workflow on PRs, + # where the branch name is suffixed with /merge. Prepend pr- to the branch name on PRs. + # Any remaining "/" (e.g. from namespaced branches like "dev/foo") is replaced with "-" since + # "/" is not a valid character in a Docker tag. + IMAGE_VERSION: '{{replace "/" "-" (regexReplaceAll "(\\d+)/merge" .GITHUB_REF_NAME "pr-${1}")}}' env: - # renovate: datasource=git-refs depName=gh lookupName=https://github.com/sagikazarmark/daggerverse - DAGGER_GH_SHA: ff27cd50f6b4eed2e3753c520632cd6099e1ce52 - preconditions: - - sh: "[[ {{.GITHUB_REF}} =~ 'refs/tags/v.*' ]]" - msg: not a tag, failing + # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main + DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 + internal: true cmds: - - > - GITHUB_REF= dagger -s call -m github.com/sagikazarmark/daggerverse/gh@${DAGGER_GH_SHA} - with-source --source . - run --repo {{.GITHUB_REPOSITORY}} --token env:GITHUB_TOKEN - --cmd "release upload {{.GITHUB_REF_NAME}} manifest.yaml" + - > + GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} + --registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD + build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64 + publish --ref {{.PLUGIN_IMAGE_NAME}} --tags {{.IMAGE_VERSION}} + - > + GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} + --registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD + build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64 + publish --ref {{.SIDECAR_IMAGE_NAME}} --tags {{.IMAGE_VERSION}} - clean: + # We build an image and push it to a local registry. + # The name is always `plugin-barman-cloud:testing`. + internal:build-plugin-image: + desc: Build the operator container image for the plugin + deps: + - internal:start-registry + - internal:start-dagger-engine-for-local-builds + env: + # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main + DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 + _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} + internal: true + cmds: + - > + GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} + build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 + publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing + + # We build an image and push it to a local registry. + # The name is always `sidecar-barman-cloud:testing`. + internal:build-sidecar-image: + desc: Build the sidecar container image for the plugin + internal: true + deps: + - internal:start-registry + - internal:start-dagger-engine-for-local-builds + env: + # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main + DAGGER_DOCKER_SHA: ee12c1a4a2630e194ec20c5a9959183e3a78c192 + _EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }} + cmds: + - > + GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} + build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 + publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing + + internal:start-registry: + desc: Start a container registry + run: once + internal: true + deps: + - internal:generate-certs + - internal:start-build-network + env: + # renovate: datasource=docker depName=registry versioning=semver + REGISTRY_VERSION: 2 + cmds: + - > + docker run -d --name {{ .REGISTRY_NAME }} + -p {{ .REGISTRY_PORT }}:5000 + --network {{ .REGISTRY_NETWORK }} + -v certs:/certs + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem + registry:${REGISTRY_VERSION} + status: + - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .REGISTRY_NAME }}" 2> /dev/null )" == 'true' \] + + # Start a dagger engine that mounts the CA certificate for the local registry. + internal:start-dagger-engine-for-local-builds: + desc: Start a dagger engine mounting the CA + run: once + deps: + - internal:generate-certs + - internal:start-build-network + vars: + # renovate: datasource=github-tags depName=dagger/dagger versioning=semver + DAGGER_VERSION: 0.21.8 + DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }} + internal: true + cmds: + - > + docker run -d -v /var/lib/dagger --name "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" + --network={{ .REGISTRY_NETWORK }} + -v certs:/usr/local/share/ca-certificates/ + --privileged {{ .DAGGER_ENGINE_IMAGE }} + status: + - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" 2> /dev/null )" == 'true' \] + + internal:start-build-network: + desc: Create a docker network for image building used by the dagger engine and the registry + run: once + internal: true + cmds: + - docker network create {{ .REGISTRY_NETWORK}} + status: + - docker network inspect {{ .REGISTRY_NETWORK }} + + # Install kind if not at the expected version. + internal:install-kind: + desc: Install kind + run: once + vars: + # renovate: datasource=git-refs depName=kind lookupName=https://github.com/kubernetes-sigs/kind versioning=semver + KIND_VERSION: v0.32.0 + cmds: + - go install sigs.k8s.io/kind@{{.KIND_VERSION}} + - kind version | grep -q {{.KIND_VERSION}} + status: + - kind version | grep -q {{.KIND_VERSION}} + + internal:start-kind-cluster: + desc: Start a kind cluster + deps: + - internal:install-kind + - internal:start-build-network + - internal:generate-certs + run: once + cmds: + - > + kind create cluster --name {{ .E2E_CLUSTER_NAME }} + --image kindest/node:{{ .E2E_KUBERNETES_VERSION }} + --config hack/kind-config.yaml + --wait 5m + - > + for node in $(kind get nodes --name {{ .E2E_CLUSTER_NAME }} ); do + docker network connect {{ .REGISTRY_NETWORK }} $node; + docker exec $node sh -c "update-ca-certificates"; + done + status: + - kind get clusters | grep -q {{ .E2E_CLUSTER_NAME }} + + internal:clean: desc: Remove autogenerated artifacts + internal: true cmds: - rm -rf .task/ + + #################################### + ## DOCUMENTATION + #################################### + + documentation:apidoc: + desc: Update the API Reference section of the documentation + deps: + - internal:controller-gen + env: + # renovate: datasource=git-refs depName=crd-gen-refs lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main + DAGGER_CRDGENREF_SHA: 7174b66d283da487638a98b431b7707b311a9a32 + # renovate: datasource=go depName=github.com/elastic/crd-ref-docs + CRDREFDOCS_VERSION: v0.3.0 + cmds: + - > + GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/crd-ref-docs@${DAGGER_CRDGENREF_SHA} + --version ${CRDREFDOCS_VERSION} + generate + --src . + --source-path api/v1 + --config-file hack/crd-gen-refs/config.yaml + --renderer markdown + --templates-dir hack/crd-gen-refs/markdown + file --path out.md + export --path web/docs/plugin-barman-cloud.v1.md + sources: + - ./api/**/*.go + - ./hack/docs/crd-gen-refs/**/* + - ./Taskfile.yml + + documentation:docusaurus-build-test: + desc: Check that the documentation builds + deps: + - documentation:apidoc + env: + # renovate: datasource=git-refs depName=docusaurus lookupName=https://github.com/levlaz/daggerverse currentValue=main + DAGGER_DOCUSAURUS_SHA: 93f57fccbd5afd22fa917107ab7697f3e7db0e5a + cmds: + - GITHUB_REF= dagger -s call -m github.com/levlaz/daggerverse/docusaurus@${DAGGER_DOCUSAURUS_SHA} + --src web --yarn build + sources: + - ./web/**/* + + documentation:docusaurus-version-is-aligned: + desc: Verify that a documentation version exists for the current version of the plugin + cmds: + - $(GITHUB_REF= dagger -s call -m dagger/check-doc-version has-version-documentation --src .) + sources: + - .release-please-manifest.json + - ./web/versions.json + + + + +