diff --git a/action.yml b/action.yml index 9165bde..fa39634 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,15 @@ inputs: token: required: true description: 'GitHub token from secrets.GITHUB_TOKEN' + allow-external-github-orgs: + required: false + description: 'Allow installing from external GitHub organizations' + artifactory-url: + required: false + description: 'Artifactory URL to use for downloading Foreman tools' + artifactory-token: + required: false + description: 'Artifactory token to use for downloading Foreman tools' runs: using: 'node16' main: 'dist/index.js' diff --git a/src/configFile.ts b/src/configFile.ts index 3da8c6f..437ce5b 100644 --- a/src/configFile.ts +++ b/src/configFile.ts @@ -1,5 +1,5 @@ -import {parse} from "toml"; -import {readFile} from "fs"; +import { parse } from "toml"; +import { readFile } from "fs"; import findUp from "find-up"; interface foremanConfig { tools: { diff --git a/src/foreman.ts b/src/foreman.ts index b1604d5..ec8c267 100644 --- a/src/foreman.ts +++ b/src/foreman.ts @@ -84,6 +84,10 @@ async function authenticate(token: string): Promise { await exec("foreman", ["github-auth", token]); } +async function addArtifactoryToken(url: string, token: string): Promise { + await exec("foreman", ["artifactory-auth", url, token]); +} + function addBinDirToPath(): void { if (process.platform === "win32") { addPath(`${process.env.USERPROFILE}\\.foreman\\bin`); @@ -105,7 +109,8 @@ export default { authenticate, addBinDirToPath, installTools, - filterValidReleases + filterValidReleases, + addArtifactoryToken }; export type { GitHubRelease }; diff --git a/src/main.ts b/src/main.ts index a1d0461..4a4aa1f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,13 @@ import { downloadTool, extractZip } from "@actions/tool-cache"; import { GitHub } from "@actions/github"; import { resolve } from "path"; import { exec } from "@actions/exec"; + +import semver from "semver"; import configFile from "./configFile"; import foreman from "./foreman"; +const MIN_ARTIFACTORY_FOREMAN_VERSION = "v1.6.0"; + async function run(): Promise { try { const versionReq: string = getInput("version"); @@ -15,6 +19,8 @@ async function run(): Promise { const allowExternalGithubOrgs: string = getInput( "allow-external-github-orgs" ).toLowerCase(); + const artifactoryUrl = getInput("artifactory-url"); + const artifactoryToken = getInput("artifactory-token"); const octokit = new GitHub(githubToken, { baseUrl: githubApiUrl @@ -50,6 +56,21 @@ async function run(): Promise { } await foreman.authenticate(githubToken); + + if (artifactoryUrl != "" && artifactoryToken != "") { // both defined + if (semver.compare(release.tag_name, MIN_ARTIFACTORY_FOREMAN_VERSION) == -1) { + throw new Error( + `Artifactory support requires Foreman version ${MIN_ARTIFACTORY_FOREMAN_VERSION} or later` + ); + } + + await foreman.addArtifactoryToken(artifactoryUrl, artifactoryToken); + } else if (artifactoryUrl != "" || artifactoryToken != "") { // only one defined + throw new Error( + "Both artifactory-url and artifactory-token must be set or null" + ); + } + foreman.addBinDirToPath(); if (workingDir !== undefined && workingDir !== null && workingDir !== "") {