Skip to content

Commit

Permalink
Merge pull request #6 from getappmap/feat/markdown-report
Browse files Browse the repository at this point in the history
feat: Add support for writing a GitHub Action summary
  • Loading branch information
kgilpin authored Apr 11, 2023
2 parents 07aed79 + 87795c0 commit 154e805
Show file tree
Hide file tree
Showing 19 changed files with 15,593 additions and 2,670 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
yarn-debug.log*
yarn-error.log*
.DS_Store

# Temporary build output
build
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib/
node_modules/
node_modules/
**/*.hbs
13,737 changes: 11,103 additions & 2,634 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ under a Creative Commons Attribution-ShareAlike 4.0 International License
https://creativecommons.org/licenses/by-sa/4.0/


handlebars
MIT
Copyright (C) 2011-2019 by Yehuda Katz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


inflight
ISC
The ISC License
Expand Down Expand Up @@ -570,6 +593,38 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


source-map
BSD-3-Clause

Copyright (c) 2009-2011, Mozilla Foundation and contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the names of the Mozilla Foundation nor the names of project
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


tmp
MIT
The MIT License (MIT)
Expand Down
159 changes: 159 additions & 0 deletions dist/templates/markdown.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# AppMap

| Summary | Status |
| --- | --- |
| [Test failures](#test-failures) | {{#if testFailures.length}}:warning: {{testFailures.length}} failed{{/if}}{{#unless testFailures.length}}:white_check_mark: All tests passed{{/unless}} |
| [API changes](#api-changes) |
{{~#unless apiDiff.differenceCount }}
:white_check_mark: No API changes
{{~/unless}}
{{~#if apiDiff.differenceCount }}
{{~#if apiDiff.breakingDifferencesFound }}:warning:{{/if~}}
{{~#unless apiDiff.breakingDifferencesFound }}:wrench:{{/unless~}}
 {{apiDiff.differenceCount}}
{{~#if apiDiff.breakingDifferencesFound }} breaking {{/if~}}
{{~#unless apiDiff.breakingDifferencesFound }} compatible {{/unless~}}
changes
{{~/if}}
|
| [Changed AppMaps](#changed-appmaps) |
{{~#unless changedAppMaps.length }}
:white_check_mark: No changes
{{~/unless}}
{{~#if changedAppMaps.length }}
:wrench: {{changedAppMaps.length}} changes
{{~/if}}
|
| [Changed Code Behavior](#changed-code-behavior) |
{{~#unless sequenceDiagramDiffSnippetCount }}
:white_check_mark: No changes
{{~/unless}}
{{~#if sequenceDiagramDiffSnippetCount }}
:wrench: {{sequenceDiagramDiffSnippetCount}} changes
{{~/if}}
|

## Test failures

{{#each testFailures}}

<details>
<summary>
{{testLocation}}
</summary>

<table>
<tbody>
<tr>
<td>Test case file</td>
<td><a href="{{testPath}}">{{testLocation}}</a></td>
</tr>
{{#if changedAppMap}}
{{#with changedAppMap}}
<tr>
<td>Sequence diagram diff</td>
<td>
<a href="./{{sequenceDiagramDiff}}">{{sequenceDiagramDiff}}</a>
</td>
</tr>
<tr>
<td>Source diff</td>
<td>

```diff
{{sourceDiff}}
```

</td>
</tr>
{{/with}}
{{/if}}
<tr>
<td>AppMap</td>
<td><a href="./head/{{appmap}}.appmap.json">{{appmap}}</a></td>
</tr>
</tbody>
</table>

</details>

{{/each}}

## API changes

{{#*inline "api-diff"}}
{{action}} {{#each sourceSpecEntityDetails}}{{location}}{{/each}}
{{/inline}}

{{#if apiDiff.breakingDifferences}}
### Breaking changes

{{#each apiDiff.breakingDifferences}}
- {{> api-diff }}
{{/each}}
{{/if}}

{{#if apiDiff.nonBreakingDifferences}}
### Non-breaking changes

{{#each apiDiff.nonBreakingDifferences}}
- {{> api-diff }}
{{/each}}
{{/if}}

{{#if apiDiff.unclassifiedDifferences}}
### Unclassified changes

{{#each apiDiff.unclassifiedDifferences}}
- {{> api-diff }}
{{/each}}
{{/if}}

## Changed AppMaps
{{#each changedAppMaps}}
<details>

<summary>
{{appmap}}
</summary>

<table>
<tbody>
<tr>
<td>Source diff</td>
<td>

```diff
{{sourceDiff}}
```

</td>
</tr>
<tr>
<td>Sequence diagram diff</td>
<td>
<a href="./{{sequenceDiagramDiff}}">{{sequenceDiagramDiff}}</a>
</tr>
</tbody>
</table>

</details>
{{/each}}

## Changed code behavior

{{#each sequenceDiagramDiffSnippets}}

```
{{{@key}}}
```

<details>
<summary>{{ this.length }} occurrances</summary>

{{#each this}}
- [{{.}}](./diff/{{.}}.diff.sequence.json)
{{/each}}
</details>

{{/each}}
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
"license": "MIT",
"main": "build/index.js",
"scripts": {
"build": "tsc",
"build": "tsc && yarn copy:assets:build",
"test": "jest",
"appmap": "appmap-agent-js -- jest --no-cache",
"clean": "rm -rf build dist tmp",
"format": "prettier --write '**/*.ts'",
"package": "ncc build --source-map --license licenses.txt"
"package": "ncc build --source-map --license licenses.txt && yarn copy:assets:package",
"copy:assets:build": "cp -r src/report/templates build/report/",
"copy:assets:package": "cp -r src/report/templates dist/"
},
"devDependencies": {
"@appland/appmap-agent-js": "^13.6.0",
"@appland/models": "^2.4.2",
"@appland/scanner": "^1.76.8",
"@types/argparse": "^2.0.10",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"@vercel/ncc": "^0.36.1",
"glob": "^9.3.4",
"jest": "^29.5.0",
"openapi-diff": "^0.23.6",
"prettier": "^2.8.7",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
Expand All @@ -29,7 +35,10 @@
"@actions/artifact": "^1.1.1",
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@types/argparse": "^2.0.10",
"argparse": "^2.0.1"
"argparse": "^2.0.1",
"handlebars": "^4.7.7"
},
"engines": {
"node": ">=16.0.0"
}
}
1 change: 1 addition & 0 deletions src/CommandOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface CommandOptions {
baseRef: string;
headRef: string;
appmapCommand?: string;
basePath?: string;
sourceDir?: string;
githubToken?: string;
githubRepo?: string;
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import assert from 'assert';
import {DirectoryArtifactStore} from './DirectoryArtifactStore';
import run from './run';
import {GitHubArtifactStore} from './GitHubArtifactStore';
import {writeFile} from 'fs/promises';

async function runInGitHub(): Promise<void> {
verbose(core.getBooleanInput('verbose'));
Expand All @@ -29,13 +30,19 @@ async function runInGitHub(): Promise<void> {
assert(baseRef, 'baseRef is undefined');
assert(headRef, 'headRef is undefined');

await run(new GitHubArtifactStore(), {
const basePath = [process.env.GITHUB_SERVER_URL, githubRepo, 'tree', baseRef].join('/');

const {summary} = await run(new GitHubArtifactStore(), {
baseRef,
headRef,
basePath,
sourceDir,
githubRepo,
githubToken,
});
if (process.env.GITHUB_STEP_SUMMARY) {
await writeFile(process.env.GITHUB_STEP_SUMMARY, summary);
}
}

async function runLocally() {
Expand All @@ -60,14 +67,15 @@ async function runLocally() {
const directory = options.directory;
if (directory) process.chdir(directory);

await run(new DirectoryArtifactStore(artifactDir), {
const summary = await run(new DirectoryArtifactStore(artifactDir), {
appmapCommand: options.appmap_command,
baseRef: options.base_revision,
headRef: options.head_revision,
sourceDir: options.source_dir,
githubToken: options.github_token,
githubRepo: options.github_repo,
});
console.log(summary);
}

if (require.main === module) {
Expand Down
40 changes: 40 additions & 0 deletions src/report/ChangeReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Metadata} from '@appland/models';
import Finding from './Finding';

export type AppMapLink = string;
export type SequenceDiagramLink = string;
// AppMap file path, without the .appmap.json extension.
export type AppMapName = string;
// hex digest of an AppMap's canonical sequence diagram.
export type AppMapDigest = string;

export type ChangedAppMap = {
appmap: string;
sourceDiff?: string | undefined;
sequenceDiagramDiff?: SequenceDiagramLink;
};

export type TestFailure = {
appmap: string;
changedAppMap?: ChangedAppMap;
name: string;
testLocation?: string;
};

export type ChangeReport = {
testFailures: TestFailure[];
newAppMaps: AppMapLink[];
changedAppMaps: ChangedAppMap[];
newFindings: Finding[];
resolvedFindings: Finding[];
apiDiff: any;
scanConfiguration: {
base: any;
head: any;
};
appMapMetadata: {
base: Record<AppMapName, Metadata>;
head: Record<AppMapName, Metadata>;
};
sequenceDiagramDiffSnippets: Record<string, AppMapLink[]>;
};
Loading

0 comments on commit 154e805

Please sign in to comment.