Skip to content

Commit f19aadd

Browse files
authored
Merge pull request #38 from patternfly-extension-testing/update-pr-preview
Gate PR preview deploy behind org membership check
2 parents d28caeb + 41ed88f commit f19aadd

1 file changed

Lines changed: 60 additions & 22 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,79 @@
11
name: pr-preview
2-
on: pull_request_target
2+
on:
3+
pull_request_target:
4+
issue_comment:
5+
types: [created]
6+
37
jobs:
4-
build-upload:
8+
check-permissions:
59
runs-on: ubuntu-latest
10+
if: >-
11+
github.event_name == 'pull_request_target' ||
12+
(github.event_name == 'issue_comment' &&
13+
github.event.issue.pull_request &&
14+
contains(github.event.comment.body, '/deploy-preview'))
15+
outputs:
16+
allowed: ${{ steps.check-team.outputs.allowed }}
17+
pr-number: ${{ steps.check-team.outputs.number }}
18+
steps:
19+
- name: Get PR info and check permissions
20+
id: check-team
21+
env:
22+
EVENT_NAME: ${{ github.event_name }}
23+
PR_NUMBER: ${{ github.event.pull_request.number }}
24+
PR_ASSOCIATION: ${{ github.event.pull_request.author_association }}
25+
COMMENT_NUMBER: ${{ github.event.issue.number }}
26+
COMMENT_ASSOCIATION: ${{ github.event.comment.author_association }}
27+
run: |
28+
if [[ "$EVENT_NAME" == "pull_request_target" ]]; then
29+
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
30+
ASSOCIATION="$PR_ASSOCIATION"
31+
else
32+
echo "number=$COMMENT_NUMBER" >> $GITHUB_OUTPUT
33+
ASSOCIATION="$COMMENT_ASSOCIATION"
34+
fi
35+
36+
if [[ "$ASSOCIATION" == "OWNER" || "$ASSOCIATION" == "MEMBER" || "$ASSOCIATION" == "COLLABORATOR" ]]; then
37+
echo "allowed=true" >> $GITHUB_OUTPUT
38+
echo "User is a repo $ASSOCIATION — allowed"
39+
else
40+
echo "allowed=false" >> $GITHUB_OUTPUT
41+
echo "User association is $ASSOCIATION — not allowed"
42+
fi
43+
44+
deploy-preview:
45+
runs-on: ubuntu-latest
46+
needs: check-permissions
47+
if: needs.check-permissions.outputs.allowed == 'true'
648
env:
749
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
850
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
951
GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }}
10-
GH_PR_NUM: ${{ github.event.number }}
52+
GH_PR_NUM: ${{ needs.check-permissions.outputs.pr-number }}
1153
steps:
12-
- uses: actions/checkout@v2
13-
# Yes, we really want to checkout the PR
54+
- uses: actions/checkout@v4
1455
- run: |
1556
git fetch origin pull/$GH_PR_NUM/head:tmp
1657
git checkout tmp
17-
- run: |
18-
git rev-parse origin/main
19-
git rev-parse HEAD
20-
git rev-parse origin/main..HEAD
21-
git log origin/main..HEAD --format="%b"
22-
# Yes, we really want to checkout the PR
23-
# Injected by generate-workflows.js
2458
- uses: actions/setup-node@v4
2559
with:
2660
node-version: '20'
2761
- run: corepack enable
62+
- uses: actions/cache@v4
63+
id: yarn-cache
64+
name: Cache yarn deps
65+
with:
66+
path: |
67+
node_modules
68+
**/node_modules
69+
key: ${{ runner.os }}-yarn-20-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
2870
- run: yarn install --immutable
29-
- run: yarn lint:js
30-
name: Lint JS
31-
if: always()
32-
- run: yarn lint:md
33-
name: Lint MD
34-
if: always()
71+
if: steps.yarn-cache.outputs.cache-hit != 'true'
3572
- run: yarn build
36-
name: Build component groups
73+
name: Build
3774
- run: yarn build:docs
3875
name: Build docs
39-
- run: node .github/upload-preview.js packages/module/public
40-
name: Upload docs
41-
if: always()
76+
- name: Upload docs
77+
uses: patternfly/.github/.github/actions/surge-preview@main
78+
with:
79+
folder: packages/module/public

0 commit comments

Comments
 (0)