# PowerShell Local Resource Manager Part 4

- URL: <https://krymtkts.github.io/posts/2026-03-29-powrshell-project-local-resource-management-part-4.html.md>
- Date: 2026-03-29
- Author: krymtkts
- Tags: powershell

[krymtkts/pslrm](https://github.com/krymtkts/pslrm) の開発をした。

`Update-PSLResource` を使えば、実行後に `psreq.lock.psd1` の差分から依存関係の更新を検知できる。
それを使って Dependabot のような自動的な更新したくてそういう GitHub Actions workflow をこしらえた。

[pslrm/.github/workflows/bump.yml at d42f35ea69c63159ff5043106bbdfc4a1b5113d1 · krymtkts/pslrm](https://github.com/krymtkts/pslrm/blob/d42f35ea69c63159ff5043106bbdfc4a1b5113d1/.github/workflows/bump.yml)

```yml
name: Bump dependencies

on:
  schedule:
    - cron: "0 20 * * 5" # Every Friday at 06:00 JST
  workflow_dispatch:

concurrency:
  group: bump-dependencies
  cancel-in-progress: false

permissions:
  contents: write
  pull-requests: write

jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: main
      - name: Restore modules from PSGallery
        shell: pwsh
        run: |
          Set-PSResourceRepository PSGallery -Trusted
          Import-Module ./pslrm.psd1 -Force
          Restore-PSLResource
      - name: Bump dependencies
        shell: pwsh
        run: |
          Import-Module ./pslrm.psd1 -Force
          Update-PSLResource
      - name: Detect lockfile changes
        id: lockfile
        shell: pwsh
        run: |
          $diff = git status --porcelain -- psreq.lock.psd1
          if ($diff) {
            "changed=true" >> $env:GITHUB_OUTPUT
            Write-Host "Lockfile changes detected."
          } else {
            "changed=false" >> $env:GITHUB_OUTPUT
            Write-Host "No lockfile changes detected."
          }
      - name: Create or update pull request
        if: steps.lockfile.outputs.changed == 'true'
        env:
          GH_TOKEN: ${{ github.token }}
        shell: pwsh
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email '41898282+github-actions[bot]@users.noreply.github.com'

          $branch = 'chore/bump-pslrm-dependencies'
          git switch --force-create $branch
          git add -- psreq.lock.psd1

          $stagedLockfile = git diff --cached --name-only -- psreq.lock.psd1
          if (-not $stagedLockfile) {
            Write-Host 'No staged lockfile changes to commit.'
            exit 0
          }

          $title = 'Bump pslrm dependencies.'
          git commit --message $title
          git push --force --set-upstream origin $branch

          $baseBranch = 'main'
          $prNumber = gh pr list --base $baseBranch --head $branch --state open --json number --jq '.[0].number'
          if ($prNumber) {
            Write-Host "Pull request #$prNumber already exists."
          } else {
            $body = 'Automated dependency bump generated by Update-PSLResource.'
            gh pr create --base $baseBranch --head $branch --title $title --body $body
          }
```

つい昨日いい感じに動き PR [#1](https://github.com/krymtkts/pslrm/pull/1) は作成されたのだが、運用してみてちょっとした問題があるとわかった。
単純な話だが GitHub Actions の仕様で bot が作った PR に対して CI の GitHub Actions workflow が起動しないというものだ。
[`pull_request`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request) の節には書いてないようだが [`check_run`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#check_run) [`check_suite`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#check_suite) には書いてある様子。

CI が `pull_request` じゃなく [`pull_request_target`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target) を使っていれば起動できるが、そこは本質じゃない。
あるべき像としては pslrm の GitHub Actions workflow 側で GitHub CLI の `GH_TOKEN` に権限を持った [PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) を使うのがいいっぽい。
GitHub App を使う手もあるが、その方式が一番一般的ぽい。
次のステップとしては [PowerShell Gallery](https://www.powershellgallery.com/) に公開している pslrm を使う third-party Action を作りたく、その場合も PAT がいいみたい。
なのでその方向でも調整していこうと思っているが、リアルで旅の途中なので着手はできてない。

他にも PR のために作成する branch name が固定だったり、 description が簡素過ぎたりもある。
Dependabot ぽくするなら label もつけたいしな。
その辺りも含めて機能を揃えられたら、 third-party Action として良さげかなと考えている。
如何せん third-party Action を作ったことがないから、手探りで進めていく予定。

続く。
