Skip to content

Commit e1a69fc

Browse files
authored
fix(gha): Fix pnpm upgrade workflow (#335)
### Description Attempting to fix failures seen in pnpm upgrade job: https://github.com/open-constructs/cdk-terrain/actions/runs/29232337176/job/86759126716 ### Checklist - [ ] I have updated the PR title to match [CDKTN's style guide](https://github.com/open-constructs/cdk-terrain/blob/main/CONTRIBUTING.md#pull-requests-1) - [ ] I have run the linter on my code locally - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the [documentation](https://github.com/open-constructs/cdk-terrain-docs/tree/main/content) if applicable - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works if applicable - [ ] New and existing unit tests pass locally with my changes <!-- If this is still a work in progress, feel free to open a draft PR until you're able to check off all the items on the list above -->
1 parent 76dd4ff commit e1a69fc

1 file changed

Lines changed: 93 additions & 24 deletions

File tree

.github/workflows/pnpm-upgrade.yml

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: ./.github/actions/setup-corepack-pnpm
4141
- name: Install Tools
4242
run: |-
43-
npm -g install npm-check-updates@^9.0.0
43+
npm -g install npm-check-updates@22.2.9
4444
# Install first so `nx` is available for the package listing below.
4545
- name: Run "pnpm install"
4646
run: pnpm install --prefer-offline
@@ -52,9 +52,10 @@ jobs:
5252
- name: Run "ncu -u"
5353
run: |-
5454
# Upgrade dependencies at repository root
55-
ncu --upgrade --filter=@types/fs-extra --target=minor
56-
ncu --upgrade --filter=typescript --target=patch
57-
ncu --upgrade --reject=@types/node,@types/fs-extra,constructs,typescript,@types/prettier --target=minor
55+
ncu --upgrade --filter=@types/fs-extra --target=minor --packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
56+
ncu --upgrade --filter=typescript --target=patch --packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
57+
ncu --upgrade --reject=@types/node,@types/fs-extra,constructs,typescript,@types/prettier --target=minor \
58+
--packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
5859
5960
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
6061
- name: Run "pnpm install"
@@ -75,6 +76,8 @@ jobs:
7576
prRoot:
7677
name: Create Pull Request Root
7778
needs: upgradeRoot
79+
permissions:
80+
contents: read
7881
runs-on: ubuntu-latest
7982
steps:
8083
- name: Check Out
@@ -91,6 +94,23 @@ jobs:
9194
- name: Remove patch file
9295
run: rm -f ./upgrade.patch
9396

97+
- name: Mint CDKTN maintainers App token
98+
id: app-token
99+
# Pin maintained by Dependabot (github-actions). See .github/dependabot.yml
100+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
101+
with:
102+
app-id: ${{ secrets.CDKTN_MAINTAINERS_APP_ID }}
103+
private-key: ${{ secrets.CDKTN_MAINTAINERS_APP_PRIVATE_KEY }}
104+
permission-contents: write # is needed to create/update the automation branch.
105+
permission-pull-requests: write # covers creating/updating the PR, labels, and review requests.
106+
permission-members: read # limits organization access to the team lookup already being requested for cdktn-maintainers.
107+
108+
- name: Get GitHub App User ID
109+
id: get_user_id
110+
env:
111+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
112+
run: echo "id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
113+
94114
- name: Make Pull Request
95115
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
96116
with:
@@ -105,7 +125,9 @@ jobs:
105125
Ran npm-check-updates and pnpm update to keep the `pnpm-lock.yaml` file up-to-date.
106126
labels: dependencies,auto-approve,ci/run-all
107127
team-reviewers: cdktn-maintainers
108-
token: ${{ secrets.TERRAFORM_CDK_PUSH_GITHUB_TOKEN }}
128+
token: ${{ steps.app-token.outputs.token }}
129+
author: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
130+
committer: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
109131

110132
upgradePackage:
111133
name: Pnpm Upgrade Package
@@ -165,7 +187,7 @@ jobs:
165187
uses: ./.github/actions/setup-corepack-pnpm
166188
- name: Install Tools
167189
run: |-
168-
npm -g install npm-check-updates@^9.0.0
190+
npm -g install npm-check-updates@22.2.9
169191
# Install first so `nx` is available for the package listing below.
170192
- name: Run "pnpm install"
171193
run: pnpm install --prefer-offline
@@ -175,19 +197,49 @@ jobs:
175197
run: |-
176198
echo "list=$(pnpm exec nx show projects --json | jq -r 'join(",")')" >> $GITHUB_OUTPUT
177199
- name: Run "ncu -u"
200+
shell: bash
201+
env:
202+
NCU_WORKSPACES: ${{ join(matrix.pr.packages, ' ') }}
178203
run: |-
179-
# Upgrade all the packages
180-
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --filter=@types/fs-extra --target=minor
181-
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --filter=typescript --target=patch
182-
pnpm exec nx exec -p '${{ join(matrix.pr.packages, ',') }}' -- ncu --upgrade --reject='@types/node,@types/fs-extra,constructs,typescript,graphology-types,jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,${{ steps.list-packages.outputs.list }}' --target=minor
204+
read -ra workspaces <<< "$NCU_WORKSPACES"
205+
workspace_args=()
206+
for workspace in "${workspaces[@]}"; do
207+
workspace_args+=(--workspace "$workspace")
208+
done
209+
210+
ncu --upgrade "${workspace_args[@]}" --no-root \
211+
--filter=@types/fs-extra --target=minor \
212+
--packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
213+
214+
ncu --upgrade "${workspace_args[@]}" --no-root \
215+
--filter=typescript --target=patch \
216+
--packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
217+
218+
ncu --upgrade "${workspace_args[@]}" --no-root \
219+
--reject='@types/node,@types/fs-extra,constructs,typescript,graphology-types,jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,${{ steps.list-packages.outputs.list }}' \
220+
--target=minor \
221+
--packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
222+
183223
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
184224
- name: Run "pnpm install"
185225
run: pnpm install --prefer-offline --no-frozen-lockfile
186226

187-
- name: Set git identity
188-
run: |-
189-
git config --global user.email "github-team-tf-cdk@hashicorp.com"
190-
git config --global user.name "team-tf-cdk"
227+
- name: Mint CDKTN maintainers App token
228+
id: app-token
229+
# Pin maintained by Dependabot (github-actions). See .github/dependabot.yml
230+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
231+
with:
232+
app-id: ${{ secrets.CDKTN_MAINTAINERS_APP_ID }}
233+
private-key: ${{ secrets.CDKTN_MAINTAINERS_APP_PRIVATE_KEY }}
234+
permission-contents: write # is needed to create/update the automation branch.
235+
permission-pull-requests: write # covers creating/updating the PR, labels, and review requests.
236+
permission-members: read # limits organization access to the team lookup already being requested for cdktn-maintainers.
237+
238+
- name: Get GitHub App User ID
239+
id: get_user_id
240+
env:
241+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
242+
run: echo "id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
191243

192244
- name: Make Pull Request
193245
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
@@ -207,8 +259,9 @@ jobs:
207259
208260
labels: dependencies,auto-approve
209261
team-reviewers: cdktn-maintainers
210-
token: ${{ secrets.TERRAFORM_CDK_PUSH_GITHUB_TOKEN }}
211-
author: team-tf-cdk <github-team-tf-cdk@hashicorp.com>
262+
token: ${{ steps.app-token.outputs.token }}
263+
author: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
264+
committer: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
212265

213266
upgradeJSII:
214267
name: Pnpm Upgrade JSII
@@ -232,7 +285,7 @@ jobs:
232285
uses: ./.github/actions/setup-corepack-pnpm
233286
- name: Install Tools
234287
run: |-
235-
npm -g install npm-check-updates@^9.0.0
288+
npm -g install npm-check-updates@22.2.9
236289
# Install first so `nx` is available for the package listing below.
237290
- name: Run "pnpm install"
238291
run: pnpm install --prefer-offline
@@ -244,15 +297,30 @@ jobs:
244297
- name: Run "ncu -u"
245298
run: |-
246299
# Upgrade all the packages
247-
pnpm exec nx exec -- ncu --upgrade --filter='jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,constructs' --target=minor
300+
ncu --upgrade --workspaces --root \
301+
--filter='jsii,jsii-pacmak,jsii-rosetta,jsii-docgen,codemaker,constructs' \
302+
--target=minor \
303+
--packageManager pnpm --dep prod,dev,optional,peer --no-deprecated
248304
# Refresh the lockfile after the ncu edits above (necessary for "pnpm update" to run)
249305
- name: Run "pnpm install"
250306
run: pnpm install --prefer-offline --no-frozen-lockfile
251307

252-
- name: Set git identity
253-
run: |-
254-
git config --global user.email "github-team-tf-cdk@hashicorp.com"
255-
git config --global user.name "team-tf-cdk"
308+
- name: Mint CDKTN maintainers App token
309+
id: app-token
310+
# Pin maintained by Dependabot (github-actions). See .github/dependabot.yml
311+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
312+
with:
313+
app-id: ${{ secrets.CDKTN_MAINTAINERS_APP_ID }}
314+
private-key: ${{ secrets.CDKTN_MAINTAINERS_APP_PRIVATE_KEY }}
315+
permission-contents: write # is needed to create/update the automation branch.
316+
permission-pull-requests: write # covers creating/updating the PR, labels, and review requests.
317+
permission-members: read # limits organization access to the team lookup already being requested for cdktn-maintainers.
318+
319+
- name: Get GitHub App User ID
320+
id: get_user_id
321+
env:
322+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
323+
run: echo "id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
256324

257325
- name: Make Pull Request
258326
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
@@ -270,5 +338,6 @@ jobs:
270338
271339
labels: dependencies,auto-approve
272340
team-reviewers: cdktn-maintainers
273-
token: ${{ secrets.TERRAFORM_CDK_PUSH_GITHUB_TOKEN }}
274-
author: team-tf-cdk <github-team-tf-cdk@hashicorp.com>
341+
token: ${{ steps.app-token.outputs.token }}
342+
author: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
343+
committer: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get_user_id.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>

0 commit comments

Comments
 (0)