Skip to content

Commit

Permalink
chore: add helm charts and release automations
Browse files Browse the repository at this point in the history
  • Loading branch information
Wielewout committed May 5, 2023
1 parent 5394dd3 commit 9b3bdef
Show file tree
Hide file tree
Showing 16 changed files with 719 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"branchPrefix": "renovate/",
"semanticCommits": "enabled",
"semanticCommitType": "fix",
"semanticCommitScope": "deps",
"commitMessagePrefix": "fix(deps):",
"dependencyDashboard": true,
"dependencyDashboardApproval": false,
"dependencyDashboardAutoclose": false,
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
":semanticCommits"
],
"helmv3": {
"fileMatch": [
"(^|/)Chart\\.yaml$"
],
"commitMessageTopic": "update {{depName}}",
"registryAliases": {}
},
"regexManagers": [
{
"datasourceTemplate": "docker",
"fileMatch": ["(^|/)Chart\\.yaml$"],
"matchStrings": [
"#\\s?renovate: image=(?<depName>.*?)\\s?appVersion:\\s?\\\"??(?<currentValue>[\\w+\\.\\-]*)\"?"
]
}
]
}
178 changes: 178 additions & 0 deletions .github/workflows/helm-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Helm Charts

on:
push:
branches:
- main
- releases/**
pull_request:
workflow_dispatch:

jobs:

vars:
name: Variables
# This is a work-around to be able to properly use variables.
# This job should be made a dependency in order to be able to use its outputs.
runs-on: ubuntu-latest
outputs:
is_main_branch: ${{ github.ref_type == 'branch' && github.ref_name == 'main' }}
is_release_branch: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'releases/') }}
is_pull_request: ${{ github.event_name == 'pull_request' }}
target_branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
charts: ${{ steps.list-charts.outputs.charts }}
timeout-minutes: 1
steps:
- name: Expose variables
run: echo "Exposing variables for proper usage"

- name: Checkout
uses: actions/checkout@v3

- name: List charts
id: list-charts
run: echo "charts=$(ls -dm charts/*/ | tr -d ' ')" >> $GITHUB_OUTPUT

lint-charts:
name: Lint Charts
needs:
- vars
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: ${{ needs.vars.outputs.is_pull_request == 'true' && '0' || '1' }}

- name: Set up Helm
uses: azure/setup-helm@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: '3.9'
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Add helm repositories
run: ./bin/add-repos

