Skip to content
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

Automatic changelog and version creation by triggering a new github release #143

Draft
wants to merge 7 commits into
base: rc-24.1.2
Choose a base branch
from

Conversation

cociweb
Copy link
Collaborator

@cociweb cociweb commented Oct 18, 2024

This PR enables appending the changelog.md with the content (body) of a new GitHub Release. Consequently, building and publishing can be initiated by creating a new release (tagged with v0.0.0/V0.0.0/0.0.0 format) or manually through the dispatcher. Publishing will no longer be triggered by merges or pushes.

ATTENTION!
Unfortunatelly, I'm not able to make a final test on my main branch, because the coderabbit 'hops' all the commit into this PR.

Addresses issue #163

Summary by CodeRabbit

  • New Features
    • Introduced a new automated workflow for creating changelogs and managing releases.
  • Improvements
    • Updated the changelog format for clearer version presentation.
  • Bug Fixes
    • Adjusted workflow triggers for better control over when workflows run.
  • Chores
    • Maintained existing job structures while updating workflow configurations.

Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces several modifications to GitHub Actions workflow files. The builder.yaml workflow now only allows manual execution, while lint.yaml and tester.yaml have adjustments to their triggering conditions. Additionally, a new workflow, release-notes.yaml, has been added to automate changelog creation and release management. The CHANGELOG.md has also been updated to improve formatting and maintain a history of version changes.

Changes

File Change Summary
.github/workflows/builder.yaml Removed push event trigger for main branch and version tags; kept workflow_dispatch for manual runs.
.github/workflows/lint.yaml Adjusted pull_request trigger to remove branch specification; push now only specifies main.
.github/workflows/release-notes.yaml Introduced new workflow to automate changelog creation and release management on tag pushes.
.github/workflows/tester.yaml Changed triggering condition to restrict workflow to only the main branch.
ebusd/CHANGELOG.md Updated changelog format and retained entries for versions 23.2.6 to 23.2.0 with respective updates.

Possibly related PRs

  • 23.2.6 #141: The changes in the lint.yaml workflow configuration regarding triggers are relevant as they involve modifications to GitHub Actions workflows, similar to the changes made in the builder.yaml workflow in the main PR.

Suggested reviewers

  • tjorim

Poem

In the meadow where we play,
Workflows dance and change today.
With triggers set and notes to write,
Changelogs shine, oh what a sight!
Hops of joy, we celebrate,
In code we trust, we innovate! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cociweb cociweb requested review from tjorim and LukasGrebe October 18, 2024 01:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between d8c6812 and 4d0664c.

📒 Files selected for processing (5)
  • .github/workflows/builder.yaml (0 hunks)
  • .github/workflows/lint.yaml (0 hunks)
  • .github/workflows/release-notes.yaml (1 hunks)
  • .github/workflows/tester.yaml (1 hunks)
  • ebusd/CHANGELOG.md (1 hunks)
💤 Files with no reviewable changes (2)
  • .github/workflows/builder.yaml
  • .github/workflows/lint.yaml
🧰 Additional context used
🪛 actionlint
.github/workflows/release-notes.yaml

22-22: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


