Skip to content

Commit b100683

Browse files
Merge branch 'patternfly:main' into main
2 parents 3fda1d6 + 3b51314 commit b100683

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

.github/upload-preview.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { Octokit } = require('@octokit/rest');
4+
const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });
5+
const surge = require('surge');
6+
const publishFn = surge().publish();
7+
8+
// From github actions
9+
const ghrepo = process.env.GITHUB_REPOSITORY || '';
10+
11+
const owner = process.env.CIRCLE_PROJECT_USERNAME || ghrepo.split('/')[0]; // patternfly
12+
const repo = process.env.CIRCLE_PROJECT_REPONAME || ghrepo.split('/')[1];
13+
const prnum = process.env.CIRCLE_PR_NUMBER || process.env.GH_PR_NUM;
14+
const prbranch = process.env.CIRCLE_BRANCH || process.env.GITHUB_REF.split('/').pop();
15+
16+
const uploadFolder = process.argv[2];
17+
if (!uploadFolder) {
18+
console.log('Usage: upload-preview uploadFolder');
19+
process.exit(1);
20+
}
21+
22+
const uploadFolderName = path.basename(uploadFolder);
23+
let uploadURL = `${repo}-${prnum ? `pr-catalog-view-${prnum}` : prbranch}`.replace(/[\/|\.]/g, '-');
24+
25+
switch(uploadFolderName) {
26+
case 'coverage':
27+
uploadURL += '-a11y.surge.sh';
28+
break;
29+
case 'public':
30+
if (!prnum && prbranch === 'main') {
31+
uploadURL = 'https://pf-extensions.surge.sh/';
32+
}
33+
else {
34+
uploadURL += '.surge.sh';
35+
}
36+
break;
37+
default:
38+
uploadURL += `-${uploadFolderName}`;
39+
uploadURL += '.surge.sh';
40+
break;
41+
}
42+
43+
publishFn({
44+
project: uploadFolder,
45+
p: uploadFolder,
46+
domain: uploadURL,
47+
d: uploadURL,
48+
e: 'https://surge.surge.sh',
49+
endpoint: 'https://surge.surge.sh'
50+
});
51+
52+
function tryAddComment(comment, commentBody) {
53+
if (!commentBody.includes(comment)) {
54+
return comment;
55+
}
56+
return '';
57+
}
58+
59+
if (prnum) {
60+
octokit.issues.listComments({
61+
owner,
62+
repo,
63+
issue_number: prnum
64+
})
65+
.then(res => res.data)
66+
.then(comments => {
67+
let commentBody = '';
68+
const existingComment = comments.find(comment => comment.user.login === 'patternfly-build');
69+
if (existingComment) {
70+
commentBody += existingComment.body.trim();
71+
commentBody += '\n\n';
72+
}
73+
74+
if (uploadFolderName === 'public') {
75+
commentBody += tryAddComment(`Preview: https://${uploadURL}`, commentBody);
76+
}
77+
else if (uploadFolderName === 'coverage') {
78+
commentBody += tryAddComment(`A11y report: https://${uploadURL}`, commentBody);
79+
}
80+
81+
if (existingComment) {
82+
octokit.issues.updateComment({
83+
owner,
84+
repo,
85+
comment_id: existingComment.id,
86+
body: commentBody
87+
}).then(() => console.log('Updated comment!'));
88+
} else {
89+
octokit.issues.createComment({
90+
owner,
91+
repo,
92+
issue_number: prnum,
93+
body: commentBody
94+
}).then(() => console.log('Created comment!'));
95+
}
96+
});
97+
}

.github/workflows/pr-preview.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: pr-preview
2+
on: pull_request_target
3+
jobs:
4+
build-upload:
5+
runs-on: ubuntu-latest
6+
env:
7+
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
8+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
9+
GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }}
10+
GH_PR_NUM: ${{ github.event.number }}
11+
steps:
12+
- uses: actions/checkout@v2
13+
# Yes, we really want to checkout the PR
14+
- run: |
15+
git fetch origin pull/$GH_PR_NUM/head:tmp
16+
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
24+
- uses: actions/setup-node@v1
25+
with:
26+
node-version: '18'
27+
- uses: actions/cache@v2
28+
id: yarn-cache
29+
name: Load npm deps from cache
30+
with:
31+
path: '**/node_modules'
32+
key: ${{ runner.os }}-yarn-14-${{ hashFiles('yarn.lock') }}
33+
- run: yarn install --frozen-lockfile
34+
if: steps.yarn-cache.outputs.cache-hit != 'true'
35+
- run: yarn lint:js
36+
name: Lint JS
37+
if: always()
38+
- run: yarn lint:md
39+
name: Lint MD
40+
if: always()
41+
- run: yarn build
42+
name: Build component groups
43+
- uses: actions/cache@v2
44+
id: docs-cache
45+
name: Load webpack cache
46+
with:
47+
path: '.cache'
48+
key: ${{ runner.os }}-v4-${{ hashFiles('yarn.lock') }}
49+
- run: yarn build:docs
50+
name: Build docs
51+
- run: node .github/upload-preview.js public
52+
name: Upload docs
53+
if: always()
54+
- run: yarn serve:docs & yarn test:a11y
55+
name: a11y tests
56+
- run: node .github/upload-preview.js coverage
57+
name: Upload a11y report
58+
if: always()

0 commit comments

Comments
 (0)