name: Update Helm chartson:release:types:- publishedpermissions:contents: writepull-requests: writeconcurrency:group: update-helm-chartscancel-in-progress: falsejobs:update:name: Propose chart updateif: ${{ github.repository_owner == 'henrygd' && startsWith(github.event.release.tag_name, 'v') && !github.event.release.prerelease }}runs-on: ubuntu-latestenv:BRANCH: automation/update-helm-app-versionRELEASE_TAG: ${{ github.event.release.tag_name }}AUTOMATION_TOKEN: ${{ secrets.CR_TOKEN || github.token }}steps:- name: Checkout mainuses: actions/checkout@v7with:ref: maintoken: ${{ env.AUTOMATION_TOKEN }}- name: Update chart versionsid: updaterun: |version="${RELEASE_TAG#v}"if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; thenecho "Unsupported software release version: $version" >&2exit 1fichanged=falsefor chart in supplemental/helm/beszel-agent supplemental/helm/beszel-hub; docurrent_app_version=$(awk -F '"' '/^appVersion:/ { print $2 }' "$chart/Chart.yaml")if [[ "$current_app_version" == "$version" ]]; thenecho "$chart already uses appVersion $version"continuefinewest_version=$(printf '%s\n' "$current_app_version" "$version" | sort -V | tail -n 1)if [[ "$newest_version" != "$version" ]]; thenecho "Skipping stale update of $chart from $current_app_version to $version"continuefichart_version=$(awk '/^version:/ { print $2 }' "$chart/Chart.yaml")if [[ ! "$chart_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; thenecho "Unsupported chart version in $chart/Chart.yaml: $chart_version" >&2exit 1finext_chart_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))"NEW_APP_VERSION="$version" NEW_CHART_VERSION="$next_chart_version" \perl -pi -e 's/^appVersion:.*$/appVersion: "$ENV{NEW_APP_VERSION}"/; s/^version:.*$/version: $ENV{NEW_CHART_VERSION}/' \"$chart/Chart.yaml"OLD_APP_VERSION="$current_app_version" NEW_APP_VERSION="$version" \perl -pi -e 's/\Q$ENV{OLD_APP_VERSION}\E/$ENV{NEW_APP_VERSION}/g' "$chart/README.md"echo "$chart: appVersion $current_app_version -> $version, chart $chart_version -> $next_chart_version"changed=truedoneecho "changed=$changed" >> "$GITHUB_OUTPUT"- name: Open or update pull requestif: steps.update.outputs.changed == 'true'env:GH_TOKEN: ${{ env.AUTOMATION_TOKEN }}run: |version="${RELEASE_TAG#v}"title="chore(helm): update app version to ${version}"body="Updates the Helm charts for [Beszel ${version}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${RELEASE_TAG}) and bumps their chart patch versions. Merging this pull request publishes the updated charts to GHCR."git config user.name "github-actions[bot]"git config user.email "41898282+github-actions[bot]@users.noreply.github.com"git checkout -B "$BRANCH"git add supplemental/helm/beszel-agent/Chart.yaml \supplemental/helm/beszel-agent/README.md \supplemental/helm/beszel-hub/Chart.yaml \supplemental/helm/beszel-hub/README.mdgit commit -m "$title"git fetch origin "$BRANCH" || truegit push --force-with-lease origin "HEAD:refs/heads/${BRANCH}"pr_number=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number')if [[ -n "$pr_number" ]]; thengh pr edit "$pr_number" --title "$title" --body "$body"elsegh pr create --base main --head "$BRANCH" --title "$title" --body "$body"fi