|
| 1 | +name: Dependabot Lockfile Refresh |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: |
| 8 | + - opened |
| 9 | + - synchronize |
| 10 | + - reopened |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + refresh-lockfiles: |
| 22 | + name: Refresh lockfiles for Dependabot PRs |
| 23 | + if: github.actor == 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout PR branch |
| 28 | + uses: actions/checkout@v7 |
| 29 | + with: |
| 30 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 31 | + ref: ${{ github.event.pull_request.head.ref }} |
| 32 | + token: ${{ github.token }} |
| 33 | + |
| 34 | + - name: Set up uv |
| 35 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 36 | + with: |
| 37 | + version: "0.8.17" |
| 38 | + enable-cache: true |
| 39 | + |
| 40 | + - name: Install Python 3.13 |
| 41 | + run: uv python install 3.13 |
| 42 | + |
| 43 | + - name: Initialize Pants |
| 44 | + uses: pantsbuild/actions/init-pants@0aaef864bd133c4055feb6adad0bfdce0de1c2e4 # v11 |
| 45 | + with: |
| 46 | + gha-cache-key: cache0-py313 |
| 47 | + named-caches-hash: ${{ hashFiles('3rdparty/python/default.lock', 'pants.toml') }} |
| 48 | + pants-ci-config: "" |
| 49 | + |
| 50 | + - name: Set up pnpm |
| 51 | + uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 |
| 52 | + with: |
| 53 | + version: 11.1.2 |
| 54 | + |
| 55 | + - name: Set up Node.js |
| 56 | + uses: actions/setup-node@v6 |
| 57 | + with: |
| 58 | + node-version: "22" |
| 59 | + cache: pnpm |
| 60 | + cache-dependency-path: pnpm-lock.yaml |
| 61 | + |
| 62 | + - name: Refresh lockfiles |
| 63 | + run: | |
| 64 | + corepack enable |
| 65 | + corepack prepare pnpm@11.1.2 --activate |
| 66 | + uv lock |
| 67 | + pants generate-lockfiles --resolve=python-default |
| 68 | + pnpm install --lockfile-only |
| 69 | +
|
| 70 | + - name: Commit lockfile updates |
| 71 | + env: |
| 72 | + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | +
|
| 76 | + git config user.name "github-actions[bot]" |
| 77 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 78 | +
|
| 79 | + # Reject unexpected ref values before using them in git commands. |
| 80 | + if [[ ! "$PR_HEAD_REF" =~ ^[A-Za-z0-9._/-]+$ ]] || [[ "$PR_HEAD_REF" == -* ]] || [[ "$PR_HEAD_REF" == *..* ]]; then |
| 81 | + echo "Invalid pull request head ref: $PR_HEAD_REF" |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + if git diff --quiet -- uv.lock 3rdparty/python/default.lock pnpm-lock.yaml; then |
| 86 | + echo "No lockfile updates needed" |
| 87 | + exit 0 |
| 88 | + fi |
| 89 | +
|
| 90 | + git add uv.lock 3rdparty/python/default.lock pnpm-lock.yaml |
| 91 | + git commit -m "chore: refresh lockfiles for dependabot" |
| 92 | + git push origin "HEAD:$PR_HEAD_REF" |
0 commit comments