Skip to content

Commit

Permalink
fix(action): link to comparadise from github status (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jul 6, 2023
1 parent 3f20710 commit 2cf3d63
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}

- uses: nrwl/nx-set-shas@v3

Expand All @@ -41,10 +38,5 @@ jobs:
if [[ $(git status --porcelain) ]]; then
echo "Detected uncommitted changes after build. See status below:"
git status
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "chore: committing generated code"
git push
exit 1
fi
32 changes: 27 additions & 5 deletions action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11831,6 +11831,27 @@ function wrappy (fn, cb) {
}


/***/ }),

/***/ 1555:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.buildComparadiseUrl = void 0;
const core_1 = __nccwpck_require__(3610);
const github_1 = __nccwpck_require__(1419);
const buildComparadiseUrl = () => {
const bucketName = (0, core_1.getInput)('bucket-name', { required: true });
const commitHash = (0, core_1.getInput)('commit-hash', { required: true });
const comparadiseHost = (0, core_1.getInput)('comparadise-host');
const { owner, repo } = github_1.context.repo;
return `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
};
exports.buildComparadiseUrl = buildComparadiseUrl;


/***/ }),

/***/ 6330:
Expand All @@ -11843,12 +11864,11 @@ exports.createGithubComment = void 0;
const octokit_1 = __nccwpck_require__(2749);
const github_1 = __nccwpck_require__(1419);
const core_1 = __nccwpck_require__(3610);
const build_comparadise_url_1 = __nccwpck_require__(1555);
const createGithubComment = async () => {
const bucketName = (0, core_1.getInput)('bucket-name', { required: true });
const commitHash = (0, core_1.getInput)('commit-hash', { required: true });
const comparadiseHost = (0, core_1.getInput)('comparadise-host');
const { owner, repo } = github_1.context.repo;
const comparadiseUrl = `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
const comparadiseUrl = (0, build_comparadise_url_1.buildComparadiseUrl)();
const comparadiseLink = comparadiseHost
? `[Comparadise](${comparadiseUrl})`
: 'Comparadise';
Expand Down Expand Up @@ -11957,6 +11977,7 @@ const glob_1 = __nccwpck_require__(1057);
const comment_1 = __nccwpck_require__(6330);
const get_latest_visual_regression_status_1 = __nccwpck_require__(5399);
const shared_1 = __nccwpck_require__(9201);
const build_comparadise_url_1 = __nccwpck_require__(1555);
const run = async () => {
const visualTestCommands = (0, core_1.getMultilineInput)('visual-test-command', {
required: true,
Expand Down Expand Up @@ -12007,8 +12028,9 @@ const run = async () => {
context: shared_1.VISUAL_REGRESSION_CONTEXT,
state: 'failure',
description: diffFileCount === 0
? 'A new visual test was created!'
: 'A visual regression was detected!',
? 'A new visual test was created. Check Comparadise!'
: 'A visual regression was detected. Check Comparadise!',
target_url: (0, build_comparadise_url_1.buildComparadiseUrl)(),
...github_1.context.repo,
});
await (0, comment_1.createGithubComment)();
Expand Down
2 changes: 1 addition & 1 deletion action/dist/index.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions action/src/build-comparadise-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getInput } from '@actions/core';
import { context } from '@actions/github';

export const buildComparadiseUrl = () => {
const bucketName = getInput('bucket-name', { required: true });
const commitHash = getInput('commit-hash', { required: true });
const comparadiseHost = getInput('comparadise-host');
const { owner, repo } = context.repo;

return `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
};
5 changes: 2 additions & 3 deletions action/src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { octokit } from './octokit';
import { context } from '@actions/github';
import { getInput } from '@actions/core';
import { buildComparadiseUrl } from './build-comparadise-url';

export const createGithubComment = async () => {
const bucketName = getInput('bucket-name', { required: true });
const commitHash = getInput('commit-hash', { required: true });
const comparadiseHost = getInput('comparadise-host');
const { owner, repo } = context.repo;
const comparadiseUrl = `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
const comparadiseUrl = buildComparadiseUrl();
const comparadiseLink = comparadiseHost
? `[Comparadise](${comparadiseUrl})`
: 'Comparadise';
Expand Down
6 changes: 4 additions & 2 deletions action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
VISUAL_REGRESSION_CONTEXT,
VISUAL_TESTS_FAILED_TO_EXECUTE,
} from 'shared';
import { buildComparadiseUrl } from './build-comparadise-url';

export const run = async () => {
const visualTestCommands = getMultilineInput('visual-test-command', {
Expand Down Expand Up @@ -96,8 +97,9 @@ export const run = async () => {
state: 'failure',
description:
diffFileCount === 0
? 'A new visual test was created!'
: 'A visual regression was detected!',
? 'A new visual test was created. Check Comparadise!'
: 'A visual regression was detected. Check Comparadise!',
target_url: buildComparadiseUrl(),
...context.repo,
});
await createGithubComment();
Expand Down
9 changes: 7 additions & 2 deletions action/test/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const inputMap: Record<string, string> = {
'bucket-name': 'some-bucket',
'commit-hash': 'sha',
'github-token': 'some-token',
'comparadise-host': 'https://comparadise.app',
};
(getInput as jest.Mock).mockImplementation(name => inputMap[name]);
const multiLineInputMap: Record<string, string[]> = {
Expand Down Expand Up @@ -100,7 +101,9 @@ describe('main', () => {
sha: 'sha',
context: VISUAL_REGRESSION_CONTEXT,
state: 'failure',
description: 'A visual regression was detected!',
description: 'A visual regression was detected. Check Comparadise!',
target_url:
'https://comparadise.app/?hash=sha&owner=owner&repo=repo&bucket=some-bucket',
});
expect(octokit.rest.issues.createComment).toHaveBeenCalled();
});
Expand All @@ -119,7 +122,9 @@ describe('main', () => {
sha: 'sha',
context: VISUAL_REGRESSION_CONTEXT,
state: 'failure',
description: 'A new visual test was created!',
description: 'A new visual test was created. Check Comparadise!',
target_url:
'https://comparadise.app/?hash=sha&owner=owner&repo=repo&bucket=some-bucket',
});
expect(octokit.rest.issues.createComment).toHaveBeenCalled();
});
Expand Down

0 comments on commit 2cf3d63

Please sign in to comment.