-
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?
Conversation
|
I doubt this is needed. It can just be "docs(chart): Generate documentation" for example. No need to overcomplicate. |
Co-authored-by: Fabian Meyer <3982806+meyfa@users.noreply.github.com>
meyfa
left a comment
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.
The workflow is currently vulnerable to at least one practical attack. Please make sure that all user input is quoted and validated before being used in a shell.
| changes="$changes"$'\n' - kind: feature | ||
| changes="$changes"$'\n' description: "${PR_TITLE#*: }" |
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.
I've never seen this syntax before... What does the second $ do, and why are there no quotes surrounding - kind: feature etc?
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.
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.
| changes="$changes"$'\n' - kind: feature | ||
| changes="$changes"$'\n' description: "${PR_TITLE#*: }" |
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.
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.
| 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 |
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.
Wouldn't this work? (Besides generating invalid YAML if the PR title contains quotes or backslashes)
| 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 |
| # 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/^/ /') |
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.
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 "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" |
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 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: Commit and push changes | ||
| run: | | ||
| git add . | ||
| git commit -m "docs(${CHANGED_CHART%*/}): Generate documentation" # Remove trailing slash |
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.
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.
Fixes #32
Fixes #27
Additional Context
N/A
Checklist
feat(chart-name): Add replica support