-
Notifications
You must be signed in to change notification settings - Fork 92
feat(helm): Add workflow for publishing Helm charts to GitHub Pages. #1891
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 all commits
959f1b3
0a8d30f
e7a79cc
e424eb1
0e29b51
82d111c
2a7bf23
e65ee3e
9ea4e04
88e671a
ec3f223
20d0b4a
e66b9ad
e14dd6a
627ed80
9116ab4
1801a73
19742d5
f5b9366
a4d72e5
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,114 @@ | ||
| name: "clp-package-helm" | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - ".github/workflows/clp-package-helm.yaml" | ||
| - "taskfiles/helm.yaml" | ||
| - "tools/deployment/package-helm/**" | ||
| push: | ||
| paths: | ||
| - ".github/workflows/clp-package-helm.yaml" | ||
| - "taskfiles/helm.yaml" | ||
| - "tools/deployment/package-helm/**" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: "${{github.workflow}}-${{github.ref}}" | ||
|
|
||
| # Cancel in-progress jobs for efficiency | ||
| cancel-in-progress: true | ||
|
Comment on lines
+18
to
+22
Contributor
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. 🧩 Analysis chain🏁 Script executed: cat -n .github/workflows/clp-package-helm.yamlRepository: y-scope/clp Length of output: 4480 🌐 Web query:
💡 Result: In GitHub Actions, only runs that resolve to the exact same What
|
||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: "ubuntu-24.04" | ||
| steps: | ||
| - uses: "actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8" # v6.0.1 | ||
| with: | ||
| submodules: "recursive" | ||
|
|
||
| # Fetch all history for all branches; otherwise, `helm lint` would complain about not | ||
| # finding the `origin/main` branch. | ||
| fetch-depth: 0 | ||
|
|
||
| - name: "Install task" | ||
| shell: "bash" | ||
| run: "npm install -g @go-task/cli@3.44.0" | ||
|
|
||
| - name: "Lint Helm charts" | ||
| shell: "bash" | ||
| run: "task lint:check-helm" | ||
|
|
||
| publish: | ||
| # Publish from `main` and `vA.B.C` release branches. | ||
| if: >- | ||
| github.event_name != 'pull_request' | ||
| && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v')) | ||
| needs: "lint" | ||
| runs-on: "ubuntu-24.04" | ||
| permissions: | ||
| # To push to the `gh-pages` branch. | ||
| contents: "write" | ||
| steps: | ||
| - uses: "actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8" # v6.0.1 | ||
| with: | ||
| submodules: "recursive" | ||
|
|
||
| - name: "Install task" | ||
| shell: "bash" | ||
| run: "npm install -g @go-task/cli@3.44.0" | ||
|
|
||
| - name: "Package Helm chart" | ||
| shell: "bash" | ||
| run: "task helm:package" | ||
|
|
||
| - name: "Checkout branch `gh-pages`" | ||
| uses: "actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8" # v6.0.1 | ||
| with: | ||
| path: "gh-pages" | ||
| ref: "gh-pages" | ||
|
|
||
| - name: "Get chart version" | ||
| id: "get-chart-version" | ||
| uses: "mikefarah/yq@065b200af9851db0d5132f50bc10b1406ea5c0a8" # v4.50.1 | ||
| with: | ||
| cmd: "yq '.version' 'tools/deployment/package-helm/Chart.yaml'" | ||
|
|
||
| - name: "Update Helm repository" | ||
| id: "update-helm-repo" | ||
| shell: "bash" | ||
| run: |- | ||
| chart_tgz="clp-${{steps.get-chart-version.outputs.result}}.tgz" | ||
|
|
||
| # Skip if this chart version already exists. | ||
| if [[ -f "gh-pages/${chart_tgz}" ]]; then | ||
| echo "Chart ${chart_tgz} already exists, skipping publish." | ||
| echo "skip_publish=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| cp "build/clp-package-helm"/*.tgz "gh-pages/" | ||
|
|
||
| # Update index.yaml, merging with existing index if present. | ||
| . "build/toolchains/helm/env" | ||
| url="${{github.server_url}}/${{github.repository}}/raw/gh-pages" | ||
| if [[ -f "gh-pages/index.yaml" ]]; then | ||
| helm repo index "gh-pages" --merge "gh-pages/index.yaml" --url "${url}" | ||
| else | ||
| helm repo index "gh-pages" --url "${url}" | ||
| fi | ||
|
|
||
| - name: "Push to gh-pages branch" | ||
| if: "steps.update-helm-repo.outputs.skip_publish != 'true'" | ||
| shell: "bash" | ||
| working-directory: "gh-pages" | ||
| run: |- | ||
| git config user.name "$GITHUB_ACTOR" | ||
| git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
| git add "*.tgz" "index.yaml" | ||
| commit_message="ci(helm): Publish clp-${{steps.get-chart-version.outputs.result}}" | ||
| commit_message+=" from ${{github.ref_name}} (${{github.sha}})." | ||
| git commit -m "$commit_message" | ||
| git push | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ | |
| """Sphinx configuration file for CLP documentation.""" | ||
|
|
||
| from datetime import datetime, timezone | ||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
| from sphinx.application import Sphinx | ||
|
|
||
| # Constants | ||
|
|
@@ -120,6 +122,24 @@ def setup(app: Sphinx) -> None: | |
| app.connect("source-read", _replace_variable_placeholders) | ||
|
|
||
|
|
||
| def _get_helm_version_flag() -> str: | ||
| """ | ||
| Reads the Helm chart version from Chart.yaml and returns the appropriate version flag. | ||
|
|
||
| :return: "--version <version>" for stable releases, or "--devel" for dev versions. | ||
| """ | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| chart_yaml_path = ( | ||
| Path(__file__).parent.parent.parent / "tools" / "deployment" / "package-helm" / "Chart.yaml" | ||
| ) | ||
| chart = yaml.safe_load(chart_yaml_path.read_text()) | ||
|
|
||
| version = chart.get("version") | ||
| if version is not None and "-dev" not in version: | ||
| return f"--version {version}" | ||
|
|
||
| return "--devel" | ||
|
Comment on lines
+131
to
+140
Contributor
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. 🧩 Analysis chain🏁 Script executed: # First, check if Chart.yaml exists at the specified path
find . -name "Chart.yaml" -type fRepository: y-scope/clp Length of output: 166 🏁 Script executed: # Check the current state of the _get_helm_version_flag function and its context
cat -n docs/conf/conf.py | sed -n '120,150p'Repository: y-scope/clp Length of output: 1224 🏁 Script executed: # Look for error handling patterns and how yaml is imported/used
rg "yaml\." docs/conf/conf.py -A 2 -B 2Repository: y-scope/clp Length of output: 241 🏁 Script executed: # Find where _get_helm_version_flag is called
rg "_get_helm_version_flag" docs/conf/conf.py -B 2 -A 2Repository: y-scope/clp Length of output: 399 🏁 Script executed: # Verify Chart.yaml exists at the expected location
find . -path "*/tools/deployment/package-helm/Chart.yaml" -type f -exec head -5 {} \;Repository: y-scope/clp Length of output: 211 🏁 Script executed: # Check for any yaml imports and their usage patterns
rg "import yaml" docs/conf/conf.pyRepository: y-scope/clp Length of output: 66 Add error handling to prevent doc build failures when Chart.yaml is missing or invalid. The function is called during Sphinx setup to populate documentation variables. If Additionally, the docstring states the function returns an empty string 🛠️ Proposed fix- chart = yaml.safe_load(chart_yaml_path.read_text())
-
- version = chart.get("version")
+ try:
+ chart = yaml.safe_load(chart_yaml_path.read_text()) or {}
+ version = chart.get("version")
+ except (FileNotFoundError, yaml.YAMLError, AttributeError):
+ return "--devel"🤖 Prompt for AI Agents
Member
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. The
Contributor
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.
One minor note: the docstring currently states the function returns :return: "--version <version>" for stable releases, or "--devel" for dev versions.This is just a documentation accuracy fix and doesn't affect the fail-fast behavior. ✏️ Learnings added
🧠 Learnings used |
||
|
|
||
|
|
||
| def _replace_variable_placeholders(_app: Sphinx, _docname: str, content: list[str]) -> None: | ||
| """ | ||
| Replaces each variable placeholder in the docs with the relevant value. | ||
|
|
@@ -130,6 +150,7 @@ def _replace_variable_placeholders(_app: Sphinx, _docname: str, content: list[st | |
| """ | ||
| placeholder_to_value = { | ||
| "DOCS_VAR_CLP_GIT_REF": CLP_GIT_REF, | ||
| "DOCS_VAR_HELM_VERSION_FLAG": _get_helm_version_flag(), | ||
| } | ||
| for placeholder, value in placeholder_to_value.items(): | ||
| content[0] = content[0].replace(placeholder, value) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| version: "3" | ||
|
|
||
| includes: | ||
| toolchains: "toolchains.yaml" | ||
|
|
||
| vars: | ||
| G_PACKAGE_HELM_BUILD_DIR: "{{.G_BUILD_DIR}}/clp-package-helm" | ||
|
|
||
| tasks: | ||
| package: | ||
| vars: | ||
| OUTPUT_DIR: "{{.G_PACKAGE_HELM_BUILD_DIR}}" | ||
| deps: ["toolchains:helm"] | ||
| cmds: | ||
| - "rm -rf '{{.OUTPUT_DIR}}'" | ||
| - "mkdir -p '{{.OUTPUT_DIR}}'" | ||
| - |- | ||
| . "{{.G_HELM_TOOLCHAIN_ENV_FILE}}" | ||
| helm package "{{.ROOT_DIR}}/tools/deployment/package-helm" --destination "{{.OUTPUT_DIR}}" |
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.
🧹 Nitpick | 🔵 Trivial
Consider using YAML anchor for duplicate paths.
The paths array is identical for both
pull_requestandpushtriggers. Per repository conventions, YAML anchors are preferred to avoid duplication.♻️ Suggested refactor
Based on learnings, YAML anchors/aliases are acceptable and preferred in this repository's workflows.
📝 Committable suggestion
🤖 Prompt for AI Agents