Skip to content

Commit

Permalink
Update release process
Browse files Browse the repository at this point in the history
- `./hack/release.sh` to make the release
- Update `Makefile` to be able to do a release (and a github-release)
- Update release workflow to use `make github-release`

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Dec 19, 2023
1 parent 120f3d1 commit b034ee3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 13 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name: release

on:
push:
tags:
- "*"
workflow_dispatch: {}

jobs:
release:
Expand All @@ -14,7 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: stable
- uses: azure/setup-helm@v3

- uses: openshift-pipelines/release-tektoncd-task@main
- name: github-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make github-release
38 changes: 29 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# using the chart name and version from chart's metadata
CHART_NAME ?= $(shell awk '/^name:/ { print $$2 }' Chart.yaml)
CHART_VERSION ?= $(shell awk '/^version:/ { print $$2 }' Chart.yaml)
RELEASE_VERSION = v$(CHART_VERSION)

# release directory where the Tekton resources are rendered into.
RELEASE_DIR ?= /tmp/$(CHART_NAME)-$(CHART_VERSION)
Expand Down Expand Up @@ -34,16 +35,35 @@ install:
$(call render-template) |kubectl $(ARGS) apply -f -

# pepare a release
.PHONY: prepare-release
prepare-release:
mkdir -p $(RELEASE_DIR)/task/$(CHART_NAME) || true
helm template $(ARGS) . > $(RELEASE_DIR)/task/$(CHART_NAME)/$(CHART_NAME).yaml
cp README.md $(RELEASE_DIR)/task/$(CHART_NAME)/
go run github.com/openshift-pipelines/tektoncd-catalog/cmd/catalog-cd@main release --output release --version $(CHART_VERSION) $(RELEASE_DIR)/task/$(CHART_NAME)
@echo "Now you can release:"
@echo " git tag v$(CHART_VERSION) && git push v$(CHART_VERSION)"
@echo " gh release create v$(CHART_VERSION) --generate-notes"
@echo " gh release upload v$(CHART_VERSION) release/catalog.yaml"
@echo " gh release upload v$(CHART_VERSION) release/resources.tar.gz"
mkdir -p $(RELEASE_DIR) || true
hack/release.sh $(RELEASE_DIR)

.PHONY: release
release: prepare-release
pushd ${RELEASE_DIR} && \
go run github.com/openshift-pipelines/tektoncd-catalog/cmd/catalog-cd@main \
release \
--output release \
--version $(CHART_VERSION) \
tasks/* \
; \
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

# packages the helm-chart as a single tarball, using it's name and version to compose the file
helm-package: clean
Expand Down
66 changes: 66 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/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 task-git (it's the only task)
# See task-containers if there is more than one task to support.
declare task_name=task-git
declare task_doc=README.md
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 . >${task_dir}/${task_name}.yaml ||
panic "Unable to render '${task_name}'!"

# 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}'"
}

release

0 comments on commit b034ee3

Please sign in to comment.