# PowerShell Local Resource Manager Part 5

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

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

[前回話していた](/posts/2026-03-29-powrshell-project-local-resource-management-part-4.md) `Update-PSLResource` を使った `psreq.lock.psd1` の Bump workflow を直した。

[pslrm/.github/workflows/bump.yml at d9a96677d1690fb5b7465a992bbbd3f55772103a · krymtkts/pslrm](https://github.com/krymtkts/pslrm/blob/d9a96677d1690fb5b7465a992bbbd3f55772103a/.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

# NOTE: no permissions are needed.
permissions: {}

jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: main
          # NOTE: to trigger the workflow on a push to the bump branch.
          token: ${{ secrets.PSLRM_BUMP_TOKEN }}
      - name: Bump dependencies
        shell: pwsh
        run: |
          Set-PSResourceRepository PSGallery -Trusted
          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: ${{ secrets.PSLRM_BUMP_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
          }
```

[Managing your personal access tokens - GitHub Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#using-a-personal-access-token-on-the-command-line)

直に URL に PAT を指定する方法を始め使おうと思ったが、やめた。
どうも [`actions/checkout`](https://github.com/actions/checkout) で `token` に PAT を渡せば PAT で認証された HTTPS remote を使うようだったのでそれを採用した。
その方が、見た目がスッキリしてよろしい。

PAT には Content read/write と Pull Request read/write を設定するので、 workflow 自体の認証が要らなくなる。
指定の仕方がわからなかったが、これは公式文書上に書いてあった。

[Defining access for the GITHUB_TOKEN scopes | Workflow syntax for GitHub Actions - GitHub Docs](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes)

```yml
permissions: {}
```

ちょっと見慣れない書き方だが、今回のケースはコレがハマるはず。

コレをベースに pslrm の third-party actions を作り始めてみたが、この週末体調が優れずあんま進んでない。
休日を有効活用できず残念だが、一歩くらいは進んでるのでよしとする。
今回使った `actions/checkout` の `token` に PAT を渡す方法は、 third-party action の場合だと checkout を内包すべきでないだろうし、使わない想定。
少しずつ仕様を詰めていってはよ v0 の bump-pslrm-action として公開したいな(そして自分の repos で使うのだ)。