22-22: shellcheck reported issue in this script: SC2001:style:8:11: See if you can use ${variable//search/replace} instead

(shellcheck)


22-22: shellcheck reported issue in this script: SC2129:style:10:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:10:54: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:11:30: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:12:22: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:13:18: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:14:15: Double quote to prevent globbing and word splitting

(shellcheck)


39-39: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


48-48: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint
.github/workflows/release-notes.yaml

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 16-16: trailing spaces

(trailing-spaces)

🪛 Markdownlint
ebusd/CHANGELOG.md

4-4: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (7)
.github/workflows/tester.yaml (1)

6-6: Verify alignment with testing strategy and PR objectives

The change to trigger the workflow only on the main branch aligns with the PR objective of changing how releases are triggered. However, this modification raises some concerns:

  1. Reduced testing frequency: By only running on the main branch, we might miss catching issues earlier in the development process on feature branches.
  2. Workflow name inconsistency: The workflow is named "Build and Test Add-on", but it now only runs on main, which might not align with a comprehensive testing strategy.

Consider the following:

  1. Is this change intentional, or should we maintain testing on feature branches as well?
  2. Should we rename the workflow to reflect its new purpose (e.g., "Build and Test Add-on for Release")?
  3. Do we need to implement additional safeguards or testing workflows for feature branches?

To verify the impact of this change, you can run the following script:

This script will help identify if there are other workflows that might be handling testing for feature branches, ensuring we maintain a robust testing strategy across the development process.

.github/workflows/release-notes.yaml (5)

13-15: LGTM! Job setup is well-defined.

The job name "release-notes" is descriptive and appropriate. Using ubuntu-latest ensures the workflow runs on an up-to-date environment.


1-76: Overall, the workflow is well-structured but has room for improvement.

The "Create Changelog and Release" workflow effectively automates the process of updating changelogs and triggering releases. Here's a summary of the main points for improvement:

  1. Enhance error handling in shell scripts, particularly in the release info extraction and file modification steps.
  2. Review and potentially limit the permissions granted to the workflow.
  3. Consider the implications of pushing changes directly to the main branch and evaluate if a pull request-based approach might be more appropriate.
  4. Verify the existence and correct configuration of the builder.yaml workflow that this workflow attempts to trigger.
  5. Improve the robustness of sed commands when handling release notes with special characters.

Addressing these points will significantly enhance the reliability and security of the workflow. Great job on automating this process, and I look forward to seeing the improvements!

🧰 Tools
🪛 actionlint

22-22: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


22-22: shellcheck reported issue in this script: SC2001:style:8:11: See if you can use ${variable//search/replace} instead

(shellcheck)


22-22: shellcheck reported issue in this script: SC2129:style:10:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:10:54: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:11:30: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:12:22: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:13:18: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:14:15: Double quote to prevent globbing and word splitting

(shellcheck)


39-39: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


48-48: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 16-16: trailing spaces

(trailing-spaces)


9-11: LGTM! Consider reviewing the necessity of both permissions.

The permissions granted are appropriate for the workflow's tasks.

However, it's a good practice to limit permissions to the minimum required. Please verify if both contents: write and actions: write are necessary for this workflow. If you can confirm that both are required, you can disregard this comment.

#!/bin/bash
# Description: Check if both permissions are used in the workflow

# Test 1: Check for operations that require contents:write
echo "Checking for contents:write usage:"
grep -n -E "git (add|commit|push)" .github/workflows/release-notes.yaml

# Test 2: Check for operations that require actions:write
echo "Checking for actions:write usage:"
grep -n -E "(workflow_dispatch|repository_dispatch)" .github/workflows/release-notes.yaml

70-76: LGTM. Verify the existence and configuration of the builder workflow.

The approach to trigger another workflow using the GitHub API is valid and well-implemented.

To ensure the reliability of this step, please verify:

  1. The existence of the builder.yaml workflow file.
  2. The correct configuration of the builder.yaml workflow to accept workflow_dispatch events.

You can use the following script to check for the existence of the builder.yaml file and its configuration:

This verification will help ensure that the triggered workflow exists and is properly configured to be dispatched by this action.

✅ Verification successful

Verified: Builder workflow exists and is properly configured for workflow_dispatch events.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and configuration of the builder workflow

# Check if builder.yaml exists
if [ -f ".github/workflows/builder.yaml" ]; then
  echo "builder.yaml exists."
  
  # Check if builder.yaml is configured for workflow_dispatch
  if grep -q "workflow_dispatch:" ".github/workflows/builder.yaml"; then
    echo "builder.yaml is configured for workflow_dispatch events."
  else
    echo "Warning: builder.yaml does not seem to be configured for workflow_dispatch events."
  fi
else
  echo "Warning: builder.yaml does not exist in the expected location."
fi

Length of output: 277


38-54: ⚠️ Potential issue

Improve error handling and consider potential sed issues.

The use of sed for file modifications is appropriate, and including error checking is good practice. However, there are some improvements we can make:

  1. Replace $? checks with direct command result checks.
  2. Consider potential issues with special characters in release notes affecting sed operation.

Here's an improved version for both steps:

# Append release notes to changelog.md
if ! sed -i "/<!-- append new version here -->/ a ## ${{ env.VERSION_WITH_PREFIX }}\n${{ env.NOTES }}\n" \
  "${{ github.workspace }}/ebusd/CHANGELOG.md"; then
  echo "Failed to update CHANGELOG.md"
  exit 1
fi

# Update version in config.yaml
if ! sed -i "s/version: .*/version: \"${{ env.VERSION }}\"/" \
  "${{ github.workspace }}/ebusd/config.yaml"; then
  echo "Failed to update config.yaml"
  exit 1
fi

Additionally, consider testing the sed commands with various types of release notes to ensure they handle special characters correctly. You might want to escape special characters in ${{ env.NOTES }} before using it in the sed command.

This script will help verify if the sed command can handle various types of release notes correctly.

✅ Verification successful

Release note handling verified successfully.

All tested sed commands handle special characters and multi-line content correctly. Additionally, adopting direct command result checks can further enhance script robustness.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test sed command with various types of release notes

# Test cases
test_notes=(
  "Simple release note"
  "Release note with special characters: $, /, &"
  "Multi-line release note
with newlines and * wildcards"
)

for note in "${test_notes[@]}"; do
  echo "Testing with note: $note"
  if ! echo "<!-- append new version here -->" | sed "/<!-- append new version here -->/ a ## v1.0.0\n$note\n"; then
    echo "Failed for note: $note"
  fi
  echo "---"
done

Length of output: 651


Script:

#!/bin/bash
# Description: Corrected script to test sed command with various types of release notes

# Initialize a temporary CHANGELOG.md file
echo "<!-- append new version here -->" > temp_CHANGELOG.md

# Test cases
test_notes=(
  "Simple release note"
  "Release note with special characters: \$, /, &"
  $'Multi-line release note\nwith newlines and * wildcards'
)

for note in "${test_notes[@]}"; do
  echo "Testing with note: $note"
  if sed "/<!-- append new version here -->/ a ## v1.0.0\n$note\n" temp_CHANGELOG.md > updated_CHANGELOG.md; then
    echo "Success for note: $note"
  else
    echo "Failed for note: $note"
  fi
  echo "---"
done

Length of output: 1431

🧰 Tools
🪛 actionlint

39-39: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


48-48: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

ebusd/CHANGELOG.md (1)

1-4: Improved changelog structure and formatting

The overall structure and formatting of the changelog have been improved:

  • The reference to Home Assistant developer documentation is helpful.
  • The placeholder for appending new versions (line 3) is a good practice for maintaining the changelog.
  • The version headers have been reformatted for better readability and consistency.

These changes align with best practices for changelog maintenance.

🧰 Tools
🪛 Markdownlint

4-4: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

.github/workflows/release-notes.yaml Show resolved Hide resolved
.github/workflows/release-notes.yaml Show resolved Hide resolved
.github/workflows/release-notes.yaml Outdated Show resolved Hide resolved
ebusd/CHANGELOG.md Show resolved Hide resolved
ebusd/CHANGELOG.md Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 4d0664c and 5757d32.

📒 Files selected for processing (1)
  • .github/workflows/release-notes.yaml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/release-notes.yaml (3)
Learnt from: cociweb
PR: LukasGrebe/ha-addons#143
File: .github/workflows/release-notes.yaml:18-36
Timestamp: 2024-10-18T01:59:29.320Z
Learning: The user prefers to keep the current code in the "Extract release notes and version" step in the `.github/workflows/release-notes.yaml` file as is, since it was previously suggested by me.
Learnt from: cociweb
PR: LukasGrebe/ha-addons#143
File: .github/workflows/release-notes.yaml:56-68
Timestamp: 2024-10-18T01:56:49.838Z
Learning: In this project, pushing changes directly to the `main` branch from GitHub Actions workflows is intentional and aligns with the team's workflow.
Learnt from: cociweb
PR: LukasGrebe/ha-addons#142
File: .github/workflows/release-notes.yaml:54-67
Timestamp: 2024-10-18T00:58:16.306Z
Learning: In the 'release-notes.yaml' workflow, direct pushes to the 'main' branch are intentional for this project.
🪛 actionlint
.github/workflows/release-notes.yaml

22-22: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


22-22: shellcheck reported issue in this script: SC2001:style:8:11: See if you can use ${variable//search/replace} instead

(shellcheck)


22-22: shellcheck reported issue in this script: SC2129:style:10:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:10:54: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:11:30: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:12:22: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:13:18: Double quote to prevent globbing and word splitting

(shellcheck)


22-22: shellcheck reported issue in this script: SC2086:info:14:15: Double quote to prevent globbing and word splitting

(shellcheck)


39-39: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


48-48: shellcheck reported issue in this script: SC2181:style:3:6: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint
.github/workflows/release-notes.yaml

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 16-16: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/release-notes.yaml (1)

1-12: 🧹 Nitpick (assertive)

LGTM! Fix minor formatting issue.

The workflow configuration is well-structured with appropriate permissions and trigger conditions. However, there's a minor formatting issue to address.

Fix the trailing whitespace:

 jobs:
   release-notes:
     runs-on: ubuntu-latest
-    
+
     steps:

Likely invalid or redundant comment.

🧰 Tools
🪛 yamllint

[warning] 3-3: truthy value should be one of [false, true]

(truthy)

.github/workflows/release-notes.yaml Show resolved Hide resolved
.github/workflows/release-notes.yaml Show resolved Hide resolved
.github/workflows/release-notes.yaml Show resolved Hide resolved
@cociweb
Copy link
Collaborator Author

cociweb commented Oct 22, 2024

@tjorim, could you please apply this patch to your updated fork and then create a new github release (with tag pattern of v0.0.0/V0.0.0/0.0.0) ? To ensure the PR does not introduce further issues according to the patch, consider making a release prior to applying the patch as well. Unfortunately, Lukas unable to test it, as it impacts the main branch. I've tested it previously on my main branch, but a confirmation would be beneficial.

As part of the pass criteria, the CHANGELOG.md must be updated to include the body text of the new release in markdown format, and the config.yaml must reflect the tag name in its version record.

@cociweb
Copy link
Collaborator Author

cociweb commented Oct 27, 2024

@tjorim @LukasGrebe

the ebusd 24.1 is in the tube. Can we merge this before we release that?

@tjorim
Copy link
Collaborator

tjorim commented Oct 27, 2024

I should have some time tonight or tomorrow to test out this PR so we are ready to ship once the alpine package bump is merged.

@cociweb
Copy link
Collaborator Author

cociweb commented Nov 11, 2024

@tjorim Do You have any feedback?

Copy link
Collaborator

@tjorim tjorim left a comment

Choose a reason for hiding this comment

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

I could see the use case but not convinced of the benefit.
Just tried it once use the 'Generate release notes' when drafting a new release, and it already failed because I used a * for formatting? https://github.com/tjorim/ebusd-ha_addons-cociweb/actions/runs/12165947177/job/33931075696

For me the extra code that could break don't tip the scale over just copying and pasting it into a file after drafting a release.

Comment on lines 5 to 6
branches:
- main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
branches:
- main

I guess we also don't need this.

@@ -0,0 +1,76 @@
name: Create Changelog and Release
# Trigger on tags matching the format: v0.0.0, V0.0.0, or 0.0.0
Copy link
Collaborator

@tjorim tjorim Dec 4, 2024

Choose a reason for hiding this comment

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

Do we want to trigger on all of these?
I think for consistency we should stick to a single format.
Or maybe just switch to Calendar Versioning like HA itself did?

Copy link
Owner

Choose a reason for hiding this comment

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

with #159 i updated the versioning to follow ebusd's ..

@cociweb
Copy link
Collaborator Author

cociweb commented Dec 12, 2024

@tjorim Thanks for checking this. I'm afraid, that the relase 'This is a test release' does not fit to the pattern of x.x.x (which is required to parse the version into the config file and to the release notes.)

@LukasGrebe

This comment was marked as resolved.

@LukasGrebe LukasGrebe changed the base branch from main to rc-24.1.2 January 10, 2025 19:09
@cociweb cociweb marked this pull request as draft January 10, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants