Skip to content
Open
Show file tree
Hide file tree
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
152 changes: 152 additions & 0 deletions .github/actions/update-cmake-dep/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Update CMake Dependency
description: Checks for updates to a GitHub-hosted dependency and creates a PR to update the cmake file

inputs:
repo:
description: 'GitHub repository (owner/repo format, e.g., "c-ares/c-ares")'
required: true
cmake-file:
description: 'Path to the cmake file to update (e.g., "cmake/targets/BuildCares.cmake")'
required: true
dep-name:
description: 'Dependency name for commit messages (e.g., "c-ares")'
required: true
workflow-file:
description: 'Name of the workflow file for the PR body link'
required: true

outputs:
current:
description: 'Current commit SHA'
value: ${{ steps.check-version.outputs.current }}
latest:
description: 'Latest commit SHA'
value: ${{ steps.check-version.outputs.latest }}
tag:
description: 'Latest release tag'
value: ${{ steps.check-version.outputs.tag }}
updated:
description: 'Whether an update was made'
value: ${{ steps.check-version.outputs.current != steps.check-version.outputs.latest }}

runs:
using: composite
steps:
- name: Check version
id: check-version
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# Helper function for authenticated GitHub API calls
gh_api() {
curl -sL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$1"
}
# Extract the commit hash from the line after COMMIT
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' "${{ inputs.cmake-file }}")
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in ${{ inputs.cmake-file }}"
exit 1
fi
# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in ${{ inputs.cmake-file }}"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
fi
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
Comment on lines +48 to +64
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider documenting the expected CMake file format.

The awk pattern assumes a specific structure: the COMMIT keyword alone on one line, followed by the hash on the next line. While this works for the current use case, the tight coupling to this format could be brittle if CMake files vary.

Consider adding a comment documenting the expected format, or handle potential variations (e.g., inline COMMIT <hash>).

📝 Example documentation addition
+        # Extract commit hash from CMake file
+        # Expected format:
+        #   COMMIT
+        #   <40-char-hex-hash>
         CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' "${{ inputs.cmake-file }}")
📝 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
# Extract the commit hash from the line after COMMIT
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' "${{ inputs.cmake-file }}")
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in ${{ inputs.cmake-file }}"
exit 1
fi
# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in ${{ inputs.cmake-file }}"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
fi
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Extract commit hash from CMake file
# Expected format:
# COMMIT
# <40-char-hex-hash>
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' "${{ inputs.cmake-file }}")
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in ${{ inputs.cmake-file }}"
exit 1
fi
# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in ${{ inputs.cmake-file }}"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
fi
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
🤖 Prompt for AI Agents
In .github/actions/update-cmake-dep/action.yml around lines 48 to 64, the awk
extraction assumes the CMake file has a line with only "COMMIT" and the hash on
the next line which is brittle; update the file to (1) add a concise comment
documenting the expected CMake snippet formats (both "COMMIT" on its own line
followed by the hash and the alternative inline form "COMMIT <hash>"), and (2)
make the extraction more robust to handle both forms (detect and extract an
inline hash after COMMIT or the following-line hash, trimming whitespace) and
keep the existing 40-hex validation afterwards.

