Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Nov 16, 2023
1 parent 492fa2a commit 3b8903d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions src/deploy/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* eslint-disable unicorn/consistent-destructuring */
/* eslint-disable unicorn/no-null */

import fs from 'node:fs';

import * as core from '@actions/core';
import { exec } from '@actions/exec';
import * as github from '@actions/github';
Expand Down Expand Up @@ -80,11 +82,7 @@ export const deployPullRequest = async ({
github.context.repo.owner
}/${github.context.repo.repo}/actions/runs/${github.context.runId})
${formatImage({
buildingLogUrl,
imageUrl:
'https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png',
})}
${getCommentFooter()}
`);
Expand Down Expand Up @@ -142,12 +140,6 @@ ${getCommentFooter()}
return commentIfNotForkedRepo(`
:recycle: [PR Preview](https://${url}) ${gitCommitSha} has been successfully destroyed since this PR has been closed.
${formatImage({
buildingLogUrl,
imageUrl:
'https://user-images.githubusercontent.com/507615/98094112-d838f700-1ec3-11eb-8530-381c2276b80e.png',
})}
${getCommentFooter()}
`);
} catch (error: any) {
Expand All @@ -156,12 +148,13 @@ ${getCommentFooter()}
}

commentIfNotForkedRepo(`
⚡️ Deploying PR Preview ${gitCommitSha} to [surge.sh](https://${url}) ... [Build logs](${buildingLogUrl})
${formatImage({
buildingLogUrl,
imageUrl:
'https://user-images.githubusercontent.com/507615/90240294-8d2abd00-de5b-11ea-8140-4840a0b2d571.gif',
gitCommitSha,
url: `https://${url}`,
status: 'Deploying',
})}
${getCommentFooter()}
Expand All @@ -175,9 +168,15 @@ ${getCommentFooter()}
core.info(`RUN: ${command}`);
await exec(command);
}
const a =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAklEQVR4AewaftIAAAKESURBVO3BQW4kSQwEQQ+i/v9lXx15SiFRLQ21oFn8whqjWKMUa5RijVKsUYo1SrFGKdYoD99Iwm9S6ZLQqdxIQqfSJeE3qZwUa5RijVKsUR4uqXxSEm4koVPpktCp3FD5pCTcKNYoxRqlWKM8vJSEGyqflISTJHQqN5JwQ+WNYo1SrFGKNcrDH6PSJaFT6ZLwlxRrlGKNUqxRHoZT6ZJwkoS/rFijFGuUYo3y8JLKT0pCp9IloVPpkvCGym8q1ijFGqVYozxcSsL/WRL+pWKNUqxRijVK/MIao1ijFGuUYo3y8I0knKicJOGGyicloVM5SUKn0iXhDZWTYo1SrFGKNcrDN1S6JJwkoVPpktCpdEk4UemS0KncSMJPUrlRrFGKNUqxRnn4RhJOktCpdEnoVLoknKh8UhJOVLokdConSXijWKMUa5RijfJwSaVLQpeETqVLQqfyhkqXhBsqXRLeUHmjWKMUa5RijfLwkkqXhBOVLgmdSpeETuWGSpeEE5U3ktCp3CjWKMUapVijPHxD5YbKDZU3ktCpdEnoVG4k4UTlJAmdykmxRinWKMUa5eEbSfhNKp1Kl4ROpUtCp9Il4Tep3CjWKMUapVijPFxS+aQknCShU+mS8IZKl4QTlROVN4o1SrFGKdYoDy8l4YbKJ6l0SeiS0KlMVqxRijVKsUZ5GE6lS8KJykkSTlS6JHRJ6FS6JJyonBRrlGKNUqxRHv4YlS4JN1S6JHRJeEPljWKNUqxRijXKw0sqPykJnUqn0iWhU+mS0KlMUqxRijVKsUZ5uJSEfykJnconJeFE5UYSOpWTYo1SrFGKNUr8whqjWKMUa5RijVKsUYo1SrFGKdYo/wGkAAXlwY+9dgAAAABJRU5ErkJggg==';
fs.writeFileSync(`${dist}/qr.png`, a.replace('data:image/png;base64,', ''), 'base64');
} else {
await exec('npm install');
await exec('npm run build');
const a =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAklEQVR4AewaftIAAAKESURBVO3BQW4kSQwEQQ+i/v9lXx15SiFRLQ21oFn8whqjWKMUa5RijVKsUYo1SrFGKdYoD99Iwm9S6ZLQqdxIQqfSJeE3qZwUa5RijVKsUR4uqXxSEm4koVPpktCp3FD5pCTcKNYoxRqlWKM8vJSEGyqflISTJHQqN5JwQ+WNYo1SrFGKNcrDH6PSJaFT6ZLwlxRrlGKNUqxRHoZT6ZJwkoS/rFijFGuUYo3y8JLKT0pCp9IloVPpkvCGym8q1ijFGqVYozxcSsL/WRL+pWKNUqxRijVK/MIao1ijFGuUYo3y8I0knKicJOGGyicloVM5SUKn0iXhDZWTYo1SrFGKNcrDN1S6JJwkoVPpktCpdEk4UemS0KncSMJPUrlRrFGKNUqxRnn4RhJOktCpdEnoVLoknKh8UhJOVLokdConSXijWKMUa5RijfJwSaVLQpeETqVLQqfyhkqXhBsqXRLeUHmjWKMUa5RijfLwkkqXhBOVLgmdSpeETuWGSpeEE5U3ktCp3CjWKMUapVijPHxD5YbKDZU3ktCpdEnoVG4k4UTlJAmdykmxRinWKMUa5eEbSfhNKp1Kl4ROpUtCp9Il4Tep3CjWKMUapVijPFxS+aQknCShU+mS8IZKl4QTlROVN4o1SrFGKdYoDy8l4YbKJ6l0SeiS0KlMVqxRijVKsUZ5GE6lS8KJykkSTlS6JHRJ6FS6JJyonBRrlGKNUqxRHv4YlS4JN1S6JHRJeEPljWKNUqxRijXKw0sqPykJnUqn0iWhU+mS0KlMUqxRijVKsUZ5uJSEfykJnconJeFE5UYSOpWTYo1SrFGKNUr8whqjWKMUa5RijVKsUYo1SrFGKdYo/wGkAAXlwY+9dgAAAABJRU5ErkJggg==';
fs.writeFileSync(`${dist}/qr.png`, a.replace('data:image/png;base64,', ''), 'base64');
}

