Skip to content

Commit

Permalink
ci: fix helm release (#14501)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney authored Oct 16, 2024
1 parent 3834c74 commit 0446d63
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 33 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: helm-release

on:
workflow_dispatch: # must be invoked manually
workflow_dispatch: # for manual testing
push:
branches:
- main
- k[0-9]+
paths:
- 'production/helm/loki/Chart.yaml'

jobs:
call-update-helm-repo:
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/helm-tagged-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
name: helm-weekly-release-pr
name: Helm tagged release PR

on:
release:
types:
- released

workflow_dispatch: # for manual testing

jobs:
weekly-release-pr:
runs-on: ubuntu-latest
env:
RELEASE_VERSION: "${{ github.event.release.tag_name || 'test' }}"
BUILD_IN_CONTAINER: false
steps:
- uses: actions/checkout@v4
- uses: gabe565/setup-helm-docs-action@v1
with:
version: v1.11.2

- id: "get_github_app_token"
name: "get github app token"
Expand All @@ -21,13 +29,14 @@ jobs:

- name: Update/regenerate files
id: update
run: bash .github/workflows/scripts/helm-tagged-release.sh ${{ github.event.release.tag_name }}
run: |
bash .github/workflows/scripts/helm-tagged-release.sh ${RELEASE_VERSION}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: Release loki Helm chart ${{ steps.update.outputs.new_chart_version }}
title: "chore: release loki helm chart ${{ steps.update.outputs.new_chart_version }}"
body: Automated PR created by [helm-tagged-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-tagged-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update.outputs.new_chart_version }}
branch: helm-chart-tagged-${{ steps.update.outputs.new_chart_version }}
Expand Down
41 changes: 36 additions & 5 deletions .github/workflows/helm-weekly-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
name: helm-weekly-release-pr
name: Helm weekly release PR

on:
schedule:
- cron: '0 10 * * 1-5' # 10 UTC on weekdays; if we miss published images one day, they should align the day after

workflow_dispatch: # for manual testing

permissions:
contents: "read"
id-token: "write"
pull-requests: "write"

jobs:
weekly-release-pr:
runs-on: ubuntu-latest
env:
BUILD_IN_CONTAINER: false
steps:
- uses: actions/checkout@v4
- uses: imjasonh/[email protected]
- uses: gabe565/setup-helm-docs-action@v1
with:
version: v1.11.2

- id: "get_github_app_token"
name: "get github app token"
Expand All @@ -21,15 +30,37 @@ jobs:
owner: "${{ github.repository_owner }}"
private-key: "${{ secrets.APP_PRIVATE_KEY }}"

- name: Update/regenerate files
- name: "Login to DockerHub (from vault)"
uses: "grafana/shared-workflows/actions/dockerhub-login@main"

- uses: imjasonh/[email protected]

- name: Update/regenerate files for k release
id: update-k
run: |
bash .github/workflows/scripts/helm-weekly-release.sh -k
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: "chore: release loki helm chart ${{ steps.update-k.outputs.new_chart_version }}"
body: Automated PR created by [helm-weekly-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-weekly-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update-k.outputs.new_chart_version }}
branch: helm-chart-weekly-${{ steps.update-k.outputs.new_chart_version }}
base: ${{ steps.update-k.outputs.weekly }}
labels: helm

- name: Update/regenerate files for standard release
id: update
run: bash .github/workflows/scripts/helm-weekly-release.sh
run: |
bash .github/workflows/scripts/helm-weekly-release.sh
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: Release loki Helm chart ${{ steps.update.outputs.new_chart_version }}
title: "chore: release loki helm chart ${{ steps.update.outputs.new_chart_version }}"
body: Automated PR created by [helm-weekly-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-weekly-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update.outputs.new_chart_version }}
branch: helm-chart-weekly-${{ steps.update.outputs.new_chart_version }}
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/scripts/common.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ get_yaml_node() {
# Increments the part of the semver string
# $1: version itself
# $2: number of part: 0 – major, 1 – minor, 2 – patch
# shellcheck disable=SC2207,SC2046,SC2248,SC2250
increment_semver() {
local delimiter=.
local array=("$(echo "$1" | tr "${delimiter}" '\n')")
array[$2]=$((array[$2] + 1))
echo "$(
local IFS=${delimiter}
echo "${array[*]}"
)"
local array=($(echo "$1" | tr $delimiter '\n'))
array[$2]=$((array[$2]+1))
echo $(local IFS=$delimiter ; echo "${array[*]}")
}

# Sets the patch segment of a semver to 0
# $1: version itself
# shellcheck disable=SC2207,SC2046,SC2248,SC2250
set_semver_patch_to_zero() {
local delimiter=.
local array=("$(echo "$1" | tr "${delimiter}" '\n')")
local array=($(echo "$1" | tr $delimiter '\n'))
array[2]="0"
echo "$(
local IFS=${delimiter}
echo "${array[*]}"
)"
echo $(local IFS=$delimiter ; echo "${array[*]}")
}
46 changes: 37 additions & 9 deletions .github/workflows/scripts/helm-weekly-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ source "${script_dir}/common.sh"
find_latest_image_tag() {
local docker_hub_repo=$1
local regExp="^(k|weekly-k)\d+-[a-z0-9]+"
crane ls "${docker_hub_repo}" | grep -P "${regExp}" | sed -E "s/([weekly-]*k[[:digit:]]*)-([^-]*).*/\1-\2/g" | uniq | sort -Vur | head -1
local crane_results
crane_results="$(crane ls "${docker_hub_repo}" | grep -P "${regExp}" | sed -E "s/([weekly-]*k[[:digit:]]*)-([^-]*).*/\1-\2/g" | sort -Vur)"
set +o pipefail
echo "${crane_results}" | head -1
set -o pipefail
}

