Skip to content

Commit de94e2d

Browse files
authored
Merge pull request #36 from nicolethoen/add-pr-preview-workflow
feat: add PR preview deployment workflow
2 parents f38c5ed + fb7e925 commit de94e2d

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: pr-preview
2+
on:
3+
pull_request_target:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
check-permissions:
9+
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'
48+
env:
49+
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
50+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
51+
GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }}
52+
GH_PR_NUM: ${{ needs.check-permissions.outputs.pr-number }}
53+
steps:
54+
- uses: actions/checkout@v4
55+
- run: |
56+
git fetch origin pull/$GH_PR_NUM/head:tmp
57+
git checkout tmp
58+
- uses: actions/setup-node@v4
59+
with:
60+
node-version: '22'
61+
- uses: actions/cache@v4
62+
id: yarn-cache
63+
name: Cache yarn deps
64+
with:
65+
path: |
66+
node_modules
67+
**/node_modules
68+
key: ${{ runner.os }}-yarn-22-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
69+
- run: yarn install --frozen-lockfile
70+
if: steps.yarn-cache.outputs.cache-hit != 'true'
71+
- run: yarn build
72+
name: Build
73+
- run: yarn build:docs
74+
name: Build docs
75+
- name: Upload docs
76+
uses: patternfly/.github/.github/actions/surge-preview@main
77+
with:
78+
folder: packages/module/public

0 commit comments

Comments
 (0)