await exec('cp', [`${dist}/index.html`, `${dist}/200.html`]);
Expand All @@ -200,6 +199,10 @@ ${formatImage({
buildingLogUrl,
imageUrl:
'https://user-images.githubusercontent.com/507615/90250366-88233900-de6e-11ea-95a5-84f0762ffd39.png',
gitCommitSha,
url: `https://${url}`,
status: 'Done',
buildTime: `${duration}s`,
})}
${getCommentFooter()}
Expand Down
19 changes: 18 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ export const execSurgeCommand = async ({ command }: ExecSurgeCommandOptions): Pr
export const formatImage = ({
buildingLogUrl,
imageUrl,
gitCommitSha,
url,
status,
buildTime,
}: {
buildingLogUrl: string;
imageUrl: string;
gitCommitSha: string;
url: string;
status: string;
buildTime?: string;
}) => {
return `<a href="${buildingLogUrl}"><img width="300" src="${imageUrl}"></a>`;
return `
| Name | |
|---|---|
| Status | ${status} |
| Commit | ${gitCommitSha} |
| Deploy log | [1223123](${buildingLogUrl}) |
| Build time | ${buildTime || '...'} |
| Preview | ${url} |
| Preview on Mobile | <details> <summary>Click me</summary> <img style="display: block;-webkit-user-select: none;margin: auto;background-color: hsl(0, 0%, 90%);transition: background-color 300ms;" src="https://images.unsplash.com/photo-1682687220975-7b2df674d3ce?q=80&w=3540&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"> </details> |
`;
};

export const getCommentFooter = () => {
Expand Down

0 comments on commit 3b8903d

Please sign in to comment.