Skip to content

Commit fc6274c

Browse files
committed
feat: Report repo changes as a patch
1 parent e7bad61 commit fc6274c

File tree

9 files changed

+14283
-2972
lines changed

9 files changed

+14283
-2972
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# You know why
12
node_modules
2-
33
yarn-debug.log*
44
yarn-error.log*
55

6+
# Temporary build output
67
build
8+
9+
# Files created when testing this action on itself.
10+
appmap.yml
11+
patch

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
description: Enable verbose logging.
1515
required: false
1616
default: false
17+
outputs:
18+
patch:
19+
description: Patch file of changes made by the installer.
1720
runs:
1821
using: 'node16'
1922
main: 'dist/index.js'

dist/index.js

Lines changed: 13003 additions & 2961 deletions
Large diffs are not rendered by default.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 389 additions & 5 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"typescript": "^5.0.2"
1919
},
2020
"dependencies": {
21+
"@actions/artifact": "^1.1.1",
2122
"@actions/core": "^1.10.0",
2223
"@actions/github": "^5.1.1",
2324
"node-fetch": "^2"

src/Installer.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import {chmod, writeFile} from 'fs/promises';
1+
import {chmod, readFile, writeFile} from 'fs/promises';
22
import {tmpdir} from 'os';
33
import {join} from 'path';
44
import {downloadFile} from './downloadFile';
55
import {executeCommand} from './executeCommand';
66

77
export interface Logger {
8+
debug(message: string): void;
89
info(message: string): void;
910
warn(message: string): void;
1011
}
@@ -25,12 +26,21 @@ export default class Installer {
2526

2627
async installAppMapLibrary() {
2728
if (this.appmapConfig) {
28-
await writeFile('.appmap.yml', this.appmapConfig);
29+
this.logger.info(`Installing the appmap.yml configuration provided by action input.`);
30+
await writeFile('appmap.yml', this.appmapConfig);
2931
}
3032
await executeCommand(
3133
`${this.appmapToolsPath} install --no-interactive --no-overwrite-appmap-config`
3234
);
3335

3436
this.logger.info(`AppMap language library has been installed and configured.`);
3537
}
38+
39+
async buildPatchFile() {
40+
await executeCommand(`git add -N .`);
41+
await executeCommand(`git diff > patch`);
42+
const patch = await readFile('patch', 'utf8');
43+
this.logger.debug(`Patch file contents:\n${patch}`);
44+
return 'patch';
45+
}
3646
}

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import * as core from '@actions/core';
2+
import * as artifact from '@actions/artifact';
3+
import assert from 'assert';
24
import Installer, {Logger} from './Installer';
35
import verbose from './verbose';
6+
import {readFile} from 'fs/promises';
7+
8+
type UploadArtifact = (path: string) => Promise<void>;
9+
10+
let uploadArtifact: UploadArtifact | undefined;
411

512
class ActionLogger implements Logger {
13+
debug(message: string): void {
14+
core.debug(message);
15+
}
16+
617
info(message: string): void {
718
core.info(message);
819
}
@@ -16,13 +27,22 @@ function usage(): string {
1627
return `Usage: node ${process.argv[1]} <appmap-tools-url>`;
1728
}
1829

30+
async function uploadPatchFile(path: string) {
31+
core.setOutput('patch', await readFile(path, 'utf8'));
32+
const upload = artifact.create();
33+
await upload.uploadArtifact('patch', [path], '.');
34+
}
35+
1936
function runInGitHub(): Installer {
2037
core.debug(`Env var 'CI' is set. Running as a GitHub action.`);
2138
verbose(core.getBooleanInput('verbose'));
2239
const appmapConfig = core.getInput('appmap-config');
2340
const appmapToolsURL = core.getInput('tools-url');
2441
const installer = new Installer(appmapToolsURL, new ActionLogger());
2542
if (appmapConfig) installer.appmapConfig = appmapConfig;
43+
44+
uploadArtifact = uploadPatchFile;
45+
2646
return installer;
2747
}
2848

@@ -31,6 +51,10 @@ function runAsScript(): Installer {
3151
const appmapToolsURL = process.argv[2];
3252
if (!appmapToolsURL) throw new Error(usage());
3353
const installer = new Installer(appmapToolsURL);
54+
55+
uploadArtifact = (path: string) =>
56+
Promise.resolve(console.log(`Repository changes stored in patch file: ${path}`));
57+
3458
return installer;
3559
}
3660

@@ -41,4 +65,7 @@ function runAsScript(): Installer {
4165

4266
await installer.installAppMapTools();
4367
await installer.installAppMapLibrary();
68+
const patchFile = await installer.buildPatchFile();
69+
assert(uploadArtifact);
70+
await uploadArtifact(patchFile);
4471
})();

0 commit comments

Comments
 (0)