-
Notifications
You must be signed in to change notification settings - Fork 263
Automate Fleet release against Rancher #4796
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
Changes from 4 commits
5a4825e
cd8f469
44d345e
9f2a7d4
631b55c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Compute the Fleet and Rancher versions needed to open a release PR. | ||
| # | ||
| # Environment variables: | ||
| # FLEET_BRANCH Fleet branch to release (e.g. release/v0.15 or main) | ||
| # GH_TOKEN GitHub token for API calls | ||
| # FLEET_REPO_DIR Path to the fleet checkout (default: ./fleet) | ||
| # GITHUB_OUTPUT Path to the GitHub Actions output file | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| FLEET_REPO_DIR="${FLEET_REPO_DIR:-./fleet}" | ||
|
|
||
| # Derive the Fleet minor version from the branch name. | ||
| # For main, compute it as (highest release branch minor) + 1. | ||
| if [ "$FLEET_BRANCH" = "main" ]; then | ||
| highest_minor=$(git -C "$FLEET_REPO_DIR" ls-remote --heads origin 'refs/heads/release/v0.*' \ | ||
| | grep -oE 'v0\.[0-9]+' | cut -d. -f2 | sort -n | tail -1) | ||
| if [ -z "$highest_minor" ]; then | ||
| printf 'ERROR: No release/v0.* branches found in fleet repo\n' >&2 | ||
| exit 1 | ||
| fi | ||
| fleet_minor=$((highest_minor + 1)) | ||
| else | ||
| fleet_minor=$(printf '%s' "$FLEET_BRANCH" | grep -oE '[0-9]+$') | ||
| fi | ||
|
|
||
| rancher_minor=$((fleet_minor - 1)) | ||
| charts_branch="dev-v2.${rancher_minor}" | ||
|
|
||
| # Fetch the Fleet chart directory listing from the rancher/charts dev branch. | ||
| chart_response=$(curl -fsSL \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/repos/rancher/charts/contents/charts/fleet?ref=${charts_branch}") || { | ||
| printf 'ERROR: Could not list Fleet charts in rancher/charts branch %s\n' "$charts_branch" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| latest_chart=$(printf '%s' "$chart_response" \ | ||
| | jq -r '.[] | select(.type == "dir") | .name' \ | ||
| | sort -V | tail -1) | ||
|
|
||
| if [ -z "$latest_chart" ]; then | ||
| printf 'ERROR: No Fleet chart directories found in rancher/charts branch %s\n' "$charts_branch" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Chart directory names follow the pattern <chart-version>+up<fleet-version>, | ||
| # e.g. 110.0.1+up0.15.1. | ||
| new_fleet="${latest_chart##*+up}" | ||
| new_chart="${latest_chart%%+*}" | ||
|
|
||
| # Target the Rancher release branch when it exists; fall back to main. | ||
| rancher_ref="release/v2.${rancher_minor}" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we are far away but given this is hardcoded maybe add a note to be changed once we are in 3.x versioin?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, but where should I add it? Trying to cover a wider variety of future cases would make the script significant more complicated I think, and there still can be changes which require us to fix things, like branch or repo changes and so on. But the good thing is that we can not really break something here, worst case we'll get a weird pull request that we can close.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a comment. The drop-down list for the workflow is static, that we have to change every ~4 month (for every new Fleet minor release). |
||
| http_status=$(curl -s -o /dev/null -w "%{http_code}" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/repos/rancher/rancher/branches/release%2Fv2.${rancher_minor}") | ||
| case "$http_status" in | ||
| 200) ;; | ||
| 404) rancher_ref="main" ;; | ||
| *) printf 'ERROR: GitHub API returned HTTP %s while checking Rancher branch\n' "$http_status" >&2; exit 1 ;; | ||
| esac | ||
|
|
||
| printf 'Charts branch: %s\n' "$charts_branch" | ||
| printf 'New Fleet version: %s\n' "$new_fleet" | ||
| printf 'New chart version: %s\n' "$new_chart" | ||
| printf 'Rancher ref: %s\n' "$rancher_ref" | ||
|
|
||
| { | ||
| printf 'new_fleet=%s\n' "$new_fleet" | ||
| printf 'new_chart=%s\n' "$new_chart" | ||
| printf 'rancher_ref=%s\n' "$rancher_ref" | ||
| } >> "${GITHUB_OUTPUT:?GITHUB_OUTPUT is not set}" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a set of existing Fleet and chart versions, isn't it? Wouldn't we then overwrite an existing chart?