From 89abe4d3cc18593c36e96c9d1051478684b88e4e Mon Sep 17 00:00:00 2001 From: Otavio Fernandes Date: Thu, 26 Oct 2023 07:35:43 +0200 Subject: [PATCH] chore: Release Automation Scripting out the release procedure for GHA. --- .github/workflows/release.yaml | 7 +++- Chart.yaml | 4 +- Makefile | 32 +++++++++++---- hack/release.sh | 73 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 12 deletions(-) create mode 100755 hack/release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 72dca43..cfaef1e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,3 +1,4 @@ +--- name: release on: @@ -12,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: openshift-pipelines/release-tektoncd-task@main + - name: release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + make github-release diff --git a/Chart.yaml b/Chart.yaml index ec795a3..fd7b2c5 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,6 +1,6 @@ --- apiVersion: v2 name: task-containers -description: TODO... +description: Contains the Tekton Tasks to manage container images type: application -version: 0.0.1 +version: 0.1.0 diff --git a/Makefile b/Makefile index 977e778..39432ce 100644 --- a/Makefile +++ b/Makefile @@ -75,8 +75,8 @@ ACT_WORKFLOWS ?= ./.github/workflows/test.yaml # generic arguments employed on most of the targets ARGS ?= -# making sure the variables declared in the Makefile are exported to the executables/scripts invoked -# on all targets +# making sure the variables declared in the Makefile are exported to the executables/scripts +# invoked on all targets .EXPORT_ALL_VARIABLES: # uses helm to render the resource templates to the stdout @@ -90,13 +90,29 @@ helm-template: default: helm-template -# renders all "task-*" named templates into the release directory, using the original -# template filename as the Task name on release direcotry. -helm-template-tasks: +# renders the task templates and copies documentation into the ${RELEASE_DIR} +prepare-release: mkdir -p $(RELEASE_DIR) || true - for t in `ls -1 templates/task-*.yaml`; do \ - helm template --show-only=$$t . >$(RELEASE_DIR)/`basename $$t`; \ - done + hack/release.sh $(RELEASE_DIR) + +# runs "catalog-cd release" to create the release payload based on the Tekton resources +# prepared by the previous step +release: prepare-release + mkdir -p $(RELEASE_DIR)/release || true + go run github.com/openshift-pipelines/tektoncd-catalog/cmd/catalog-cd@main release \ + --output $(RELEASE_DIR)/release \ + --version $(CHART_VERSION) \ + $(RELEASE_DIR)/tasks/* + +# rolls out the current Chart version as the repository release version, uploads the release +# payload prepared to GitHub (using gh) +github-release: RELEASE_VERSION = v$(CHART_VERSION) +github-release: release + git tag $(RELEASE_VERSION) && \ + git push $(RELEASE_VERSION) && \ + 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 # renders and installs the resources (task) install: diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 0000000..a1ac16b --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,73 @@ +#!/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%.*}" +} + +# Finds the respective documentation for the task name, however, for s2i it only consider the +# "task-s2i" part instead of the whole name. +find_doc() { + declare task_name="${1}" + [[ "${task_name}" == "task-s2i"* ]] && + task_name="task-s2i" + find docs/ -name "${task_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}'!" + + # releasing all task templates using the following glob expression + for t in $(ls -1 templates/task-*.yaml); do + declare task_name=$(extract_name ${t}) + [[ -z "${task_name}" ]] && + panic "Unable to extract Task name from '${t}'!" + + declare task_doc="$(find_doc ${task_name})" + [[ -z "${task_doc}" ]] && + panic "Unable to find documentation file for '${task_name}'!" + + declare task_dir="${RELEASE_DIR}/tasks/${task_name}" + [[ ! -d "${task_dir}" ]] && + mkdir -p "${task_dir}" + + # rendering the helm template for the specific file, using the resource name for the + # filename respectively + echo "# Rendering '${task_name}' at '${task_dir}'..." + helm template --show-only=${t} . >${task_dir}/${task_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 '${task_name}' documentation file '${task_doc}'..." + cp -v -f ${task_doc} "${task_dir}/README.md" || + panic "Unable to copy '${task_doc}' into '${task_dir}'" + done +} + +release