Skip to content
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
142 changes: 142 additions & 0 deletions .github/workflows/bump-hl2sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Bump hl2sdk

on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
check-and-bump:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Get current submodule commit
id: current
run: |
cd libraries/hl2sdk-cs2
CURRENT_COMMIT="$(git rev-parse HEAD)"
echo "commit=$CURRENT_COMMIT" >> "$GITHUB_OUTPUT"
echo "Current hl2sdk commit: $CURRENT_COMMIT"

- name: Fetch latest hl2sdk cs2 branch
id: latest
run: |
LATEST_COMMIT="$(git ls-remote https://github.com/alliedmodders/hl2sdk refs/heads/cs2 | cut -f1)"
if [ -z "${LATEST_COMMIT}" ]; then
echo "::error::Failed to fetch latest commit from hl2sdk"
exit 1
fi
echo "commit=$LATEST_COMMIT" >> "$GITHUB_OUTPUT"
echo "Latest hl2sdk cs2 commit: $LATEST_COMMIT"

- name: Check if update is needed
id: check
run: |
if [ "${{ steps.current.outputs.commit }}" = "${{ steps.latest.outputs.commit }}" ]; then
echo "needs_update=false" >> "$GITHUB_OUTPUT"
echo "hl2sdk is already up to date"
else
echo "needs_update=true" >> "$GITHUB_OUTPUT"
echo "hl2sdk update available!"
fi

- name: Check for existing PR
id: existing_pr
if: steps.check.outputs.needs_update == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2016:info:7:71: Expressions don't expand in single quotes, use double quotes for that [shellcheck]

EXISTING_PR="$(gh pr list --state open --head "chore/bump-hl2sdk" --json number,body --jq '.[0] // empty')"
if [ -n "${EXISTING_PR}" ]; then
PR_NUMBER="$(echo "${EXISTING_PR}" | jq -r '.number')"
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "Existing PR found: #$PR_NUMBER"

EXISTING_TARGET="$(echo "${EXISTING_PR}" | jq -r '.body' | grep -oP '(?<=\*\*To:\*\* `)[a-f0-9]+(?=`)' || true)"
if [ "${EXISTING_TARGET}" = "${{ steps.latest.outputs.commit }}" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Existing PR already targets latest commit, skipping"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "Existing PR needs update"
fi
else
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "No existing PR found"
fi

- name: Update submodule
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true'
run: |
cd libraries/hl2sdk-cs2
git fetch origin cs2
git checkout ${{ steps.latest.outputs.commit }}
cd ../..
echo "Updated hl2sdk to ${{ steps.latest.outputs.commit }}"

- name: Get commit details
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true'
id: commit_info
run: |
Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:10:33: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:11:29: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:12:32: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:7:24: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:8:23: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

📝 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2086:info:9:15: Double quote to prevent globbing and word splitting [shellcheck]

Copy link

Choose a reason for hiding this comment

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

🚫 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2129:style:7:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects [shellcheck]

cd libraries/hl2sdk-cs2
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an")
COMMIT_DATE=$(git log -1 --pretty=format:"%ci")
SHORT_SHA=$(git rev-parse --short HEAD)

echo "message<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "author=$COMMIT_AUTHOR" >> $GITHUB_OUTPUT
echo "date=$COMMIT_DATE" >> $GITHUB_OUTPUT
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT

git log --oneline ${{ steps.current.outputs.commit }}..${{ steps.latest.outputs.commit }} | head -20 > /tmp/commits.txt

- name: Generate PR body
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true'
run: |
mkdir -p .github
{
echo "Automated PR to update hl2sdk submodule."
echo ""
echo "## Changes"
echo "- **From:** \`${{ steps.current.outputs.commit }}\`"
echo "- **To:** \`${{ steps.latest.outputs.commit }}\`"
echo ""
echo "## Commits in this update"
echo '```'
cat /tmp/commits.txt
echo '```'
echo ""
echo "## Latest commit info"
echo "- **Message:** ${{ steps.commit_info.outputs.message }}"
echo "- **Author:** ${{ steps.commit_info.outputs.author }}"
echo "- **Date:** ${{ steps.commit_info.outputs.date }}"
echo ""
echo "---"
echo "🤖 This PR was automatically created by the [bump-hl2sdk workflow](https://github.com/${{ github.repository }}/actions/workflows/bump-hl2sdk.yml)."
} > .github/pr-body.md

- name: Create or update Pull Request
if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore(deps): bump hl2sdk to ${{ steps.commit_info.outputs.short_sha }}"
branch: chore/bump-hl2sdk
delete-branch: true
title: "chore(deps): bump hl2sdk to ${{ steps.commit_info.outputs.short_sha }}"
body-path: .github/pr-body.md
labels: |
dependencies
automated
Loading