mirror of
https://github.com/graalvm/setup-graalvm.git
synced 2025-03-13 14:30:15 +08:00
refactor report and utils.ts
This commit is contained in:
parent
d0de3476cf
commit
714a309928
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@ -49,7 +49,7 @@ jobs:
|
||||
|
||||
# If index.js was different than expected, upload the expected version as an artifact
|
||||
- uses: actions/upload-artifact@v3
|
||||
# if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
|
@ -50,9 +50,6 @@ inputs:
|
||||
gds-token:
|
||||
required: false
|
||||
description: 'Download token for the GraalVM Download Service. If provided, the action will set up GraalVM Enterprise Edition.'
|
||||
report-token:
|
||||
required: false
|
||||
description: 'Github-Token for add build report tp repository.'
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
|
@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write '**/*.ts'",
|
||||
"format-check": "prettier --check '**/*.ts'",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build -o dist/main src/main.ts && ncc build -o dist/cleanup src/cleanup.ts",
|
||||
"test": "jest",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as otypes from '@octokit/types'
|
||||
import {context} from "@actions/github";
|
||||
|
||||
export const INPUT_VERSION = 'version'
|
||||
export const INPUT_GDS_TOKEN = 'gds-token'
|
||||
@ -10,7 +11,6 @@ export const INPUT_SET_JAVA_HOME = 'set-java-home'
|
||||
export const INPUT_CACHE = 'cache'
|
||||
export const INPUT_CHECK_FOR_UPDATES = 'check-for-updates'
|
||||
export const INPUT_NI_MUSL = 'native-image-musl'
|
||||
export const INPUT_REPORT_TOKEN = 'report-token'
|
||||
|
||||
export const IS_LINUX = process.platform === 'linux'
|
||||
export const IS_MACOS = process.platform === 'darwin'
|
||||
@ -44,12 +44,20 @@ export const EVENT_NAME_PULL_REQUEST = 'pull_request'
|
||||
export const ERROR_HINT =
|
||||
'If you think this is a mistake, please file an issue at: https://github.com/graalvm/setup-graalvm/issues.'
|
||||
|
||||
export const METRIC_REF_PATH = 'refs/graalvm-metrics'
|
||||
|
||||
export const OCTOKIT_ROUTE_REF_METRICS = `GET /repos/${context.repo.owner}/${context.repo.repo}/git/ref/metrics/${baseCommitSha}`
|
||||
|
||||
export type LatestReleaseResponse =
|
||||
otypes.Endpoints['GET /repos/{owner}/{repo}/releases/latest']['response']
|
||||
|
||||
export type MatchingRefsResponse =
|
||||
otypes.Endpoints['GET /repos/{owner}/{repo}/git/matching-refs/{ref}']['response']
|
||||
|
||||
export type LatestReleaseResponse =
|
||||
otypes.Endpoints['GET /repos/{owner}/{repo}/releases/latest']['response']
|
||||
|
||||
|
||||
function determineJDKArchitecture(): string {
|
||||
switch (process.arch) {
|
||||
case 'x64': {
|
||||
|
@ -6,9 +6,6 @@ import {join} from 'path'
|
||||
import {tmpdir} from 'os'
|
||||
import {createPRComment, createRef, createTree, getPrBaseBranchMetrics, isPREvent, toSemVer} from '../utils'
|
||||
import {gte} from 'semver'
|
||||
import {Base64} from 'js-base64';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import fetch from "node-fetch";
|
||||
|
||||
const BUILD_OUTPUT_JSON_PATH = join(tmpdir(), 'native-image-build-output.json')
|
||||
const BYTES_TO_KiB = 1024
|
||||
@ -23,9 +20,6 @@ const NATIVE_IMAGE_CONFIG_FILE = join(
|
||||
'native-image-options.properties'
|
||||
)
|
||||
const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'
|
||||
//const { Octokit } = require("@octokit/rest");
|
||||
|
||||
let REPORT_TOKEN = '';
|
||||
|
||||
interface AnalysisResult {
|
||||
total: number
|
||||
@ -119,7 +113,6 @@ export async function setUpNativeImageBuildReports(
|
||||
setNativeImageOption(
|
||||
`-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`
|
||||
)// Escape backslashes for Windows
|
||||
REPORT_TOKEN = reportToken
|
||||
}
|
||||
|
||||
export async function generateReports(): Promise<void> {
|
||||
@ -139,7 +132,6 @@ export async function generateReports(): Promise<void> {
|
||||
const prMetrics: BuildOutput = JSON.parse(
|
||||
await getPrBaseBranchMetrics()
|
||||
)
|
||||
const prBaseReport = createReport(prMetrics)
|
||||
|
||||
const report = createReport(buildOutput)
|
||||
if (areJobReportsEnabled()) {
|
||||
@ -148,9 +140,9 @@ export async function generateReports(): Promise<void> {
|
||||
}
|
||||
if (arePRReportsEnabled()) {
|
||||
createPRComment(report)
|
||||
const prBaseReport = createPRComparison(buildOutput, prMetrics)
|
||||
createPRComment(prBaseReport)
|
||||
}
|
||||
const prBaseReport = createPRComparison(buildOutput, prMetrics)
|
||||
createPRComment(prBaseReport)
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,7 +306,7 @@ function createReport(data: BuildOutput): string {
|
||||
)} of total time)`
|
||||
}
|
||||
|
||||
return `## GraalVM Native Image Build Report example
|
||||
return `## GraalVM Native Image Build Report
|
||||
|
||||
\`${info.name}\` generated${totalTime} as part of the '${
|
||||
context.job
|
||||
|
@ -19,7 +19,6 @@ async function run(): Promise<void> {
|
||||
const distribution = core.getInput(c.INPUT_DISTRIBUTION)
|
||||
const graalVMVersion = core.getInput(c.INPUT_VERSION)
|
||||
const gdsToken = core.getInput(c.INPUT_GDS_TOKEN)
|
||||
const reportToken = core.getInput(c.INPUT_REPORT_TOKEN)
|
||||
const componentsString: string = core.getInput(c.INPUT_COMPONENTS)
|
||||
const components: string[] =
|
||||
componentsString.length > 0
|
||||
|
61
src/utils.ts
61
src/utils.ts
@ -161,13 +161,10 @@ function getGitHubToken(): string {
|
||||
}
|
||||
|
||||
function getCommitSha(): string {
|
||||
return process.env.GITHUB_SHA || "default_tag"
|
||||
return process.env.GITHUB_SHA || "default_sha"
|
||||
}
|
||||
|
||||
function getPrBaseBranchSha(): string {
|
||||
if (!isPREvent()) {
|
||||
return ""
|
||||
}
|
||||
return process.env.GITHUB_BASE_REF || "default_branch"
|
||||
}
|
||||
|
||||
@ -190,30 +187,35 @@ export async function createPRComment(content: string): Promise<void> {
|
||||
}
|
||||
|
||||
export async function createRef(sha: string) {
|
||||
const commitSha = getCommitSha()
|
||||
const ref = `refs/metrics/${commitSha}`
|
||||
console.log(`creating ref ${ref} for metrics tree ${sha}`);
|
||||
const octokit = new Octokit({
|
||||
auth: getGitHubToken(),
|
||||
request: {
|
||||
fetch: fetch,
|
||||
},
|
||||
});
|
||||
const context = github.context
|
||||
|
||||
const response = await octokit.request(
|
||||
`POST /repos/${context.repo.owner}/${context.repo.repo}/git/refs`,
|
||||
{
|
||||
...context.repo,
|
||||
ref,
|
||||
sha,
|
||||
}
|
||||
);
|
||||
|
||||
core.info(response.data);
|
||||
try {
|
||||
const commitSha = getCommitSha()
|
||||
const ref = c.METRIC_REF_PATH + commitSha
|
||||
core.info(`creating ref ${ref} for metrics tree ${sha}`);
|
||||
const octokit = new Octokit({
|
||||
auth: getGitHubToken(),
|
||||
request: {
|
||||
fetch: fetch,
|
||||
},
|
||||
});
|
||||
const context = github.context
|
||||
await octokit.request(
|
||||
`POST /repos/${context.repo.owner}/${context.repo.repo}/git/refs`,
|
||||
{
|
||||
...context.repo,
|
||||
ref,
|
||||
sha,
|
||||
}
|
||||
);
|
||||
} catch(err) {
|
||||
core.error(
|
||||
`Failed to create ref. Please make sure that the referred sha '${sha}' exist.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTree(metadataJson: string): Promise<string> {
|
||||
try {
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: getGitHubToken(),
|
||||
request: {
|
||||
@ -221,9 +223,7 @@ export async function createTree(metadataJson: string): Promise<string> {
|
||||
},
|
||||
});
|
||||
const context = github.context
|
||||
|
||||
core.info(`creating tree at ${context.repo.owner}/${context.repo.repo}`);
|
||||
|
||||
const response = await octokit.request(
|
||||
`POST /repos/${context.repo.owner}/${context.repo.repo}/git/trees`,
|
||||
{
|
||||
@ -241,6 +241,11 @@ export async function createTree(metadataJson: string): Promise<string> {
|
||||
|
||||
core.info("Tree-sha" + response.data.sha);
|
||||
return response.data.sha;
|
||||
} catch (err) {
|
||||
core.error(
|
||||
`Creating metrics tree failed.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPrBaseBranchMetrics(): Promise<string> {
|
||||
@ -280,7 +285,7 @@ async function getBaseBranchCommitSha(octokit: Octokit, context: Context): Promi
|
||||
}
|
||||
|
||||
async function getBlobTreeSha(octokit: Octokit, context: Context, baseCommitSha: string): Promise<string> {
|
||||
const { data } = await octokit.request(`GET /repos/${context.repo.owner}/${context.repo.repo}/git/ref/metrics/${baseCommitSha}`, {
|
||||
const { data } = await octokit.request(, {
|
||||
...context.repo,
|
||||
headers: {
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
|
Loading…
x
Reference in New Issue
Block a user