Skip to content

Commit

Permalink
Add Release workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Pramod Bindal <[email protected]>

Add Release workflows

Add Release workflows

Signed-off-by: Pramod Bindal <[email protected]>

Signed-off-by: Pramod Bindal <[email protected]>

change stepAction version to tekton.dev/v1beta1

Signed-off-by: Pramod Bindal <[email protected]>
  • Loading branch information
pramodbindal committed Feb 3, 2025
1 parent 0e5f607 commit 5223ccf
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,3 +56,34 @@ fumpt:
help: ## print this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\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
85 changes: 85 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tekton/cache-fetch.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: StepAction
metadata:
name: cache-fetch
Expand Down
2 changes: 1 addition & 1 deletion tekton/cache-upload.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: StepAction
metadata:
name: cache-upload
Expand Down

0 comments on commit 5223ccf

Please sign in to comment.