From ece83721e6828f0d3d5654dc0ca0d41ce2ec72ae Mon Sep 17 00:00:00 2001 From: Pramod Bindal Date: Thu, 16 Jan 2025 22:24:29 +0530 Subject: [PATCH] Add Release workflows Signed-off-by: Pramod Bindal Add Release workflows Add Release workflows Signed-off-by: Pramod Bindal Signed-off-by: Pramod Bindal change stepAction version to tekton.dev/v1beta1 Signed-off-by: Pramod Bindal --- .github/workflows/release.yaml | 27 +++++++++++ Makefile | 45 ++++++++++++++++++ hack/release.sh | 85 ++++++++++++++++++++++++++++++++++ tekton/cache-fetch.yaml | 2 +- tekton/cache-upload.yaml | 2 +- 5 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100755 hack/release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..a999088a4 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,27 @@ +--- +name: release + +on: + workflow_dispatch: + inputs: + version: + description: 'Define the version you want to release' + required: true + default: '0.0.1' + +jobs: + release: + permissions: + contents: write + packages: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: github-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + make RELEASE_VERSION=v${{github.event.inputs.version}} github-release \ No newline at end of file diff --git a/Makefile b/Makefile index c0c92214e..821294a99 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,24 @@ +SHELL := /usr/bin/env bash E2E_TAG ?= e2e + REGISTRY_NAME ?= registry GOLANGCI_LINT=golangci-lint TIMEOUT_UNIT = 20m GOFUMPT=gofumpt +BIN = $(CURDIR)/.bin +# release directory where the Tekton resources are rendered into. +RELEASE_VERSION=v0.1.1 +RELEASE_DIR ?= /tmp/tekton-caches-${RELEASE_VERSION} +$(BIN): + @mkdir -p $@ +CATALOGCD = $(or ${CATALOGCD_BIN},${CATALOGCD_BIN},$(BIN)/catalog-cd) +$(BIN)/catalog-cd: $(BIN) + curl -fsL https://github.com/openshift-pipelines/catalog-cd/releases/download/v0.3.0/catalog-cd_0.3.0_linux_x86_64.tar.gz | tar xzf - -C $(BIN) catalog-cd + + + e2e-coverage: ## run e2e tests with coverage tests/e2e.sh @go test -v -failfast -count=1 -tags=$(E2E_TAG) ./tests -coverpkg=./... -coverprofile /tmp/coverage.out @@ -42,3 +56,34 @@ fumpt: help: ## print this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) +#Release +# pepare a release +.PHONY: prepare-release +prepare-release: + mkdir -p $(RELEASE_DIR) || true + hack/release.sh $(RELEASE_DIR) + + +.PHONY: release +release: ${CATALOGCD} prepare-release + pushd ${RELEASE_DIR} && \ + $(CATALOGCD) release \ + --output release \ + --version $(RELEASE_VERSION) \ + stepactions/* \ + ; \ + popd + +# tags the repository with the RELEASE_VERSION and pushes to "origin" +git-tag-release-version: + if ! git rev-list "${RELEASE_VERSION}".. >/dev/null; then \ + git tag "$(RELEASE_VERSION)" && \ + git push origin --tags; \ + fi + +# github-release +.PHONY: github-release +github-release: git-tag-release-version release + gh release create $(RELEASE_VERSION) --generate-notes && \ + gh release upload $(RELEASE_VERSION) $(RELEASE_DIR)/release/catalog.yaml && \ + gh release upload $(RELEASE_VERSION) $(RELEASE_DIR)/release/resources.tar.gz \ No newline at end of file diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 000000000..4f50ef022 --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# +# Renders and copies documentation files into the informed RELEASE_DIR, the script search for +# task templates on a specific glob expression. The templates are rendered using the actual +# task name and documentation is searched for and copied over to the task release directory. +# + +shopt -s inherit_errexit +set -eu -o pipefail + +readonly RELEASE_DIR="${1:-}" + +# Print error message and exit non-successfully. +panic() { + echo "# ERROR: ${*}" + exit 1 +} + +# Extracts the filename only, without path or extension. +extract_name() { + declare filename=$(basename -- "${1}") + declare extension="${filename##*.}" + echo "${filename%.*}" +} + +# Function to find the respective documentation for a given name, however, for s2i it only consider the +## "task-s2i" part instead of the whole name. +find_doc() { + declare name="${1}" + [[ "${name}" == "task-s2i"* ]] && + name="task-s2i" + find docs/ -name "${name}*.md" +} + +# +# Main +# + +release() { + # making sure the release directory exists, this script should only create releative + # directories using it as root + [[ ! -d "${RELEASE_DIR}" ]] && + panic "Release dir is not found '${RELEASE_DIR}'!" + + # Release task templates +# release_templates "task" "templates/task-*.yaml" "tasks" + + # Release StepAction templates + release_templates "stepaction" "tekton/*.yaml" "stepactions" +} + +release_templates() { + local template_type=$1 + local glob_expression=$2 + local release_subdir=$3 + + # releasing all templates using the following glob expression + for t in $(ls -1 ${glob_expression}); do + declare name=$(extract_name ${t}) + [[ -z "${name}" ]] && + panic "Unable to extract name from '${t}'!" + +# local doc=$(find_doc ${name}) +# [[ -z "${doc}" ]] && +# panic "Unable to find documentation file for '${name}'!" + + local dir="${RELEASE_DIR}/${release_subdir}/${name}" + [[ ! -d "${dir}" ]] && + mkdir -p "${dir}" + + # rendering the helm template for the specific file, using the resource name for the + # filename respectively + echo "# Rendering '${name}' at '${dir}'..." + cp $t ${dir}/${name}.yaml || + panic "Unable to render '${t}'!" + + # finds the respective documentation file copying as "README.md", on the same + # directory where the respective task is located +# echo "# Copying '${name}' documentation file '${doc}'..." +# cp -v -f ${doc} "${dir}/README.md" || +# panic "Unable to copy '${doc}' into '${dir}'" + done +} + +release \ No newline at end of file diff --git a/tekton/cache-fetch.yaml b/tekton/cache-fetch.yaml index b45ad2efe..a890418af 100644 --- a/tekton/cache-fetch.yaml +++ b/tekton/cache-fetch.yaml @@ -1,4 +1,4 @@ -apiVersion: tekton.dev/v1alpha1 +apiVersion: tekton.dev/v1beta1 kind: StepAction metadata: name: cache-fetch diff --git a/tekton/cache-upload.yaml b/tekton/cache-upload.yaml index dde20c441..2aa82bbc1 100644 --- a/tekton/cache-upload.yaml +++ b/tekton/cache-upload.yaml @@ -1,4 +1,4 @@ -apiVersion: tekton.dev/v1alpha1 +apiVersion: tekton.dev/v1beta1 kind: StepAction metadata: name: cache-upload