Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ permissions:
pull-requests: write # To comment on pull requests
```

The report is also written to the [job summary](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#adding-a-job-summary) of the workflow run, which doesn't need any extra permissions.

## Artifact Mode

By default, the action posts a comment directly to the pull request. This requires `pull-requests: write` permission in the workflow that runs the analysis, which typically means using `pull_request_target` for fork PRs.
Expand Down
18 changes: 12 additions & 6 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19836,6 +19836,7 @@ var Summary = class {
}
};
var _summary = new Summary();
var summary = _summary;

// node_modules/@actions/core/lib/platform.js
import os3 from "os";
Expand Down Expand Up @@ -25130,6 +25131,13 @@ async function findExistingComment(octokit, prNumber) {
}
return void 0;
}
async function writeJobSummary(report) {
try {
await summary.addRaw(report).write();
} catch (err) {
info(`Failed to write job summary: ${err}`);
}
}
async function upsertComment(octokit, prNumber, body) {
const { owner, repo } = context2.repo;
const existingCommentId = await findExistingComment(octokit, prNumber);
Expand Down Expand Up @@ -25348,12 +25356,10 @@ async function analyzeAndComment() {
);
scanForReplacements(messages, baseDependencies, currentDependencies);
}
const commentBody = messages.length === 0 ? `${COMMENT_TAG}
## e18e dependency analysis

No dependency warnings found.
` : `${COMMENT_TAG}
${messages.join("\n\n")}`;
const report = messages.length === 0 ? "## e18e dependency analysis\n\nNo dependency warnings found.\n" : messages.join("\n\n");
const commentBody = `${COMMENT_TAG}
${report}`;
await writeJobSummary(report);
if (mode === "artifact") {
const tmpDir = join2(baseWorkspace, ".e18e-tmp");
const outputPath = join2(tmpDir, ARTIFACT_FILENAME);
Expand Down
8 changes: 8 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export async function findExistingComment(
return undefined;
}

export async function writeJobSummary(report: string): Promise<void> {
try {
await core.summary.addRaw(report).write();
} catch (err) {
core.info(`Failed to write job summary: ${err}`);
}
}

export async function upsertComment(
octokit: Octokit,
prNumber: number,
Expand Down
11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {scanForLicenses} from './checks/license.js';
import {scanForBundleSize} from './checks/bundle-size.js';
import {formatBytes, parseCommaList} from './common.js';
import {ARTIFACT_FILENAME, COMMENT_TAG} from './constants.js';
import {findExistingComment, upsertComment} from './github.js';
import {findExistingComment, upsertComment, writeJobSummary} from './github.js';

interface ArtifactResult {
pr_number: number;
Expand Down Expand Up @@ -266,10 +266,13 @@ async function analyzeAndComment(): Promise<void> {
scanForReplacements(messages, baseDependencies, currentDependencies);
}

const commentBody =
const report =
messages.length === 0
? `${COMMENT_TAG}\n## e18e dependency analysis\n\nNo dependency warnings found.\n`
: `${COMMENT_TAG}\n${messages.join('\n\n')}`;
? '## e18e dependency analysis\n\nNo dependency warnings found.\n'
: messages.join('\n\n');
const commentBody = `${COMMENT_TAG}\n${report}`;

await writeJobSummary(report);

if (mode === 'artifact') {
const tmpDir = join(baseWorkspace, '.e18e-tmp');
Expand Down
39 changes: 39 additions & 0 deletions test/github_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
import * as fs from 'node:fs/promises';
import * as os from 'node:os';
import * as path from 'node:path';
import * as process from 'process';
import {writeJobSummary} from '../src/github.js';
import {coreLogs, clearCoreLogs} from './util.js';

describe('writeJobSummary', () => {
let tmpDir: string;

beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'job-summary-'));
});

afterEach(async () => {
delete process.env['GITHUB_STEP_SUMMARY'];
clearCoreLogs();
await fs.rm(tmpDir, {recursive: true, force: true});
});

it('should write the report to the job summary', async () => {
const summaryPath = path.join(tmpDir, 'summary.md');
await fs.writeFile(summaryPath, '');
process.env['GITHUB_STEP_SUMMARY'] = summaryPath;

await writeJobSummary('## e18e dependency analysis\n\nsome report');

const content = await fs.readFile(summaryPath, 'utf-8');
expect(content).toContain('## e18e dependency analysis\n\nsome report');
});

it('should not throw if the job summary cannot be written', async () => {
process.env['GITHUB_STEP_SUMMARY'] = path.join(tmpDir, 'missing.md');

await expect(writeJobSummary('report')).resolves.toBeUndefined();
expect(coreLogs.info.join('\n')).toContain('Failed to write job summary');
});
});