Skip to content

Commit 0af4852

Browse files
authored
Merge pull request #2 from patternfly-extension-testing/publish-previews
chore: update pr-preview publishing
2 parents 1577918 + 195cab3 commit 0af4852

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

.github/workflows/check-pr.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: check-pr
22
on:
33
pull_request:
4-
branches:
5-
- main
64
jobs:
75
call-build-lint-test-workflow:
86
uses: ./.github/workflows/build-lint-test.yml
7+
secrets: inherit

.github/workflows/pr-preview.yml

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,78 @@
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:
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:
545
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:
1254
- uses: actions/checkout@v4
13-
# Yes, we really want to checkout the PR
1455
- run: |
1556
git fetch origin pull/$GH_PR_NUM/head:tmp
1657
git checkout tmp
17-
18-
- run: |
19-
git rev-parse origin/main
20-
git rev-parse HEAD
21-
git rev-parse origin/main..HEAD
22-
git log origin/main..HEAD --format="%b"
23-
2458
- uses: actions/setup-node@v4
2559
with:
2660
node-version: '20'
27-
- name: Enable Corepack
28-
shell: bash
29-
run: corepack enable
61+
- run: corepack enable
3062
- uses: actions/cache@v4
3163
id: yarn-cache
3264
name: Load Yarn cache
3365
with:
3466
path: |
3567
.yarn/cache
36-
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('yarn.lock') }}
68+
key: ${{ runner.os }}-yarn-cache-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
3769
restore-keys: |
3870
${{ runner.os }}-yarn-cache-
3971
- name: Install dependencies
4072
shell: bash
4173
run: yarn install --immutable --network-timeout 100000
4274
- run: yarn build
43-
name: Build component groups
75+
name: Build
4476
- uses: actions/cache@v4
4577
id: docs-cache
4678
name: Load webpack cache
@@ -49,11 +81,7 @@ jobs:
4981
key: ${{ runner.os }}-v4-${{ hashFiles('yarn.lock') }}
5082
- run: yarn build:docs
5183
name: Build docs
52-
- name: Deploy preview to surge
53-
if: env.SURGE_LOGIN != '' && env.SURGE_TOKEN != ''
54-
run: |
55-
npx surge packages/module/public --domain pr-${{ github.event.number }}-widgetized-dashboard.surge.sh
56-
- name: Install Chrome for Puppeteer
57-
run: npx puppeteer browsers install chrome
58-
- name: a11y tests
59-
run: yarn serve:docs & yarn test:a11y
84+
- name: Upload docs
85+
uses: patternfly/.github/.github/actions/surge-preview@main
86+
with:
87+
folder: packages/module/public

0 commit comments

Comments
 (0)