-
Notifications
You must be signed in to change notification settings - Fork 0
ci: add hl2sdk bump workflow #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: | | ||
| 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: | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [actionlint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [actionlint] reported by reviewdog 🐶 |
||
| 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 | ||
There was a problem hiding this comment.
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]