Files
ess-helm/.github/workflows/releasing.yml

167 lines
5.8 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright 2024-2025 New Vector Ltd
# Copyright 2025-2026 Element Creations Ltd
#
# SPDX-License-Identifier: AGPL-3.0-only
name: Helm Chart packaging and releasing
on:
pull_request:
push:
branches:
- main
- 'maintenance/*'
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
jobs:
helm-package:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@6ee6290f1cbc4156c0bdd66691b2c144ef8df19a # v7
with:
enable-cache: true
activate-environment: true
- name: Set up UV environment
run: uv sync
- uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
- name: Set version
run: |
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
scripts/check_semver.py "$GITHUB_REF_NAME"
scripts/set_chart_version.sh "$GITHUB_REF_NAME"
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_target" ]; then
actual_pr_head_commit=$(yq --input-format json -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")
version=$(yq '.version' charts/matrix-stack/Chart.yaml | sed "s/-dev/-sha$actual_pr_head_commit/")
scripts/set_chart_version.sh "$version"
elif [ "$GITHUB_EVENT_NAME" != "main" ]; then
version=$(yq '.version' charts/matrix-stack/Chart.yaml | sed "s/-dev/-sha$GITHUB_SHA/")
scripts/set_chart_version.sh "$version"
else
echo "Did not set chart version on event $GITHUB_EVENT_NAME: $GITHUB_REF_TYPE/$GITHUB_REF_NAME"
fi
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Set helm changes annotations
run: |
scripts/towncrier_to_helm_annotation.py charts/matrix-stack
- name: Generate changelog
run: |
version=$(yq '.version' charts/matrix-stack/Chart.yaml)
# Add changes to CHANGELOG.md, keep files to generate CHANGELOG.latest.md
towncrier build --version "$version" --keep
# in empty file
sed -i "s/CHANGELOG.md/CHANGELOG.latest.md/" pyproject.toml
towncrier build --version "$version" --yes
sed -i "s/CHANGELOG.latest.md/CHANGELOG.md/" pyproject.toml
- name: Helm package
run: |
cd charts/matrix-stack
helm package .
- name: Helm push
if: ${{ github.event_name != 'pull_request' }}
run: helm push charts/matrix-stack/matrix-stack-*.tgz oci://ghcr.io/${{ github.repository }}
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: helm-package
path: |
charts/matrix-stack/*.tgz*
CHANGELOG.md
CHANGELOG.latest.md
retention-days: 1
release:
if: ${{ !failure() && !cancelled() && startsWith(github.ref, 'refs/tags/') }}
permissions:
contents: write
packages: read
pull-requests: write
needs:
- helm-package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
# We are creating a commit changing the chart version for the next version PR
persist-credentials: true
- name: Grab packaged chart
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: helm-package
path: ./
- name: Install uv
uses: astral-sh/setup-uv@6ee6290f1cbc4156c0bdd66691b2c144ef8df19a # v7
with:
enable-cache: true
activate-environment: true
- name: Set up UV environment
run: uv sync
- name: Calculate versions
id: versions
run: |
this_version=$(find charts/matrix-stack -name 'matrix-stack-*.tgz' | sed 's/.*matrix-stack-//;s/.tgz//')
next_version=$(echo "$this_version" | sed 's/-dev//' | awk -F'[ .]' '{print $1"."$2"."$3+1"-dev"}')
scripts/set_chart_version.sh "$next_version"
echo "this-version=$this_version" >> "$GITHUB_OUTPUT"
echo "next-version=$next_version" >> "$GITHUB_OUTPUT"
- name: Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
with:
draft: true
body_path: CHANGELOG.latest.md
files: charts/matrix-stack/matrix-stack*.tgz*
fail_on_unmatched_files: true
# This could simply be omitted if we didn't want to test without a tag
tag_name: "${{ steps.versions.outputs.this-version }}"
- name: Remove latest changelog
run: |
rm CHANGELOG.latest.md
rm newsfragments/*.md
touch newsfragments/.gitkeep
- name: Create PR for next patch version
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8
with:
branch: "gha/bump-to-${{ steps.versions.outputs.next-version }}"
base: "main"
commit-message: "Bump chart version to ${{ steps.versions.outputs.next-version }}"
title: "Bump chart version to ${{ steps.versions.outputs.next-version }} after release"
labels: automated,version-bump
body: |
${{ steps.versions.outputs.this-version }} has just been released.
This PR prepares the chart & dependencies for the next release:
${{ steps.versions.outputs.next-version }}.
The target branch may be wrong. In which case this PR should be taken over and manually adjusted.