LATEST_RELEASE=$(gh_api "https://api.github.com/repos/${{ inputs.repo }}/releases/latest")
if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Failed to fetch latest release from GitHub API"
exit 1
fi
LATEST_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" = "null" ]; then
echo "Error: Could not extract tag name from GitHub API response"
exit 1
fi
# URL-encode the tag name for API requests
ENCODED_TAG=$(printf '%s' "$LATEST_TAG" | jq -sRr @uri)
# Get the tag reference to determine if it's annotated or lightweight
TAG_REF=$(gh_api "https://api.github.com/repos/${{ inputs.repo }}/git/refs/tags/$ENCODED_TAG")
if [ -z "$TAG_REF" ]; then
echo "Error: Could not fetch tag reference for $LATEST_TAG"
exit 1
fi
TAG_OBJECT_SHA=$(echo "$TAG_REF" | jq -r '.object.sha')
TAG_OBJECT_TYPE=$(echo "$TAG_REF" | jq -r '.object.type')
if [ -z "$TAG_OBJECT_SHA" ] || [ "$TAG_OBJECT_SHA" = "null" ]; then
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
exit 1
fi
# Handle both lightweight tags (type: commit) and annotated tags (type: tag)
if [ "$TAG_OBJECT_TYPE" = "commit" ]; then
# Lightweight tag - object.sha is already the commit SHA
LATEST_SHA="$TAG_OBJECT_SHA"
elif [ "$TAG_OBJECT_TYPE" = "tag" ]; then
# Annotated tag - need to fetch the tag object to get the commit SHA
LATEST_SHA=$(gh_api "https://api.github.com/repos/${{ inputs.repo }}/git/tags/$TAG_OBJECT_SHA" | jq -r '.object.sha')
if [ -z "$LATEST_SHA" ] || [ "$LATEST_SHA" = "null" ]; then
echo "Error: Could not fetch commit SHA for annotated tag $LATEST_TAG @ $TAG_OBJECT_SHA"
exit 1
fi
else
echo "Error: Unexpected tag object type: $TAG_OBJECT_TYPE"
exit 1
fi
if ! [[ $LATEST_SHA =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid SHA format received from GitHub"
echo "Found: $LATEST_SHA"
echo "Expected: 40 character hexadecimal string"
exit 1
fi
echo "latest=$LATEST_SHA" >> $GITHUB_OUTPUT
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Current: $CURRENT_VERSION"
echo "Latest: $LATEST_SHA ($LATEST_TAG)"
- name: Update version if needed
if: steps.check-version.outputs.current != steps.check-version.outputs.latest
shell: bash
run: |
set -euo pipefail
# Handle multi-line format where COMMIT and its value are on separate lines
# Preserve original indentation by capturing and reusing it
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/^([[:space:]]*)[0-9a-f]+[[:space:]]*$/\1${{ steps.check-version.outputs.latest }}/}' "${{ inputs.cmake-file }}"
- name: Create Pull Request
if: steps.check-version.outputs.current != steps.check-version.outputs.latest
uses: peter-evans/create-pull-request@v7
with:
token: ${{ github.token }}
add-paths: |
${{ inputs.cmake-file }}
commit-message: "deps: update ${{ inputs.dep-name }} to ${{ steps.check-version.outputs.tag }} (${{ steps.check-version.outputs.latest }})"
title: "deps: update ${{ inputs.dep-name }} to ${{ steps.check-version.outputs.tag }}"
delete-branch: true
branch: deps/update-${{ inputs.dep-name }}-${{ github.run_number }}
body: |
## What does this PR do?
Updates ${{ inputs.dep-name }} to version ${{ steps.check-version.outputs.tag }}
Compare: https://github.com/${{ inputs.repo }}/compare/${{ steps.check-version.outputs.current }}...${{ steps.check-version.outputs.latest }}
Auto-updated by [this workflow](https://github.com/oven-sh/bun/actions/workflows/${{ inputs.workflow-file }})
86 changes: 5 additions & 81 deletions .github/workflows/update-cares.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Check c-ares version
id: check-version
run: |
set -euo pipefail

# Extract the commit hash from the line after COMMIT
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' cmake/targets/BuildCares.cmake)

if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in BuildCares.cmake"
exit 1
fi

# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in BuildCares.cmake"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
fi

echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT

LATEST_RELEASE=$(curl -sL https://api.github.com/repos/c-ares/c-ares/releases/latest)
if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Failed to fetch latest release from GitHub API"
exit 1
fi

LATEST_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" = "null" ]; then
echo "Error: Could not extract tag name from GitHub API response"
exit 1
fi

LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
exit 1
fi
LATEST_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/tags/$LATEST_TAG_SHA" | jq -r '.object.sha')
if [ -z "$LATEST_SHA" ] || [ "$LATEST_SHA" = "null" ]; then
echo "Error: Could not fetch SHA for tag $LATEST_TAG @ $LATEST_TAG_SHA"
exit 1
fi

if ! [[ $LATEST_SHA =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid SHA format received from GitHub"
echo "Found: $LATEST_SHA"
echo "Expected: 40 character hexadecimal string"
exit 1
fi

echo "latest=$LATEST_SHA" >> $GITHUB_OUTPUT
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT

- name: Update version if needed
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
run: |
set -euo pipefail
# Handle multi-line format where COMMIT and its value are on separate lines
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/[[:space:]]*([0-9a-f]+)[[:space:]]*$/ ${{ steps.check-version.outputs.latest }}/}' cmake/targets/BuildCares.cmake

- name: Create Pull Request
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
uses: peter-evans/create-pull-request@v7
- uses: ./.github/actions/update-cmake-dep
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
cmake/targets/BuildCares.cmake
commit-message: "deps: update c-ares to ${{ steps.check-version.outputs.tag }} (${{ steps.check-version.outputs.latest }})"
title: "deps: update c-ares to ${{ steps.check-version.outputs.tag }}"
delete-branch: true
branch: deps/update-cares-${{ github.run_number }}
body: |
## What does this PR do?

Updates c-ares to version ${{ steps.check-version.outputs.tag }}

Compare: https://github.com/c-ares/c-ares/compare/${{ steps.check-version.outputs.current }}...${{ steps.check-version.outputs.latest }}

Auto-updated by [this workflow](https://github.com/oven-sh/bun/actions/workflows/update-cares.yml)
repo: "c-ares/c-ares"
cmake-file: "cmake/targets/BuildCares.cmake"
dep-name: "c-ares"
workflow-file: "update-cares.yml"
89 changes: 5 additions & 84 deletions .github/workflows/update-hdrhistogram.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,88 +15,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Check hdrhistogram version
id: check-version
run: |
set -euo pipefail

# Extract the commit hash from the line after COMMIT
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' cmake/targets/BuildHdrHistogram.cmake)

if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in BuildHdrHistogram.cmake"
exit 1
fi

# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in BuildHdrHistogram.cmake"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
fi

echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT

LATEST_RELEASE=$(curl -sL https://api.github.com/repos/HdrHistogram/HdrHistogram_c/releases/latest)
if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Failed to fetch latest release from GitHub API"
exit 1
fi

LATEST_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" = "null" ]; then
echo "Error: Could not extract tag name from GitHub API response"
exit 1
fi

LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/HdrHistogram/HdrHistogram_c/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
exit 1
fi

# Try to get commit SHA from tag object (for annotated tags)
# If it fails, assume it's a lightweight tag pointing directly to commit
LATEST_SHA=$(curl -sL "https://api.github.com/repos/HdrHistogram/HdrHistogram_c/git/tags/$LATEST_TAG_SHA" 2>/dev/null | jq -r '.object.sha // empty')
if [ -z "$LATEST_SHA" ]; then
# Lightweight tag - SHA points directly to commit
LATEST_SHA="$LATEST_TAG_SHA"
fi

if ! [[ $LATEST_SHA =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid SHA format received from GitHub"
echo "Found: $LATEST_SHA"
echo "Expected: 40 character hexadecimal string"
exit 1
fi

echo "latest=$LATEST_SHA" >> $GITHUB_OUTPUT
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT

- name: Update version if needed
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
run: |
set -euo pipefail
# Handle multi-line format where COMMIT and its value are on separate lines
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/[[:space:]]*([0-9a-f]+)[[:space:]]*$/ ${{ steps.check-version.outputs.latest }}/}' cmake/targets/BuildHdrHistogram.cmake

- name: Create Pull Request
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
uses: peter-evans/create-pull-request@v7
- uses: ./.github/actions/update-cmake-dep
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
cmake/targets/BuildHdrHistogram.cmake
commit-message: "deps: update hdrhistogram to ${{ steps.check-version.outputs.tag }} (${{ steps.check-version.outputs.latest }})"
title: "deps: update hdrhistogram to ${{ steps.check-version.outputs.tag }}"
delete-branch: true
branch: deps/update-hdrhistogram-${{ github.run_number }}
body: |
## What does this PR do?

Updates hdrhistogram to version ${{ steps.check-version.outputs.tag }}

Compare: https://github.com/HdrHistogram/HdrHistogram_c/compare/${{ steps.check-version.outputs.current }}...${{ steps.check-version.outputs.latest }}

Auto-updated by [this workflow](https://github.com/oven-sh/bun/actions/workflows/update-hdrhistogram.yml)
repo: "HdrHistogram/HdrHistogram_c"
cmake-file: "cmake/targets/BuildHdrHistogram.cmake"
dep-name: "hdrhistogram"
workflow-file: "update-hdrhistogram.yml"
Loading