From 5347ab0e2e18acd5b4c6c3c6e5b017692840bb42 Mon Sep 17 00:00:00 2001 From: dollan Date: Sat, 6 Dec 2025 23:44:06 +0100 Subject: [PATCH 1/4] ci: add hl2sdk bump workflow --- .github/workflows/bump-hl2sdk.yml | 127 ++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 .github/workflows/bump-hl2sdk.yml diff --git a/.github/workflows/bump-hl2sdk.yml b/.github/workflows/bump-hl2sdk.yml new file mode 100644 index 000000000..bb8829492 --- /dev/null +++ b/.github/workflows/bump-hl2sdk.yml @@ -0,0 +1,127 @@ +name: Bump hl2sdk + +on: + schedule: + # Run every 15 minutes + - cron: "*/15 * * * *" + workflow_dispatch: # Allow manual trigger + +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) + 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: | + # Check if there's already an open PR for hl2sdk bump + EXISTING_PR=$(gh pr list --state open --head "chore/bump-hl2sdk" --json number --jq '.[0].number // empty') + if [ -n "$EXISTING_PR" ]; then + echo "has_existing_pr=true" >> $GITHUB_OUTPUT + echo "pr_number=$EXISTING_PR" >> $GITHUB_OUTPUT + echo "Existing PR found: #$EXISTING_PR" + else + echo "has_existing_pr=false" >> $GITHUB_OUTPUT + echo "No existing PR found" + fi + + - name: Update submodule + if: steps.check.outputs.needs_update == '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' + id: commit_info + run: | + 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=$COMMIT_MSG" >> $GITHUB_OUTPUT + echo "author=$COMMIT_AUTHOR" >> $GITHUB_OUTPUT + echo "date=$COMMIT_DATE" >> $GITHUB_OUTPUT + echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT + + # Get recent commits for PR body (last 10 since previous) + cd ../.. + echo "COMMITS<> $GITHUB_OUTPUT + cd libraries/hl2sdk-cs2 + git log --oneline ${{ steps.current.outputs.commit }}..${{ steps.latest.outputs.commit }} | head -20 >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create or update Pull Request + if: steps.check.outputs.needs_update == '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: | + Automated PR to update hl2sdk submodule. + + ## Changes + - **From:** `${{ steps.current.outputs.commit }}` + - **To:** `${{ steps.latest.outputs.commit }}` + + ## Recent hl2sdk commits + ``` + ${{ steps.commit_info.outputs.COMMITS }} + ``` + + ## Latest commit info + - **Message:** ${{ steps.commit_info.outputs.message }} + - **Author:** ${{ steps.commit_info.outputs.author }} + - **Date:** ${{ steps.commit_info.outputs.date }} + + --- + 🤖 This PR was automatically created by the [bump-hl2sdk workflow](https://github.com/${{ github.repository }}/actions/workflows/bump-hl2sdk.yml). + labels: | + dependencies + automated From 1aac7800a1b2e28b64f3c884ed8c199438057802 Mon Sep 17 00:00:00 2001 From: dollan Date: Sun, 7 Dec 2025 00:15:08 +0100 Subject: [PATCH 2/4] Rename it to better reflect actual output --- .github/workflows/bump-hl2sdk.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bump-hl2sdk.yml b/.github/workflows/bump-hl2sdk.yml index bb8829492..d2ecef151 100644 --- a/.github/workflows/bump-hl2sdk.yml +++ b/.github/workflows/bump-hl2sdk.yml @@ -87,7 +87,7 @@ jobs: echo "date=$COMMIT_DATE" >> $GITHUB_OUTPUT echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT - # Get recent commits for PR body (last 10 since previous) + # Get commits in this update for PR body (last 20) cd ../.. echo "COMMITS<> $GITHUB_OUTPUT cd libraries/hl2sdk-cs2 @@ -110,7 +110,7 @@ jobs: - **From:** `${{ steps.current.outputs.commit }}` - **To:** `${{ steps.latest.outputs.commit }}` - ## Recent hl2sdk commits + ## Commits in this update ``` ${{ steps.commit_info.outputs.COMMITS }} ``` From ef26fc049c426b33153167b81b10279b6b865cb2 Mon Sep 17 00:00:00 2001 From: dollan Date: Sun, 7 Dec 2025 00:25:16 +0100 Subject: [PATCH 3/4] Improved --- .github/workflows/bump-hl2sdk.yml | 91 ++++++++++++++++++------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/.github/workflows/bump-hl2sdk.yml b/.github/workflows/bump-hl2sdk.yml index d2ecef151..6fc3ad0ec 100644 --- a/.github/workflows/bump-hl2sdk.yml +++ b/.github/workflows/bump-hl2sdk.yml @@ -2,9 +2,8 @@ name: Bump hl2sdk on: schedule: - # Run every 15 minutes - - cron: "*/15 * * * *" - workflow_dispatch: # Allow manual trigger + - cron: "0 * * * *" + workflow_dispatch: permissions: contents: write @@ -32,6 +31,10 @@ jobs: 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" @@ -52,19 +55,27 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Check if there's already an open PR for hl2sdk bump - EXISTING_PR=$(gh pr list --state open --head "chore/bump-hl2sdk" --json number --jq '.[0].number // empty') + EXISTING_PR=$(gh pr list --state open --head "chore/bump-hl2sdk" --json number,body --jq '.[0] // empty') if [ -n "$EXISTING_PR" ]; then - echo "has_existing_pr=true" >> $GITHUB_OUTPUT - echo "pr_number=$EXISTING_PR" >> $GITHUB_OUTPUT - echo "Existing PR found: #$EXISTING_PR" + 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 "has_existing_pr=false" >> $GITHUB_OUTPUT + echo "skip=false" >> $GITHUB_OUTPUT echo "No existing PR found" fi - name: Update submodule - if: steps.check.outputs.needs_update == 'true' + if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true' run: | cd libraries/hl2sdk-cs2 git fetch origin cs2 @@ -73,7 +84,7 @@ jobs: echo "Updated hl2sdk to ${{ steps.latest.outputs.commit }}" - name: Get commit details - if: steps.check.outputs.needs_update == 'true' + if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true' id: commit_info run: | cd libraries/hl2sdk-cs2 @@ -82,20 +93,42 @@ jobs: COMMIT_DATE=$(git log -1 --pretty=format:"%ci") SHORT_SHA=$(git rev-parse --short HEAD) - echo "message=$COMMIT_MSG" >> $GITHUB_OUTPUT + echo "message<> $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 - # Get commits in this update for PR body (last 20) - cd ../.. - echo "COMMITS<> $GITHUB_OUTPUT - cd libraries/hl2sdk-cs2 - git log --oneline ${{ steps.current.outputs.commit }}..${{ steps.latest.outputs.commit }} | head -20 >> $GITHUB_OUTPUT - echo "EOF" >> $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 + cat > .github/pr-body.md << 'ENDOFBODY' + Automated PR to update hl2sdk submodule. + + ## Changes + ENDOFBODY + echo "- **From:** \`${{ steps.current.outputs.commit }}\`" >> .github/pr-body.md + echo "- **To:** \`${{ steps.latest.outputs.commit }}\`" >> .github/pr-body.md + echo "" >> .github/pr-body.md + echo "## Commits in this update" >> .github/pr-body.md + echo '```' >> .github/pr-body.md + cat /tmp/commits.txt >> .github/pr-body.md + echo '```' >> .github/pr-body.md + echo "" >> .github/pr-body.md + echo "## Latest commit info" >> .github/pr-body.md + echo "- **Message:** ${{ steps.commit_info.outputs.message }}" >> .github/pr-body.md + echo "- **Author:** ${{ steps.commit_info.outputs.author }}" >> .github/pr-body.md + echo "- **Date:** ${{ steps.commit_info.outputs.date }}" >> .github/pr-body.md + echo "" >> .github/pr-body.md + echo "---" >> .github/pr-body.md + 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' + 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 }} @@ -103,25 +136,7 @@ jobs: branch: chore/bump-hl2sdk delete-branch: true title: "chore(deps): bump hl2sdk to ${{ steps.commit_info.outputs.short_sha }}" - body: | - Automated PR to update hl2sdk submodule. - - ## Changes - - **From:** `${{ steps.current.outputs.commit }}` - - **To:** `${{ steps.latest.outputs.commit }}` - - ## Commits in this update - ``` - ${{ steps.commit_info.outputs.COMMITS }} - ``` - - ## Latest commit info - - **Message:** ${{ steps.commit_info.outputs.message }} - - **Author:** ${{ steps.commit_info.outputs.author }} - - **Date:** ${{ steps.commit_info.outputs.date }} - - --- - 🤖 This PR was automatically created by the [bump-hl2sdk workflow](https://github.com/${{ github.repository }}/actions/workflows/bump-hl2sdk.yml). + body-path: .github/pr-body.md labels: | dependencies automated From 58542a29a6366c9cd5e6d8cceca699d54e4ef53e Mon Sep 17 00:00:00 2001 From: dollan Date: Sun, 7 Dec 2025 00:29:54 +0100 Subject: [PATCH 4/4] Hopefully resolve spellcheck --- .github/workflows/bump-hl2sdk.yml | 72 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/bump-hl2sdk.yml b/.github/workflows/bump-hl2sdk.yml index 6fc3ad0ec..ca655c31f 100644 --- a/.github/workflows/bump-hl2sdk.yml +++ b/.github/workflows/bump-hl2sdk.yml @@ -23,29 +23,29 @@ jobs: id: current run: | cd libraries/hl2sdk-cs2 - CURRENT_COMMIT=$(git rev-parse HEAD) - echo "commit=$CURRENT_COMMIT" >> $GITHUB_OUTPUT + 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 + 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 "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 "needs_update=false" >> "$GITHUB_OUTPUT" echo "hl2sdk is already up to date" else - echo "needs_update=true" >> $GITHUB_OUTPUT + echo "needs_update=true" >> "$GITHUB_OUTPUT" echo "hl2sdk update available!" fi @@ -55,22 +55,22 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - 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 + 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 + 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 "skip=false" >> "$GITHUB_OUTPUT" echo "Existing PR needs update" fi else - echo "skip=false" >> $GITHUB_OUTPUT + echo "skip=false" >> "$GITHUB_OUTPUT" echo "No existing PR found" fi @@ -106,26 +106,26 @@ jobs: if: steps.check.outputs.needs_update == 'true' && steps.existing_pr.outputs.skip != 'true' run: | mkdir -p .github - cat > .github/pr-body.md << 'ENDOFBODY' - Automated PR to update hl2sdk submodule. - - ## Changes - ENDOFBODY - echo "- **From:** \`${{ steps.current.outputs.commit }}\`" >> .github/pr-body.md - echo "- **To:** \`${{ steps.latest.outputs.commit }}\`" >> .github/pr-body.md - echo "" >> .github/pr-body.md - echo "## Commits in this update" >> .github/pr-body.md - echo '```' >> .github/pr-body.md - cat /tmp/commits.txt >> .github/pr-body.md - echo '```' >> .github/pr-body.md - echo "" >> .github/pr-body.md - echo "## Latest commit info" >> .github/pr-body.md - echo "- **Message:** ${{ steps.commit_info.outputs.message }}" >> .github/pr-body.md - echo "- **Author:** ${{ steps.commit_info.outputs.author }}" >> .github/pr-body.md - echo "- **Date:** ${{ steps.commit_info.outputs.date }}" >> .github/pr-body.md - echo "" >> .github/pr-body.md - echo "---" >> .github/pr-body.md - 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 + { + 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'