Compare commits

..

2 Commits

Author SHA1 Message Date
Fabio Niephaus
81dd1da2d8 Force-upgrade minimatch.
See: https://github.com/actions/typescript-action/issues/1017#issuecomment-2659619253
2025-02-17 10:58:39 +01:00
Fabio Niephaus
d385f29997 Convert to ESM and use rollup.
First attempt: https://github.com/graalvm/setup-graalvm/pull/134
2025-02-17 10:53:29 +01:00
30 changed files with 130981 additions and 132360 deletions

View File

@@ -32,8 +32,6 @@ jobs:
run: npm run lint
- name: Test
run: npm run test
env:
INPUT_GITHUB_TOKEN: ${{ github.token }} # for core.getInput()
test-action:
name: GraalVM
@@ -43,7 +41,7 @@ jobs:
PASSES_GDS_TOKEN_CHECK: ${{ !matrix.set-gds-token || secrets.GDS_TOKEN != '' }}
strategy:
matrix:
java-version: ['24', '21', '17', '20', 'dev']
java-version: ['23', '21', '17', '20', 'dev']
distribution: ['graalvm', 'graalvm-community']
os: [
ubuntu-latest, # Linux on Intel
@@ -58,7 +56,7 @@ jobs:
- java-version: 'latest-ea'
distribution: 'graalvm'
os: ubuntu-latest
- java-version: '25-ea'
- java-version: '24-ea'
distribution: 'graalvm'
os: ubuntu-latest
- java-version: '21'
@@ -133,7 +131,7 @@ jobs:
- version: '22.2.0' # for update notifications
java-version: '17'
components: 'native-image'
os: ubuntu-22.04
os: ubuntu-20.04
- version: '21.2.0'
java-version: '8' # for JDK 8 notification
components: 'native-image'

View File

@@ -1,7 +1,5 @@
# GitHub Action for GraalVM [![CI](https://github.com/graalvm/setup-graalvm/actions/workflows/ci.yml/badge.svg)](https://github.com/graalvm/setup-graalvm/actions/workflows/ci.yml)
Set up your GitHub Actions workflow with a specific [GraalVM][graalvm] distribution, and use it both as your JDK and for [ahead-of-time Native Image compilation][graalvm].
This GitHub action sets up [Oracle GraalVM][graalvm-medium], GraalVM [Community Edition (CE)][repo], [Enterprise Edition (EE)][graalvm-ee], [Mandrel][mandrel], or [Liberica Native Image Kit][liberica] as well as [Native Image][native-image] and GraalVM components such as [Truffle languages][truffle-languages].
## Key Features
@@ -9,10 +7,12 @@ This action:
- supports Oracle GraalVM [releases][graalvm-dl], [EA builds][ea-builds], GraalVM Community Edition (CE) [releases], [dev builds][dev-builds], GraalVM Enterprise Edition (EE) [releases][graalvm-ee] (set [`gds-token`](#options)) 22.1.0 and later, [Mandrel][mandrel], and [Liberica Native Image Kit][liberica] (see [Options](#options))
- exports a `$GRAALVM_HOME` environment variable
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(`native-image`, `javac`, and other JDK tools can be invoked directly)
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(Native Image, Truffle languages, and tools can be invoked directly)
- sets `$JAVA_HOME` to `$GRAALVM_HOME` by default<br>(can be disabled via `set-java-home: 'false'`, see [Options](#options))
- supports `x64` and `aarch64/arm64` (see how to use [Linux arm64 runners](https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/))
- supports `x64` and `aarch64` (selected automatically, `aarch64` requires a [self-hosted runner][gha-self-hosted-runners])
- supports dependency caching for Apache Maven, Gradle, and sbt (see [`cache` option](#options))
- sets up Windows environments with build tools using [vcvarsall.bat][vcvarsall]
- has built-in support for GraalVM components and the [GraalVM Updater][gu]
## Templates
@@ -194,7 +194,7 @@ This actions can be configured with the following options:
| Name | Default | Description |
|-----------------|:--------:|-------------|
| `java-version`<br>*(required)* | n/a | Java version <ul><li>major versions: `'24'`, `'21'`, `'17'`, `'11'`, `'8'`</li><li>specific versions: `'21.0.3'`, `'17.0.11'`</li><li>early access (EA) builds: `'25-ea'` *(requires `distribution: 'graalvm'`)*</li><li>latest EA build: `'latest-ea'` *(requires `distribution: 'graalvm'`)*</li><li>dev builds: `'dev'`</li></ul> |
| `java-version`<br>*(required)* | n/a | Java version <ul><li>major versions: `'23'`, `'21'`, `'17'`, `'11'`, `'8'`</li><li>specific versions: `'21.0.3'`, `'17.0.11'`</li><li>early access (EA) builds: `'24-ea'` *(requires `distribution: 'graalvm'`)*</li><li>latest EA build: `'latest-ea'` *(requires `distribution: 'graalvm'`)*</li><li>dev builds: `'dev'`</li></ul> |
| `distribution` | `'graalvm'` | GraalVM distribution (see [supported distributions](#supported-distributions)) |
| `java-package` | `'jdk'` | The package type (`'jdk'` or `'jdk+fx'`). Currently applies to Liberica only. |
| `github-token` | `'${{ github.token }}'` | Token for communication with the GitHub API. Please set this to `${{ secrets.GITHUB_TOKEN }}` (see [templates](#templates)) to allow the action to authenticate with the GitHub API, which helps reduce rate-limiting issues. |
@@ -270,16 +270,21 @@ Only pull requests from committers that can be verified as having signed the OCA
[gha-self-hosted-runners]: https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
[graalvm]: https://www.graalvm.org/
[graalvm-dl]: https://www.graalvm.org/downloads/
[graalvm-dl]: https://www.oracle.com/java/technologies/downloads/
[graalvm-medium]: https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5
[graalvm-ee]: https://www.oracle.com/downloads/graalvm-downloads.html
[liberica]: https://bell-sw.com/liberica-native-image-kit/
[mandrel]: https://github.com/graalvm/mandrel
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
[musl]: https://musl.libc.org/
[native-image]: https://www.graalvm.org/native-image/
[native-image-musl-build]: https://github.com/graalvm/setup-graalvm/blob/778131f1d6837ccd4b2e91382c31830896a2d56e/.github/workflows/test.yml#L74-L92
[native-image-static]: https://github.com/oracle/graal/blob/fa6f4a974dedacf4688dcc430dd100849d9882f2/docs/reference-manual/native-image/StaticImages.md
[oca]: https://oca.opensource.oracle.com
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases
[repo]: https://github.com/oracle/graal
[setup-java-caching]: https://github.com/actions/setup-java/tree/5b36705a13905facb447b6812d613a06a07e371d#caching-packages-dependencies
[stable]: https://github.com/graalvm/graalvm-ce-builds/releases/latest
[truffle-languages]: https://www.graalvm.org/reference-manual/languages/
[vcvarsall]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line

View File

@@ -145,7 +145,6 @@ describe('sbom feature', () => {
writeFileSync(sbomPath, JSON.stringify(sbom, null, 2))
mockFindSBOM([sbomPath])
jest.spyOn(core, 'getState').mockReturnValue(javaVersion)
await processSBOM()
}
@@ -191,10 +190,6 @@ describe('sbom feature', () => {
]
}
it('should throw an error if setUpSBOMSupport was not called before processSBOM', async () => {
await expect(processSBOM()).rejects.toThrow('setUpSBOMSupport must be called before processSBOM')
})
it('should process SBOM and display components', async () => {
await setUpAndProcessSBOM(sampleSBOM)

View File

@@ -72,6 +72,6 @@ outputs:
description: 'A boolean value to indicate an exact match was found for the primary key'
runs:
using: 'node20'
main: 'dist/main/index.js'
post: 'dist/cleanup/index.js'
main: 'dist/main.js'
post: 'dist/cleanup.js'
post-if: 'success()'

126425
dist/cleanup/index.js → dist/cleanup.js generated vendored

File diff suppressed because one or more lines are too long

1
dist/cleanup.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

131076
dist/main/index.js → dist/main.js generated vendored

File diff suppressed because one or more lines are too long

1
dist/main.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +1,29 @@
module.exports = {
// See: https://jestjs.io/docs/configuration
/** @type {import('ts-jest').JestConfigWithTsJest} **/
export default {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['./src/**'],
coverageDirectory: './coverage',
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
coverageReporters: ['json-summary', 'text', 'lcov'],
moduleFileExtensions: ['js', 'ts'],
extensionsToTreatAsEsm: ['.ts'],
moduleFileExtensions: ['ts', 'js'],
preset: 'ts-jest',
reporters: ['default'],
resolver: 'ts-jest-resolver',
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: 'tsconfig.eslint.json',
useESM: true
}
]
},
verbose: true
}

5506
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,8 @@
"name": "setup-graalvm",
"author": "GraalVM Community",
"description": "GitHub Action for GraalVM",
"version": "1.3.6",
"version": "1.3.1",
"type": "module",
"private": true,
"repository": {
"type": "git",
@@ -26,49 +27,63 @@
"format:check": "npx prettier --check .",
"lint": "npx eslint .",
"package": "npm run package:main && npm run package:cleanup",
"package:main": "npx ncc build src/main.ts -o dist/main",
"package:cleanup": "npx ncc build src/cleanup.ts -o dist/cleanup",
"package:main": "npx rollup --config rollup.main.config.ts --configPlugin @rollup/plugin-typescript",
"package:cleanup": "npx rollup --config rollup.cleanup.config.ts --configPlugin @rollup/plugin-typescript",
"test": "npx jest",
"all": "npm run format:write && npm run lint && npm run test && npm run package"
},
"license": "UPL",
"dependencies": {
"@actions/cache": "^4.0.5",
"@actions/cache": "^4.0.0",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.5.0",
"@actions/http-client": "^2.2.3",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.2",
"@octokit/types": "^14.1.0",
"@github/dependency-submission-toolkit": "^2.0.5",
"semver": "^7.7.2",
"uuid": "^11.1.0"
"@octokit/core": "^5.2.0",
"@octokit/types": "^13.8.0",
"@github/dependency-submission-toolkit": "^2.0.4",
"semver": "^7.7.1",
"uuid": "^11.0.5"
},
"devDependencies": {
"@eslint/compat": "^1.3.1",
"@types/jest": "^30.0.0",
"@types/node": "^20.19.9",
"@types/semver": "^7.7.0",
"@eslint/compat": "^1.2.6",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.17",
"@types/semver": "^7.5.8",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.38.0",
"@typescript-eslint/parser": "^8.31.1",
"@vercel/ncc": "^0.38.3",
"eslint": "^9.31.0",
"eslint-config-prettier": "^10.1.8",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-jsonc": "^2.20.1",
"@typescript-eslint/eslint-plugin": "^8.24.0",
"@typescript-eslint/parser": "^8.24.0",
"eslint": "^9.20.1",
"eslint-config-prettier": "^10.0.1",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.10.0",
"eslint-plugin-jsonc": "^2.19.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.5.3",
"jest": "^30.0.5",
"eslint-plugin-prettier": "^5.2.3",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"prettier": "^3.6.2",
"prettier-eslint": "^16.4.2",
"ts-jest": "^29.4.0",
"prettier": "^3.5.0",
"prettier-eslint": "^16.3.0",
"rollup": "^4.34.1",
"ts-jest": "^29.2.5",
"ts-jest-resolver": "^2.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
"typescript": "^5.7.3"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "*"
},
"overrides": {
"@actions/glob": {
"minimatch": "^10.0.1"
}
}
}

19
rollup.cleanup.config.ts Normal file
View File

@@ -0,0 +1,19 @@
// See: https://rollupjs.org/introduction/
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
const config = {
input: 'src/cleanup.ts',
output: {
esModule: true,
file: 'dist/cleanup.js',
format: 'es',
sourcemap: true
},
plugins: [typescript(), nodeResolve(), commonjs(), json()]
}
export default config

19
rollup.main.config.ts Normal file
View File

@@ -0,0 +1,19 @@
// See: https://rollupjs.org/introduction/
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
const config = {
input: 'src/main.ts',
output: {
esModule: true,
file: 'dist/main.js',
format: 'es',
sourcemap: true
},
plugins: [typescript(), nodeResolve(), commonjs(), json()]
}
export default config

View File

@@ -25,10 +25,10 @@
*/
import * as core from '@actions/core'
import * as constants from './constants'
import { save } from './features/cache'
import { generateReports } from './features/reports'
import { processSBOM } from './features/sbom'
import * as constants from './constants.js'
import { save } from './features/cache.js'
import { generateReports } from './features/reports.js'
import { processSBOM } from './features/sbom.js'
/**
* Check given input and run a save process for the specified package manager

View File

@@ -1,6 +1,6 @@
import * as otypes from '@octokit/types'
export const ACTION_VERSION = '1.3.6'
export const ACTION_VERSION = '1.3.1'
export const INPUT_VERSION = 'version'
export const INPUT_GDS_TOKEN = 'gds-token'

View File

@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import { GRAALVM_PLATFORM } from './constants'
import { exec } from './utils'
import { GRAALVM_PLATFORM } from './constants.js'
import { exec } from './utils.js'
const APT_GET_INSTALL_BASE = 'sudo apt-get -y --no-upgrade install'
const COMPONENT_TO_DEPS = new Map<string, Map<string, string>>([

View File

@@ -1,7 +1,7 @@
import * as c from '../constants'
import * as c from '../constants.js'
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import { exec } from '../utils'
import { exec } from '../utils.js'
import { join } from 'path'
const MUSL_NAME = 'x86_64-linux-musl-native'

View File

@@ -1,4 +1,4 @@
import * as c from '../constants'
import * as c from '../constants.js'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as github from '@actions/github'
@@ -11,7 +11,7 @@ import {
updatePRComment,
tmpfile,
setNativeImageOption
} from '../utils'
} from '../utils.js'
const BUILD_OUTPUT_JSON_PATH = tmpfile('native-image-build-output.json')
const BYTES_TO_KiB = 1024

View File

@@ -1,16 +1,17 @@
import * as c from '../constants'
import * as c from '../constants.js'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as github from '@actions/github'
import * as glob from '@actions/glob'
import { basename } from 'path'
import * as semver from 'semver'
import { setNativeImageOption } from '../utils'
import { setNativeImageOption } from '../utils.js'
const INPUT_NI_SBOM = 'native-image-enable-sbom'
const SBOM_FILE_SUFFIX = '.sbom.json'
const MIN_JAVA_VERSION = '24.0.0'
const javaVersionKey = 'javaVersionKey'
let javaVersionOrLatestEA: string | null = null
interface SBOM {
components: Component[]
@@ -66,36 +67,36 @@ interface DependencySnapshot {
>
}
export function setUpSBOMSupport(javaVersion: string, distribution: string): void {
export function setUpSBOMSupport(javaVersionOrDev: string, distribution: string): void {
if (!isFeatureEnabled()) {
return
}
validateJavaVersionAndDistribution(javaVersion, distribution)
core.saveState(javaVersionKey, javaVersion)
setNativeImageOption(javaVersion, '--enable-sbom=export')
validateJavaVersionAndDistribution(javaVersionOrDev, distribution)
javaVersionOrLatestEA = javaVersionOrDev
setNativeImageOption(javaVersionOrLatestEA, '--enable-sbom=export')
core.info('Enabled SBOM generation for Native Image build')
}
function validateJavaVersionAndDistribution(javaVersion: string, distribution: string): void {
function validateJavaVersionAndDistribution(javaVersionOrDev: string, distribution: string): void {
if (distribution !== c.DISTRIBUTION_GRAALVM) {
throw new Error(
`The '${INPUT_NI_SBOM}' option is only supported for Oracle GraalVM (distribution '${c.DISTRIBUTION_GRAALVM}'), but found distribution '${distribution}'.`
)
}
if (javaVersion === 'dev') {
if (javaVersionOrDev === 'dev') {
throw new Error(`The '${INPUT_NI_SBOM}' option is not supported for java-version 'dev'.`)
}
if (javaVersion === 'latest-ea') {
if (javaVersionOrDev === 'latest-ea') {
return
}
const coercedJavaVersion = semver.coerce(javaVersion)
const coercedJavaVersion = semver.coerce(javaVersionOrDev)
if (!coercedJavaVersion || semver.gt(MIN_JAVA_VERSION, coercedJavaVersion)) {
throw new Error(
`The '${INPUT_NI_SBOM}' option is only supported for GraalVM for JDK ${MIN_JAVA_VERSION} or later, but found java-version '${javaVersion}'.`
`The '${INPUT_NI_SBOM}' option is only supported for GraalVM for JDK ${MIN_JAVA_VERSION} or later, but found java-version '${javaVersionOrDev}'.`
)
}
}
@@ -105,8 +106,7 @@ export async function processSBOM(): Promise<void> {
return
}
const javaVersion = core.getState(javaVersionKey)
if (!javaVersion) {
if (javaVersionOrLatestEA === null) {
throw new Error('setUpSBOMSupport must be called before processSBOM')
}
@@ -116,7 +116,7 @@ export async function processSBOM(): Promise<void> {
const sbomData = parseSBOM(sbomContent)
const components = mapToComponentsWithDependencies(sbomData)
printSBOMContent(components)
const snapshot = convertSBOMToSnapshot(javaVersion, sbomPath, components)
const snapshot = convertSBOMToSnapshot(sbomPath, components)
await submitDependencySnapshot(snapshot)
} catch (error) {
throw new Error(
@@ -184,7 +184,7 @@ function printSBOMContent(components: Component[]): void {
core.info('==================')
}
function convertSBOMToSnapshot(javaVersion: string, sbomPath: string, components: Component[]): DependencySnapshot {
function convertSBOMToSnapshot(sbomPath: string, components: Component[]): DependencySnapshot {
const context = github.context
const sbomFileName = basename(sbomPath)
@@ -203,7 +203,7 @@ function convertSBOMToSnapshot(javaVersion: string, sbomPath: string, components
},
detector: {
name: 'Oracle GraalVM',
version: javaVersion,
version: javaVersionOrLatestEA ?? '',
url: 'https://www.graalvm.org/'
},
scanned: new Date().toISOString(),

View File

@@ -1,4 +1,4 @@
import * as c from './constants'
import * as c from './constants.js'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as httpClient from '@actions/http-client'
@@ -8,8 +8,8 @@ import * as stream from 'stream'
import * as util from 'util'
import * as semver from 'semver'
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'
import { RetryHelper } from '@actions/tool-cache/lib/retry-helper'
import { calculateSHA256 } from './utils'
import { RetryHelper } from '@actions/tool-cache/lib/retry-helper.js'
import { calculateSHA256 } from './utils.js'
import { ok } from 'assert'
import { v4 as uuidv4 } from 'uuid'

View File

@@ -1,4 +1,4 @@
import * as c from './constants'
import * as c from './constants.js'
import * as core from '@actions/core'
import * as semver from 'semver'
import {
@@ -8,8 +8,8 @@ import {
getLatestRelease,
getMatchingTags,
getTaggedRelease
} from './utils'
import { downloadGraalVM, downloadGraalVMEELegacy } from './gds'
} from './utils.js'
import { downloadGraalVM, downloadGraalVMEELegacy } from './gds.js'
import { downloadTool } from '@actions/tool-cache'
import { basename } from 'path'

View File

@@ -1,8 +1,8 @@
import * as c from './constants'
import * as c from './constants.js'
import * as core from '@actions/core'
import * as semver from 'semver'
import { GRAALVM_PLATFORM } from './constants'
import { exec } from './utils'
import { GRAALVM_PLATFORM } from './constants.js'
import { exec } from './utils.js'
import { join } from 'path'
const BASE_FLAGS = ['--non-interactive', 'install', '--no-progress']

View File

@@ -1,6 +1,6 @@
import * as c from './constants'
import * as c from './constants.js'
import * as semver from 'semver'
import { downloadExtractAndCacheJDK, getTaggedRelease, getMatchingTags } from './utils'
import { downloadExtractAndCacheJDK, getTaggedRelease, getMatchingTags } from './utils.js'
import { downloadTool } from '@actions/tool-cache'
import { spawnSync } from 'child_process'

View File

@@ -1,20 +1,20 @@
import * as c from './constants'
import * as c from './constants.js'
import * as core from '@actions/core'
import * as graalvm from './graalvm'
import * as graalvm from './graalvm.js'
import * as semver from 'semver'
import { isFeatureAvailable as isCacheAvailable } from '@actions/cache'
import { basename, join } from 'path'
import { restore } from './features/cache'
import { setUpDependencies } from './dependencies'
import { setUpGUComponents } from './gu'
import { setUpMandrel } from './mandrel'
import { setUpLiberica } from './liberica'
import { checkForUpdates } from './features/check-for-updates'
import { setUpNativeImageMusl } from './features/musl'
import { setUpWindowsEnvironment } from './msvc'
import { setUpNativeImageBuildReports } from './features/reports'
import { restore } from './features/cache.js'
import { setUpDependencies } from './dependencies.js'
import { setUpGUComponents } from './gu.js'
import { setUpMandrel } from './mandrel.js'
import { setUpLiberica } from './liberica.js'
import { checkForUpdates } from './features/check-for-updates.js'
import { setUpNativeImageMusl } from './features/musl.js'
import { setUpWindowsEnvironment } from './msvc.js'
import { setUpNativeImageBuildReports } from './features/reports.js'
import { exec } from '@actions/exec'
import { setUpSBOMSupport } from './features/sbom'
import { setUpSBOMSupport } from './features/sbom.js'
async function run(): Promise<void> {
try {

View File

@@ -1,6 +1,6 @@
import * as c from './constants'
import * as c from './constants.js'
import * as httpClient from '@actions/http-client'
import { downloadExtractAndCacheJDK } from './utils'
import { downloadExtractAndCacheJDK } from './utils.js'
import { downloadTool } from '@actions/tool-cache'
import { basename } from 'path'

View File

@@ -1,7 +1,7 @@
import * as core from '@actions/core'
import { execSync } from 'child_process'
import { existsSync } from 'fs'
import { VERSION_DEV } from './constants'
import { VERSION_DEV } from './constants.js'
// Keep in sync with https://github.com/actions/virtual-environments
const KNOWN_VISUAL_STUDIO_INSTALLATIONS = [

View File

@@ -1,15 +1,25 @@
import * as c from './constants'
import * as c from './constants.js'
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as httpClient from '@actions/http-client'
import * as semver from 'semver'
import * as tc from '@actions/tool-cache'
import * as fs from 'fs'
import { ExecOptions, exec as e } from '@actions/exec'
import { readFileSync, readdirSync } from 'fs'
import { Octokit } from '@octokit/core'
import { createHash } from 'crypto'
import { join } from 'path'
import { tmpdir } from 'os'
import { GitHub } from '@actions/github/lib/utils'
// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = 'https://api.github.com'
const GitHubDotCom = Octokit.defaults({
baseUrl,
request: {
agent: new httpClient.HttpClient().getAgent(baseUrl)
}
})
export async function exec(commandLine: string, args?: string[], options?: ExecOptions | undefined): Promise<void> {
const exitCode = await e(commandLine, args, options)
@@ -19,7 +29,9 @@ export async function exec(commandLine: string, args?: string[], options?: ExecO
}
export async function getLatestRelease(repo: string): Promise<c.LatestReleaseResponse['data']> {
const octokit = getOctokit()
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? { auth: githubToken } : {}
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: c.GRAALVM_GH_USER,
@@ -29,7 +41,9 @@ export async function getLatestRelease(repo: string): Promise<c.LatestReleaseRes
}
export async function getContents(repo: string, path: string): Promise<c.ContentsResponse['data']> {
const octokit = getOctokit()
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? { auth: githubToken } : {}
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: c.GRAALVM_GH_USER,
@@ -44,7 +58,9 @@ export async function getTaggedRelease(
repo: string,
tag: string
): Promise<c.LatestReleaseResponse['data']> {
const octokit = getOctokit()
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? { auth: githubToken } : {}
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {
owner,
@@ -59,7 +75,9 @@ export async function getMatchingTags(
repo: string,
tagPrefix: string
): Promise<c.MatchingRefsResponse['data']> {
const octokit = getOctokit()
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? { auth: githubToken } : {}
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', {
owner,
@@ -138,15 +156,8 @@ export function isPREvent(): boolean {
return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST
}
function getOctokit(): InstanceType<typeof GitHub> {
/* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */
const GitHubWithPlugins = GitHub.plugin()
const token = core.getInput(c.INPUT_GITHUB_TOKEN)
if (token) {
return new GitHubWithPlugins({ auth: `token ${token}` })
} else {
return new GitHubWithPlugins() /* unauthenticated */
}
function getGitHubToken(): string {
return core.getInput(c.INPUT_GITHUB_TOKEN)
}
export async function findExistingPRCommentId(bodyStartsWith: string): Promise<number | undefined> {
@@ -155,7 +166,7 @@ export async function findExistingPRCommentId(bodyStartsWith: string): Promise<n
}
const context = github.context
const octokit = getOctokit()
const octokit = github.getOctokit(getGitHubToken())
try {
const comments = await octokit.paginate(octokit.rest.issues.listComments, {
...context.repo,
@@ -178,7 +189,7 @@ export async function updatePRComment(content: string, commentId: number): Promi
}
try {
await getOctokit().rest.issues.updateComment({
await github.getOctokit(getGitHubToken()).rest.issues.updateComment({
...github.context.repo,
comment_id: commentId,
body: content
@@ -196,7 +207,7 @@ export async function createPRComment(content: string): Promise<void> {
}
const context = github.context
try {
await getOctokit().rest.issues.createComment({
await github.getOctokit(getGitHubToken()).rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request?.number as number,
body: content

View File

@@ -15,7 +15,6 @@
"noUnusedParameters": false,
"pretty": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "ES2022"

View File

@@ -6,5 +6,12 @@
"noEmit": true
},
"exclude": ["dist", "node_modules"],
"include": ["__tests__", "src", "eslint.config.mjs", "jest.config.js"]
"include": [
"__tests__",
"src",
"eslint.config.mjs",
"jest.config.js",
"rollup.cleanup.config.ts",
"rollup.main.config.ts"
]
}

View File

@@ -2,7 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"isolatedModules": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist"