-
Notifications
You must be signed in to change notification settings - Fork 2
chore(repo): Auto-generate changelog per chart #40
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
base: main
Are you sure you want to change the base?
Changes from all commits
652e189
57d594a
c147897
8d625a5
443246a
da0f41b
1a5890c
8236211
d0315fa
266b202
c4d6e05
3bd4562
592bb3e
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,135 @@ | ||||||||||||||||||||||||||
| name: Update documentation | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||
| pull_request_target: | ||||||||||||||||||||||||||
| branches: | ||||||||||||||||||||||||||
| - main | ||||||||||||||||||||||||||
| 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: | | ||||||||||||||||||||||||||
|
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: | ||||||||||||||||||||||||||
|
lusu007 marked this conversation as resolved.
|
||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||
| contents: write | ||||||||||||||||||||||||||
| needs: gather-information | ||||||||||||||||||||||||||
| if: ${{ needs.gather-information.outputs.failed != 'true' }} | ||||||||||||||||||||||||||
|
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" | ||||||||||||||||||||||||||
|
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
Member
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. 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
Member
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've never seen this syntax before... What does the second $ do, and why are there no quotes surrounding
Member
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. 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
Member
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. Wouldn't this work? (Besides generating invalid YAML if the PR title contains quotes or backslashes)
Suggested change
|
||||||||||||||||||||||||||
| 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
Member
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'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 | ||||||||||||||||||||||||||
|
Member
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 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 |
||||||||||||||||||||||||||
| git push | ||||||||||||||||||||||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.