Skip to content

Commit

Permalink
Merge pull request #6 from patternfly/nicolethoen-patch-1
Browse files Browse the repository at this point in the history
fix: update to PF release candidate versions + add PR previews
  • Loading branch information
adamviktora authored Oct 7, 2024
2 parents 200a4ea + f894850 commit e6d2afd
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 118 deletions.
98 changes: 98 additions & 0 deletions .github/upload-preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const fs = require('fs');
const path = require('path');
const surge = require('surge');
const publishFn = surge().publish();

(async () => {
const { Octokit } = await import('@octokit/rest');
const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });

// From github actions
const ghrepo = process.env.GITHUB_REPOSITORY || '';

const owner = process.env.CIRCLE_PROJECT_USERNAME || ghrepo.split('/')[0]; // patternfly
const repo = process.env.CIRCLE_PROJECT_REPONAME || ghrepo.split('/')[1];
const prnum = process.env.CIRCLE_PR_NUMBER || process.env.GH_PR_NUM;
const prbranch = process.env.CIRCLE_BRANCH || process.env.GITHUB_REF.split('/').pop();

const uploadFolder = process.argv[2];
if (!uploadFolder) {
console.log('Usage: upload-preview uploadFolder');
process.exit(1);
}

const uploadFolderName = path.basename(uploadFolder);
let uploadURL = `${repo}-${prnum ? `pr-ai-infra-ui-components-${prnum}` : prbranch}`.replace(/[\/|\.]/g, '-');

switch(uploadFolderName) {
case 'coverage':
uploadURL += '-a11y.surge.sh';
break;
case 'public':
if (!prnum && prbranch === 'main') {
uploadURL = 'https://pf-ai-infra-ui-components.surge.sh/';
} else {
uploadURL += '.surge.sh';
}
break;
default:
uploadURL += `-${uploadFolderName}`;
uploadURL += '.surge.sh';
break;
}

publishFn({
project: uploadFolder,
p: uploadFolder,
domain: uploadURL,
d: uploadURL,
e: 'https://surge.surge.sh',
endpoint: 'https://surge.surge.sh'
});

function tryAddComment(comment, commentBody) {
if (!commentBody.includes(comment)) {
return comment;
}
return '';
}

if (prnum) {
const comments = await octokit.issues.listComments({
owner,
repo,
issue_number: prnum
}).then(res => res.data);

let commentBody = '';
const existingComment = comments.find(comment => comment.user.login === 'patternfly-build');
if (existingComment) {
commentBody += existingComment.body.trim();
commentBody += '\n\n';
}

if (uploadFolderName === 'public') {
commentBody += tryAddComment(`Preview: https://${uploadURL}`, commentBody);
} else if (uploadFolderName === 'coverage') {
commentBody += tryAddComment(`A11y report: https://${uploadURL}`, commentBody);
}

if (existingComment) {
await octokit.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody
});
console.log('Updated comment!');
} else {
await octokit.issues.createComment({
owner,
repo,
issue_number: prnum,
body: commentBody
});
console.log('Created comment!');
}
}
})();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@typescript-eslint/parser": "^8.1.0",
"prettier": "3.3.3",
"jest": "^29.7.0",
"@octokit/rest": "^21.0.1",
"babel-jest": "^29.7.0",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"access": "public"
},
"dependencies": {
"@patternfly/react-core": "6.0.0-alpha.100"
"@patternfly/react-core": "6.0.0-prerelease.21"
},
"peerDependencies": {
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@patternfly/documentation-framework": "6.0.0-alpha.79",
"@patternfly/patternfly": "6.0.0-alpha.205",
"@patternfly/react-table": "6.0.0-alpha.101",
"@patternfly/react-code-editor": "6.0.0-alpha.100",
"@patternfly/documentation-framework": "6.0.0-alpha.109",
"@patternfly/patternfly": "6.0.0-prerelease.15",
"@patternfly/react-table": "6.0.0-prerelease.22",
"@patternfly/react-code-editor": "6.0.0-prerelease.21",
"rimraf": "^6.0.1",
"@patternfly/patternfly-a11y": "^4.3.1",
"react-monaco-editor": "^0.56.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pageData.examples = {

const Component = () => (
<React.Fragment>
<p {...{"className":"pf-v6-c-content--p ws-p "}}>
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
{`Design guidelines intro`}
</p>
<AutoLinkHeader {...{"id":"header","headingLevel":"h2","className":"ws-title ws-h2"}}>
Expand All @@ -31,20 +31,20 @@ const Component = () => (
<AutoLinkHeader {...{"id":"sub-header","headingLevel":"h3","className":"ws-title ws-h3"}}>
{`Sub-header`}
</AutoLinkHeader>
<p {...{"className":"pf-v6-c-content--p ws-p "}}>
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
{`Guidelines:`}
</p>
<ol {...{"className":"pf-v6-c-content--ol ws-ol "}}>
<li {...{"className":"pf-v6-c-content--li ws-li "}}>
<ol {...{"className":"pf-v6-c-content--ol pf-m-editorial ws-ol "}}>
<li {...{"className":"pf-v6-c-content--li pf-m-editorial ws-li "}}>
{`A`}
</li>
<li {...{"className":"pf-v6-c-content--li ws-li "}}>
<li {...{"className":"pf-v6-c-content--li pf-m-editorial ws-li "}}>
{`list`}
</li>
<li {...{"className":"pf-v6-c-content--li ws-li "}}>
<li {...{"className":"pf-v6-c-content--li pf-m-editorial ws-li "}}>
{`using`}
</li>
<li {...{"className":"pf-v6-c-content--li ws-li "}}>
<li {...{"className":"pf-v6-c-content--li pf-m-editorial ws-li "}}>
{`markdown`}
</li>
</ol>
Expand Down
Loading

0 comments on commit e6d2afd

Please sign in to comment.