tests
This commit is contained in:
+4
-1
@@ -2,6 +2,9 @@
|
||||
* The entrypoint for the action.
|
||||
*/
|
||||
import { run } from './main'
|
||||
import minimist from 'minimist'
|
||||
|
||||
const path = minimist(process.argv.slice(2)).path || '.'
|
||||
console.log(path)
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
run()
|
||||
run(path)
|
||||
|
||||
+13
-9
@@ -4,17 +4,19 @@ import * as fsHelper from './fs-helper'
|
||||
import * as ociContainer from './oci-container'
|
||||
import * as ghcr from './ghcr-client'
|
||||
import semver from 'semver'
|
||||
import crypto from 'crypto'
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
export async function run(pathInput: string): Promise<void> {
|
||||
const tmpDirs: string[] = []
|
||||
|
||||
try {
|
||||
// Parse and validate Actions execution context, including the repository name, release name and event type
|
||||
const repository: string = process.env.GITHUB_REPOSITORY || ''
|
||||
|
||||
if (repository === '') {
|
||||
core.setFailed(`Could not find Repository.`)
|
||||
return
|
||||
@@ -25,7 +27,6 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
const releaseId: string = github.context.payload.release.id
|
||||
const releaseTag: string = github.context.payload.release.tag_name
|
||||
|
||||
// Strip any leading 'v' from the tag in case the release format is e.g. 'v1.0.0' as recommended by GitHub docs
|
||||
// https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions
|
||||
const targetVersion = semver.parse(releaseTag.replace(/^v/, ''))
|
||||
@@ -38,7 +39,6 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
const token: string = process.env.TOKEN!
|
||||
|
||||
// TODO: once https://github.com/github/github/pull/309384 goes in, we can switch to the actual endpoint
|
||||
//const response = await fetch(
|
||||
// process.env.GITHUB_API_URL + '/packages/container-registry-url'
|
||||
@@ -55,7 +55,8 @@ export async function run(): Promise<void> {
|
||||
|
||||
// Gather & validate user input
|
||||
// Paths to be included in the OCI image
|
||||
const paths: string[] = core.getInput('path').split(' ')
|
||||
// const paths: string[] = core.getInput('path').split(' ')
|
||||
const paths: string[] = pathInput.split(' ')
|
||||
let path = ''
|
||||
|
||||
if (paths.length === 1 && fsHelper.isDirectory(paths[0])) {
|
||||
@@ -82,6 +83,12 @@ export async function run(): Promise<void> {
|
||||
new Date()
|
||||
)
|
||||
|
||||
// Generate SHA-256 hash of the manifest
|
||||
const manifestSHA = crypto.createHash('sha256')
|
||||
const manifestHash = manifestSHA
|
||||
.update(JSON.stringify(manifest))
|
||||
.digest('hex')
|
||||
|
||||
const packageURL = await ghcr.publishOCIArtifact(
|
||||
token,
|
||||
registryURL,
|
||||
@@ -95,14 +102,11 @@ export async function run(): Promise<void> {
|
||||
)
|
||||
|
||||
core.setOutput('package-url', packageURL.toString())
|
||||
|
||||
// TODO: We might need to do some attestation stuff here, but unsure how to integrate it yet.
|
||||
// We might need to return the manifest JSON from the Action and link it to another action,
|
||||
// or we might be able to make an API call here. It's unclear at this point.
|
||||
core.setOutput('package-manifest', JSON.stringify(manifest))
|
||||
core.setOutput('package-manifest-sha', `sha256:${manifestHash}`)
|
||||
} catch (error) {
|
||||
// Fail the workflow run if an error occurs
|
||||
if (error instanceof Error) core.setFailed(error.message)
|
||||
// if (error instanceof Error) core.setFailed(error.message)
|
||||
} finally {
|
||||
// Clean up any temporary directories that exist
|
||||
for (const tmpDir of tmpDirs) {
|
||||
|
||||
Reference in New Issue
Block a user