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
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
41 changes: 41 additions & 0 deletions .github/actions/version-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# You can find code and docs here: https://github.com/allthings/github-action-tools
name: version-tag
description: 'Creates a git version tag'
inputs:
trigger-workflow-name:
description: 'Name of workflow that is triggered after creating tag'
required: false

runs:
using: "composite"
steps:
- 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
Comment on lines +12 to +20
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


- name: create new tag
shell: bash
env:
WORKFLOW_NAME: ${{ inputs.trigger-workflow-name }}
run: |
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
Comment on lines +27 to +33
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)

latestVersion="${currentVersion//v[0-9]*.[0-9]*./}"
((++latestVersion))
newVersion="${currentVersion%.*}.$latestVersion"
git tag -a $newVersion -m "Release new version: $newVersion"
Comment on lines +34 to +37
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"

git push origin $newVersion
if [ ! -z "${{ env.WORKFLOW_NAME }}" ]; then
gh workflow run ${{ env.WORKFLOW_NAME }} --ref $newVersion
fi
Comment on lines +38 to +41
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)

Loading