- name: List changed
id: list-changed
run: |
changed_charts="all"
if [ "${{ needs.vars.outputs.is_pull_request }}" == "true" ]; then
changed_charts="$(ct list-changed --config etc/ct.yaml --target-branch ${{ needs.vars.outputs.target_branch }})"
fi
if [[ -n "${changed_charts}" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Lint charts
if: ${{ steps.list-changed.outputs.changed == 'true' }}
run: ct lint --config etc/ct.yaml ${{ needs.vars.outputs.is_pull_request == 'true' && format('--target-branch {0}', needs.vars.outputs.target_branch) || format('--charts {0}', needs.vars.outputs.charts) }}

test-charts:
name: Test Charts
needs:
- vars
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: ${{ needs.vars.outputs.is_pull_request == 'true' && '0' || '1' }}

- name: Set up Helm
uses: azure/setup-helm@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: '3.9'
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Add helm repositories
run: ./bin/add-repos

- name: List changed
id: list-changed
run: |
changed_charts="all"
if [ "${{ needs.vars.outputs.is_pull_request }}" == "true" ]; then
changed_charts="$(ct list-changed --config etc/ct.yaml --target-branch ${{ needs.vars.outputs.target_branch }})"
fi
if [[ -n "${changed_charts}" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Create kind cluster
if: ${{ steps.list-changed.outputs.changed == 'true' }}
uses: helm/[email protected]

- name: Test charts
if: ${{ steps.list-changed.outputs.changed == 'true' }}
run: ct install --config etc/ct.yaml ${{ needs.vars.outputs.is_pull_request == 'true' && format('--target-branch {0}', needs.vars.outputs.target_branch) || format('--charts {0}', needs.vars.outputs.charts) }}

release-charts:
name: Release Charts
if: ${{ needs.vars.outputs.is_main_branch == 'true' || needs.vars.outputs.is_release_branch == 'true' }}
needs:
- vars
- lint-charts
- test-charts
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set git user
uses: git-actions/set-user@v1

- name: Install Helm
uses: azure/setup-helm@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add helm repositories
run: ./bin/add-repos

- name: Run chart releaser
uses: helm/[email protected]
with:
config: etc/cr.yaml
mark_as_latest: ${{ needs.vars.outputs.is_main_branch == 'true' }}
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

release-please:
name: Release
if: ${{ needs.vars.outputs.is_main_branch == 'true' || needs.vars.outputs.is_release_branch == 'true' }}
# Run after release-charts so that the tag exists in case of release commits.
# Otherwise release please will create a new PR
# as it doesn't yet have the release to compare changes with.
needs:
- release-charts
permissions:
contents: write
pull-requests: write
uses: ./.github/workflows/release-please.yaml
29 changes: 29 additions & 0 deletions .github/workflows/release-please-pr-labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release Please PR Labels

on:
pull_request:
types:
- closed

jobs:

label-release-pr:
name: Label Release PR
if: "${{ startsWith(github.event.pull_request.title, 'chore: release') }}"
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Remove pending release label
uses: buildsville/[email protected]
with:
type: remove
labels: "release: pending"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Add ${{ github.event.pull_request.merged && 'approved' || 'rejected' }} release label
uses: buildsville/[email protected]
with:
type: add
labels: "release: ${{ github.event.pull_request.merged && 'approved' || 'rejected' }}"
token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release Please

on:
workflow_call:

jobs:

release-please:
name: Please
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Release please
uses: google-github-actions/release-please-action@v3
with:
command: manifest-pr
default-branch: ${{ github.ref_name }}
config-file: "etc/release-please-config.json"
manifest-file: "etc/.release-please-manifest.json"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.tgz
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Helm charts

This repository contains accelleran's helm charts.

## Chart dependencies

For helm chart dependencies the required repository needs to be added.
In case a new dependency repository is needed it should be added to `bin/add-repos`.
Otherwise the workflow will be broken as helm would be unable to build the chart dependencies.

To locally add all necessary repos:

```sh
./bin/add-repos
```

## New charts

A bit of setup is needed for release please when adding a new chart.
This is automated in `bin/add-chart`.

```sh
./bin/add-chart example 0.1.0
```

> The initial version is optional (default is `0.1.0`).
> **Note**
>
> When adding a new chart, the chart releaser action will always create an initial release without release please intervening.
> This means that the automatic changelog etc. will be missing in this initial GitHub release.
> Instead, chart releaser will use the description in `Chart.yaml` as the body of the GitHub release.
## Legacy charts

To add legacy helm charts, they need to be added to a release with the packaged chart as an asset.
This asset then needs to be linked to the `index.yaml` file for GitHub Pages.

The `release-legacy-chart` script expects either a directory of packaged charts or a single file (i.c.w. an index file).
The release tag etc. are derived from the file name.

```sh
export GITHUB_TOKEN=abc-xyz

./bin/release-legacy-chart -f example-0.1.0.tgz -i index.yaml
./bin/release-legacy-chart -d charts
```

> Note the space to hide the token from history.
50 changes: 50 additions & 0 deletions bin/add-chart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

BASE_DIR=$(dirname "$0")
GIT_ROOT=$(cd "${BASE_DIR}/.." && pwd)

function print_error() {
echo "${1}" 1>&2
}

function error() {
print_error "${1}"
exit 1
}

function warn() {
print_error "${1}"
}

if [ ${#} -lt 1 ]; then
error "Invalid number of arguments: requires at least 1 (chart)"
fi

chart="${1}"
version="${2:-0.1.0}"

if [ -f "${GIT_ROOT}/charts/${chart}/Chart.yaml" ]; then
warn "Chart ${chart} already exists"
else
helm create "${GIT_ROOT}/charts/${chart}"
fi

version="${version}" yq --inplace \
'.version = env(version)' \
"${GIT_ROOT}/charts/${chart}/Chart.yaml"

contents="$(jq \
--arg chart_path "charts/${chart}" \
--arg chart "${chart}" \
'.packages[$chart_path].component = $chart | .packages[$chart_path]."package-name" = $chart' \
"${GIT_ROOT}"/etc/release-please-config.json)"
echo -E "${contents}" > "${GIT_ROOT}"/etc/release-please-config.json

# chart releaser will create release on first commit
# so include version in release please manifest
contents="$(jq \
--arg chart_path "charts/${chart}" \
--arg version "${version}" \
'.[$chart_path] = $version' \
"${GIT_ROOT}"/etc/.release-please-manifest.json)"
echo -E "${contents}" > "${GIT_ROOT}"/etc/.release-please-manifest.json
3 changes: 3 additions & 0 deletions bin/add-repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

helm repo add accelleran https://accelleran.github.io/helm-charts-ng/
Loading

0 comments on commit 9b3bdef

Please sign in to comment.