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

Update actions #39

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Update actions #39

merged 1 commit into from
Dec 6, 2024

Conversation

allthings-bot
Copy link
Member

@allthings-bot allthings-bot commented Dec 3, 2024

Update actions from workflow

Summary by CodeRabbit

  • New Features
    • Introduced a new GitHub Action named version-tag for automating Git version tagging.
    • Added an optional input parameter trigger-workflow-name to trigger additional workflows after tagging.

Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request introduces a new GitHub Action named version-tag, defined in the file .github/actions/version-tag/action.yml. This action automates the process of creating a Git version tag, with an optional input parameter to trigger another workflow after tagging. It includes steps for setting the Git environment, creating and pushing the new tag, and handling errors during execution.

Changes

File Path Change Summary
.github/actions/version-tag/action.yml Added a new GitHub Action version-tag with an optional input parameter trigger-workflow-name.

Possibly related PRs

  • Update actions #22: This PR updates actions in the workflow, which may relate to the new GitHub Action defined in the main PR.
  • Update actions #25: Similar to Update actions #22, this PR also updates actions, potentially impacting the workflow where the new version-tag action is introduced.
  • Update actions #26: This PR introduces new actions, which could be relevant as they may interact with the new version-tag action.
  • Update actions #28: This PR updates actions in the workflow, which could be related to the integration of the new version-tag action.
  • Update actions #30: This PR focuses on updating actions, which may include changes that affect the new version-tag action.
  • Update actions #33: This PR introduces a new action that may interact with the version-tag action in the workflow.
  • Update actions #34: This PR adds a new input parameter to an action, which could relate to how the version-tag action is utilized.
  • Update actions #36: This PR modifies the docker-tag action, which may have implications for how version tagging is handled in conjunction with the new version-tag action.
  • Update actions #37: This PR adds an environment variable that could be relevant to the context in which the version-tag action operates.

Suggested reviewers

  • DmitryMarkov

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.

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.

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: 4

🧹 Outside diff range and nitpick comments (2)
.github/actions/version-tag/action.yml (2)

1-8: Consider making documentation publicly accessible

The referenced documentation URL points to a private repository (allthings/github-action-tools). Consider either making the documentation public or including essential documentation directly in this file to ensure users can understand and use the action effectively.


22-41: Consider concurrent execution safety

The current implementation might face race conditions if multiple workflows attempt to create version tags simultaneously.

Consider these approaches to handle concurrent execution:

  1. Use GitHub Actions concurrency controls to ensure only one instance runs at a time:
concurrency: 
  group: version-tag
  cancel-in-progress: false
  1. Implement a locking mechanism using GitHub API
  2. Use GitHub's branch protection rules to prevent concurrent tag creation
🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)


[error] 39-39: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d659cf3 and b63350a.

📒 Files selected for processing (1)
  • .github/actions/version-tag/action.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/actions/version-tag/action.yml

[error] 31-31: trailing spaces

(trailing-spaces)


[error] 39-39: trailing spaces

(trailing-spaces)

Comment on lines +12 to +20
- name: Set PATH
shell: bash
run: |
echo "/bin" >> $GITHUB_PATH
echo "/sbin" >> $GITHUB_PATH
echo "/usr/bin" >> $GITHUB_PATH
echo "/usr/sbin" >> $GITHUB_PATH
echo "/usr/local/bin" >> $GITHUB_PATH
echo "/usr/local/sbin" >> $GITHUB_PATH
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider PATH modification approach

Adding standard system directories to GITHUB_PATH is unnecessary as these paths are typically already included in the default PATH of GitHub Actions runners. This approach might mask underlying PATH-related issues rather than addressing them properly.

Consider removing this step unless there's a specific documented reason for including it. If you're experiencing PATH-related issues, it would be better to:

  1. Debug the specific command that's failing
  2. Use absolute paths for critical commands
  3. Document why this PATH modification is necessary if it must be kept

Comment on lines +27 to +33
set +e
git config user.name "Bot"
git config user.email "admin@allthings.me"
currentVersion="$(git describe --tags `git rev-list --tags --max-count=1`)"
if [ "$currentVersion" = "" ]; then
currentVersion="v0.0.0"
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve error handling and version initialization

While set +e is used, the script doesn't check for errors after critical git commands. Also, the version initialization could be more robust.

Consider this improved implementation:

-        set +e
-        git config user.name "Bot"
-        git config user.email "admin@allthings.me"
-        currentVersion="$(git describe --tags `git rev-list --tags --max-count=1`)"
-        if [ "$currentVersion" = "" ]; then 
-          currentVersion="v0.0.0"
-        fi
+        set -e  # Fail fast on errors
+        git config user.name "Allthings Bot"
+        git config user.email "admin@allthings.me"
+        
+        # Get latest version tag with error handling
+        if ! currentVersion=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null); then
+          echo "No existing tags found, initializing with v0.0.0"
+          currentVersion="v0.0.0"
+        fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set +e
git config user.name "Bot"
git config user.email "admin@allthings.me"
currentVersion="$(git describe --tags `git rev-list --tags --max-count=1`)"
if [ "$currentVersion" = "" ]; then
currentVersion="v0.0.0"
fi
set -e # Fail fast on errors
git config user.name "Allthings Bot"
git config user.email "admin@allthings.me"
# Get latest version tag with error handling
if ! currentVersion=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null); then
echo "No existing tags found, initializing with v0.0.0"
currentVersion="v0.0.0"
fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)

Comment on lines +34 to +37
latestVersion="${currentVersion//v[0-9]*.[0-9]*./}"
((++latestVersion))
newVersion="${currentVersion%.*}.$latestVersion"
git tag -a $newVersion -m "Release new version: $newVersion"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Strengthen version parsing and increment logic

The current version parsing is fragile and could break with unexpected version formats. It also doesn't validate the version structure.

Consider using a more robust version parsing approach:

-        latestVersion="${currentVersion//v[0-9]*.[0-9]*./}"
-        ((++latestVersion))
-        newVersion="${currentVersion%.*}.$latestVersion"
+        # Validate and parse semantic version
+        if [[ ! $currentVersion =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+          echo "Error: Current version $currentVersion doesn't match expected format (vX.Y.Z)"
+          exit 1
+        fi
+        
+        # Parse version components
+        major=$(echo $currentVersion | cut -d. -f1 | tr -d 'v')
+        minor=$(echo $currentVersion | cut -d. -f2)
+        patch=$(echo $currentVersion | cut -d. -f3)
+        
+        # Increment patch version
+        newVersion="v$major.$minor.$((patch + 1))"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
latestVersion="${currentVersion//v[0-9]*.[0-9]*./}"
((++latestVersion))
newVersion="${currentVersion%.*}.$latestVersion"
git tag -a $newVersion -m "Release new version: $newVersion"
# Validate and parse semantic version
if [[ ! $currentVersion =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Current version $currentVersion doesn't match expected format (vX.Y.Z)"
exit 1
fi
# Parse version components
major=$(echo $currentVersion | cut -d. -f1 | tr -d 'v')
minor=$(echo $currentVersion | cut -d. -f2)
patch=$(echo $currentVersion | cut -d. -f3)
# Increment patch version
newVersion="v$major.$minor.$((patch + 1))"
git tag -a $newVersion -m "Release new version: $newVersion"

Comment on lines +38 to +41
git push origin $newVersion
if [ ! -z "${{ env.WORKFLOW_NAME }}" ]; then
gh workflow run ${{ env.WORKFLOW_NAME }} --ref $newVersion
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add safeguards for tag creation and workflow triggering

The current implementation doesn't handle tag conflicts or verify workflow existence before triggering.

Consider adding these safety checks:

-        git tag -a $newVersion -m "Release new version: $newVersion"
-        git push origin $newVersion
-        if [ ! -z "${{ env.WORKFLOW_NAME }}" ]; then 
-          gh workflow run ${{ env.WORKFLOW_NAME }} --ref $newVersion
-        fi
+        # Check if tag already exists
+        if git rev-parse "$newVersion" >/dev/null 2>&1; then
+          echo "Error: Tag $newVersion already exists"
+          exit 1
+        fi
+
+        # Create and push tag with error handling
+        if ! git tag -a "$newVersion" -m "Release new version: $newVersion"; then
+          echo "Error: Failed to create tag $newVersion"
+          exit 1
+        fi
+
+        if ! git push origin "$newVersion"; then
+          echo "Error: Failed to push tag $newVersion"
+          git tag -d "$newVersion"  # Clean up local tag
+          exit 1
+        fi
+
+        # Trigger workflow if specified
+        if [ -n "$WORKFLOW_NAME" ]; then
+          if ! gh workflow list | grep -q "^$WORKFLOW_NAME"; then
+            echo "Error: Workflow $WORKFLOW_NAME not found"
+            exit 1
+          fi
+          if ! gh workflow run "$WORKFLOW_NAME" --ref "$newVersion"; then
+            echo "Error: Failed to trigger workflow $WORKFLOW_NAME"
+            exit 1
+          fi
+        fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
git push origin $newVersion
if [ ! -z "${{ env.WORKFLOW_NAME }}" ]; then
gh workflow run ${{ env.WORKFLOW_NAME }} --ref $newVersion
fi
# Check if tag already exists
if git rev-parse "$newVersion" >/dev/null 2>&1; then
echo "Error: Tag $newVersion already exists"
exit 1
fi
# Create and push tag with error handling
if ! git tag -a "$newVersion" -m "Release new version: $newVersion"; then
echo "Error: Failed to create tag $newVersion"
exit 1
fi
if ! git push origin "$newVersion"; then
echo "Error: Failed to push tag $newVersion"
git tag -d "$newVersion" # Clean up local tag
exit 1
fi
# Trigger workflow if specified
if [ -n "$WORKFLOW_NAME" ]; then
if ! gh workflow list | grep -q "^$WORKFLOW_NAME"; then
echo "Error: Workflow $WORKFLOW_NAME not found"
exit 1
fi
if ! gh workflow run "$WORKFLOW_NAME" --ref "$newVersion"; then
echo "Error: Failed to trigger workflow $WORKFLOW_NAME"
exit 1
fi
fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 39-39: trailing spaces

(trailing-spaces)

@DmitryMarkov DmitryMarkov merged commit 4a62c65 into master Dec 6, 2024
4 checks passed
@DmitryMarkov DmitryMarkov deleted the actions-spreader-12137651992 branch December 6, 2024 14:58
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