Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix helm release #14501

Merged
merged 26 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7683ee4
ci: fix helm release
trevorwhitney Oct 16, 2024
e9689b8
ci: run on all pull requests
trevorwhitney Oct 16, 2024
a38c7fc
ci: fix id conflict
trevorwhitney Oct 16, 2024
877fa81
ci: remove uniq
trevorwhitney Oct 16, 2024
d0103e7
ci: test tagged version CI on pull request
trevorwhitney Oct 16, 2024
984b7af
ci: crane login
trevorwhitney Oct 16, 2024
651b394
ci: move docker auth lower
trevorwhitney Oct 16, 2024
8ae9149
ci: fix permissions
trevorwhitney Oct 16, 2024
c0a3db1
ci: add contents read permission
trevorwhitney Oct 16, 2024
5d56b0f
ci: fix docker hub auth
trevorwhitney Oct 16, 2024
8ef43c2
ci: fix docker username and password
trevorwhitney Oct 16, 2024
a91ca8a
ci: remove crane auth
trevorwhitney Oct 16, 2024
647aeab
ci: move crane results to variable for debugging
trevorwhitney Oct 16, 2024
6d123f6
ci: more debugging
trevorwhitney Oct 16, 2024
d0805bd
ci: more debugging
trevorwhitney Oct 16, 2024
58e62b1
ci: don't build in container
trevorwhitney Oct 16, 2024
c990367
ci: install helm-docs
trevorwhitney Oct 16, 2024
95f394f
ci: helm-docs version
trevorwhitney Oct 16, 2024
bded131
ci: fix broken pipe
trevorwhitney Oct 16, 2024
2130efd
ci: still dealing with broken pipes
trevorwhitney Oct 16, 2024
1cd29f8
ci: pipefail is a fail
trevorwhitney Oct 16, 2024
ed80bed
ci: fix linting of created PR
trevorwhitney Oct 16, 2024
8835ba7
ci: fixed tagged release script
trevorwhitney Oct 16, 2024
6dae0c5
ci: remove temporary triggers
trevorwhitney Oct 16, 2024
b367f1b
fix: script linting
trevorwhitney Oct 16, 2024
81e7aca
Merge branch 'main' into fix-helm-release
trevorwhitney Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading