Skip to content

Commit 269e34f

Browse files
authored
fix(ci): tighten PR workflow permissions and secret access (#901)
1 parent ae84122 commit 269e34f

2 files changed

Lines changed: 64 additions & 23 deletions

File tree

.github/workflows/next-drupal.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,51 @@ on:
33
push:
44
branches:
55
- main
6-
pull_request_target:
7-
types: [opened, reopened, synchronize]
6+
pull_request:
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
816

917
jobs:
1018
test:
1119
runs-on: ubuntu-latest
20+
timeout-minutes: 15
1221
steps:
1322
- uses: actions/checkout@v4
1423
with:
15-
ref: ${{github.event.pull_request.head.ref}}
16-
repository: ${{github.event.pull_request.head.repo.full_name}}
17-
# TODO: Work-around for failing code coverage.
18-
# https://github.com/chapter-three/next-drupal/issues/740
24+
persist-credentials: false
1925
- name: Use Node.js
2026
uses: actions/setup-node@v4
2127
with:
2228
node-version: '18.19.x'
2329
- name: Install packages
24-
run: yarn
25-
- name: Run tests
26-
run: yarn test
30+
run: yarn install --frozen-lockfile
31+
- name: Run unit tests (PR)
32+
if: github.event_name == 'pull_request'
33+
# Skip integration test files that exercise a live Drupal instance.
34+
# Tracking removal of the live dependency in .claude/plans/.
35+
run: |
36+
yarn workspace next-drupal test \
37+
--testPathIgnorePatterns="NextDrupal/(crud-methods|resource-methods|basic-methods)|NextDrupalPages/(resource-methods|pages-router-methods)" \
38+
--coverageThreshold='{}'
39+
env:
40+
# Placeholders only — unit tests mock fetch. The test utils
41+
# construct a Drupal client at module load and require these
42+
# to be present (not valid).
43+
DRUPAL_BASE_URL: http://localhost
44+
DRUPAL_USERNAME: test
45+
DRUPAL_PASSWORD: test
46+
DRUPAL_CLIENT_ID: test
47+
DRUPAL_CLIENT_SECRET: test
48+
- name: Run all tests (main)
49+
if: github.event_name == 'push'
50+
run: yarn workspace next-drupal test
2751
env:
2852
DRUPAL_BASE_URL: ${{ secrets.DRUPAL_BASE_URL }}
2953
DRUPAL_USERNAME: ${{ secrets.DRUPAL_USERNAME }}

.github/workflows/release-pr.yml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
name: release-pr
22
on:
33
pull_request:
4-
types: [opened, reopened, synchronize, labeled]
4+
types: [labeled]
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.number }}
12+
cancel-in-progress: true
513

614
jobs:
715
next-drupal:
816
runs-on: ubuntu-latest
9-
if: ${{ contains(github.event.pull_request.labels.*.name, format('release-pr{0} next-drupal', ':')) }}
17+
timeout-minutes: 15
18+
if: |
19+
contains(github.event.pull_request.labels.*.name, format('release-pr{0} next-drupal', ':')) &&
20+
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
1021
environment: Preview
1122
steps:
1223
- name: Init
1324
uses: actions/checkout@v4
1425
with:
1526
ref: ${{ github.event.pull_request.head.sha }}
27+
persist-credentials: false
1628
- name: Setup Node
17-
uses: actions/setup-node@v3
29+
uses: actions/setup-node@v4
1830
with:
1931
node-version: 20
32+
registry-url: https://registry.npmjs.org/
2033
- name: Install dependencies
21-
run: yarn install
34+
run: yarn install --frozen-lockfile
2235
- name: Determine version
2336
uses: ./.github/version-pr
2437
id: determine-version
@@ -27,18 +40,22 @@ jobs:
2740
- name: Publish to npm
2841
run: |
2942
cd packages/next-drupal
30-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
3143
yarn publish --no-git-checks --access public --tag experimental
3244
env:
33-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3446
- name: Comment version on PR
35-
uses: NejcZdovc/comment-pr@v2
36-
with:
37-
message:
38-
"🎉 Experimental release [published 📦️ on npm](https://npmjs.com/package/next-drupal/v/${{ env.VERSION }})!\n \
39-
```sh\npnpm add next-drupal@${{ env.VERSION }}\n```\n \
40-
```sh\nyarn add next-drupal@${{ env.VERSION }}\n```\n \
41-
```sh\nnpm i next-drupal@${{ env.VERSION }}\n```"
4247
env:
4348
VERSION: ${{ steps.determine-version.outputs.version }}
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
PR_NUMBER: ${{ github.event.number }}
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
gh pr comment "$PR_NUMBER" --body "🎉 Experimental release [published 📦️ on npm](https://npmjs.com/package/next-drupal/v/$VERSION)!
53+
\`\`\`sh
54+
pnpm add next-drupal@$VERSION
55+
\`\`\`
56+
\`\`\`sh
57+
yarn add next-drupal@$VERSION
58+
\`\`\`
59+
\`\`\`sh
60+
npm i next-drupal@$VERSION
61+
\`\`\`"

0 commit comments

Comments
 (0)