# takes k197-abcdef and returns r197, k197-abcdef-arm64 and returns k197, weekly-k197-abcdef and returns k197
Expand All @@ -22,6 +26,7 @@ extract_k_version() {
calculate_next_chart_version() {
local current_chart_version=$1
local latest_image_tag=$2
local k_release=$3

local current_chart_semver
current_chart_semver=$(echo "${current_chart_version}" | grep -P -o '^(\d+.){2}\d+')
Expand All @@ -35,7 +40,12 @@ calculate_next_chart_version() {
# Also reset the patch release number to 0.
new_chart_semver=$(set_semver_patch_to_zero "${new_chart_semver}")
fi
echo "${new_chart_semver}-weekly.${new_chart_weekly}"

if ${k_release}; then
echo "${new_chart_semver}-weekly.${new_chart_weekly}"
else
echo "${new_chart_semver}"
fi
}

validate_version_update() {
Expand All @@ -60,25 +70,43 @@ validate_version_update() {
fi
}

k_release=false
if [[ "$1" == "-k" ]]; then
k_release=true
shift
fi

values_file=production/helm/loki/values.yaml
chart_file=production/helm/loki/Chart.yaml

latest_loki_tag=$(find_latest_image_tag grafana/loki)
latest_gel_tag=$(find_latest_image_tag grafana/enterprise-logs)
current_chart_version=$(get_yaml_node "${chart_file}" .version)
new_chart_version=$(calculate_next_chart_version "${current_chart_version}" "${latest_loki_tag}")
new_chart_version=$(calculate_next_chart_version "${current_chart_version}" "${latest_loki_tag}" "${k_release}")

validate_version_update "${new_chart_version}" "${current_chart_version}" "${latest_gel_tag}" "${latest_loki_tag}"

update_yaml_node "${values_file}" .loki.image.tag "${latest_loki_tag}"
update_yaml_node "${values_file}" .enterprise.image.tag "${latest_gel_tag}"
update_yaml_node "${chart_file}" .appVersion "$(extract_k_version "${latest_loki_tag}")"
if ${k_release}; then
update_yaml_node "${values_file}" .loki.image.tag "${latest_loki_tag}"
update_yaml_node "${values_file}" .enterprise.image.tag "${latest_gel_tag}"
update_yaml_node "${chart_file}" .appVersion "$(extract_k_version "${latest_loki_tag}")"
fi

update_yaml_node "${chart_file}" .version "${new_chart_version}"

sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}\n\n- \[CHANGE\] Changed version of Grafana Loki to ${latest_loki_tag}\n- \[CHANGE\] Changed version of Grafana Enterprise Logs to ${latest_gel_tag}/g" production/helm/loki/CHANGELOG.md
if ${k_release}; then
sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}\n\n- \[CHANGE\] Changed version of Grafana Loki to ${latest_loki_tag}\n- \[CHANGE\] Changed version of Grafana Enterprise Logs to ${latest_gel_tag}/g" production/helm/loki/CHANGELOG.md
else
sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}/g" production/helm/loki/CHANGELOG.md
fi

make TTY='' helm-docs

echo "::set-output name=new_chart_version::${new_chart_version}"
if ${k_release}; then
echo "::set-output name=weekly::$(extract_k_version "${latest_loki_tag}")"
fi
5 changes: 5 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ ifeq ($(BUILD_IN_CONTAINER),true)
-c /helm-docs/production/helm/ \
-t reference.md.gotmpl \
-o reference.md
$(PODMAN) run --rm --volume "$(realpath ..):/helm-docs" -u "$$(id -u)" "docker.io/jnorwood/helm-docs:v1.11.0" \
-c /helm-docs/production/helm/ \
-t README.md.gotmpl \
-o README.md
else
helm-docs -c ../production/helm/ -t reference.md.gotmpl -o reference.md
helm-docs -c ../production/helm/ -t README.md.gotmpl -o README.md
endif
mv "$(basename $<)" "$@"
11 changes: 7 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@

devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(import ./packages/chart-releaser.nix {
inherit (prev) pkgs lib buildGoModule fetchFromGitHub;
(pkgs.callPackage ./nix/packages/chart-releaser.nix {
inherit pkgs;
inherit (pkgs) buildGoModule fetchFromGitHub;
})

(pkgs.callPackage ./nix/packages/faillint.nix {
inherit (pkgs) lib buildGoModule fetchFromGitHub;
})

chart-testing
faillint
gcc
go
golangci-lint
Expand All @@ -89,7 +93,6 @@
nettools
nixpkgs-fmt
statix
systemd
yamllint
];
};
Expand Down

0 comments on commit 0446d63

Please sign in to comment.