Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
135 changes: 135 additions & 0 deletions .github/workflows/update-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Update documentation

on:
pull_request_target:
branches:
- main
Comment thread
lusu007 marked this conversation as resolved.
paths:
- "charts/**"

jobs:
gather-information:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
chart: ${{ steps.gather-information.outputs.chart }}
values_changed: ${{ steps.gather-information.outputs.values_changed }}
failed: ${{ steps.gather-information.outputs.failed }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.CONTANE_BOT_TOKEN }}

- name: Gather pull request information
id: gather-information
shell: bash
run: |
Comment thread
lusu007 marked this conversation as resolved.
NUM_CHANGED_CHARTS=0
cd charts || exit 1
for chart in */; do
# Check if there are changes
if git diff --name-only HEAD~1 | grep -q "$chart"; then
echo "$chart: No changes detected"
continue
fi
echo "$chart: Changes detected"
NUM_CHANGED_CHARTS=$((NUM_CHANGED_CHARTS + 1))
echo "CHANGED_CHART=\"$chart\"" >> "$GITHUB_ENV"
done
if [ "$NUM_CHANGED_CHARTS" -gt 1 ]; then
echo "Multiple charts have changed, only update one chart per PR"
exit 1
fi
if git diff --name-only HEAD~1 | grep -q "$CHANGED_CHART/values.yaml"; then
echo "$CHANGED_CHART: No values.yaml changes detected"
fi
echo "$CHANGED_CHART: values.yaml changes detected"
echo "VALUES_CHANGED=true" >> "$GITHUB_ENV"

update-documentation:
Comment thread
lusu007 marked this conversation as resolved.
runs-on: ubuntu-latest
permissions:
contents: write
needs: gather-information
if: ${{ needs.gather-information.outputs.failed != 'true' }}
Comment thread
lusu007 marked this conversation as resolved.
env:
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.CONTANE_BOT_TOKEN }}

- name: Configure Git
run: |
git config user.name "contane-bot"
git config user.email "160241315+contane-bot@users.noreply.github.com"

- name: Install readme-generator-for-helm
if: ${{ needs.gather-information.outputs.values_changed == 'true' }}
run: npm install -g @bitnami/readme-generator-for-helm@2.6.1

- name: Update README.md
if: ${{ needs.gather-information.outputs.values_changed == 'true' }}
shell: bash
run: |
cd charts || exit 1
echo "Updating README.md for $CHANGED_CHART"
readme-generator --values "$CHANGED_CHART/values.yaml" --readme "$CHANGED_CHART/README.md"
Comment thread
meyfa marked this conversation as resolved.

- name: Update changelog.md
shell: bash
run: |
echo "Generating changelog for $CHANGED_CHART"
npx semantic-release --dry-run --no-ci --plugins @semantic-release/release-notes-generator > "$CHANGED_CHART/release-notes.md"
# Extract relevant part
sed -n '/### \[/{:a;n;/### \[/{p;q};p;ba}' "$CHANGED_CHART/release-notes.md" > "$CHANGED_CHART/CHANGELOG.md"
rm "$CHANGED_CHART/release-notes.md"
Comment on lines +92 to +96
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get rid of any previous content in CHANGELOG.md, right? Usually, we would want the changelog to contain all versions ever released. This is also important e.g. if Renovate jumps over a version (such as updating from 1.2.0 straight to 1.4.0, in which case it should also have access to the 1.3.0 changelog).


- name: Install changelog-generator
run: npm install -g github-changelog-generator

- name: Update ArtifactHub change annotations
shell: bash
run: |
# Parse PR title to create changelog entries
changes=""
if [[ $PR_TITLE == *"feat:"* ]]; then
changes="$changes"$'\n' - kind: feature
changes="$changes"$'\n' description: "${PR_TITLE#*: }"
Comment on lines +107 to +108
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen this syntax before... What does the second $ do, and why are there no quotes surrounding - kind: feature etc?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, if there was a quote in the PR title, it would need to be escaped. We might have to use a tool for that, since any backslash in the PR title would also need to be escaped, etc. In general, this can often lead to invalid YAML. Not a security risk, just something that could lead to broken commits.

elif [[ "$PR_TITLE" == *"fix:"* ]]; then
changes="$changes"$'\n' - kind: bugfix
changes="$changes"$'\n' description: "${PR_TITLE#*: }"
fi
Comment on lines +106 to +112
Copy link
Copy Markdown
Member

@meyfa meyfa Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this work? (Besides generating invalid YAML if the PR title contains quotes or backslashes)

Suggested change
if [[ $PR_TITLE == *"feat:"* ]]; then
changes="$changes"$'\n' - kind: feature
changes="$changes"$'\n' description: "${PR_TITLE#*: }"
elif [[ "$PR_TITLE" == *"fix:"* ]]; then
changes="$changes"$'\n' - kind: bugfix
changes="$changes"$'\n' description: "${PR_TITLE#*: }"
fi
if [[ "$PR_TITLE" == "feat"* ]]; then
changes=" - kind: feature\n description: \"${PR_TITLE#*: }\""
elif [[ "$PR_TITLE" == "fix"* ]]; then
changes=" - kind: bugfix\n description: \"${PR_TITLE#*: }\""
fi

local file_path="Chart.yaml"
if [ ! -f "$file_path" ]; then
echo "Chart.yaml not found!"
exit 1
fi
chart=$(cat "$file_path")
# Check if annotations exist
if ! grep -q "annotations:" <<< "$chart"; then
chart=$(echo "$chart"$'\n'annotations:)
fi
# Check if artifacthub.io/changes annotation exists
if ! grep -q "artifacthub.io/changes:" <<< "$chart"; then
chart=$(echo "$chart"$'\n' artifacthub.io/changes: | sed 's/^/ /')
fi
# Append the new changes to the existing ones
chart=$(echo "$chart"$'\n'"$changes" | sed 's/^/ /')
Comment on lines +119 to +128
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure what this part is trying to do 😅 Why would we always append? Shouldn't we replace the annotations from the previous release? In any case, I don't think the current syntax achieves this - however, I'm struggling right now to come up with a good solution that is guaranteed not to break the YAML.

Maybe Bash isn't the right tool for the job, after all.

echo "$chart" > "$file_path"

- name: Commit and push changes
run: |
git add .
git commit -m "docs(${CHANGED_CHART%*/}): Generate documentation" # Remove trailing slash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous workflow would not create a commit if the README.md was up-to-date. This workflow will create a commit on every run, even if README.md and CHANGELOG.md are unchanged. In the best case, this will fail since --allow-empty is not passed to git commit, but it may also trigger the dreaded infinite loop in CI.

git push
47 changes: 0 additions & 47 deletions .github/workflows/update-mds.yml

This file was deleted.