Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for artifactory auth #48

Merged
merged 10 commits into from
Mar 29, 2024
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why was this missing? Does this action.yml file actually get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think action.yml is used to give information about how the action is used, so it would warn that an unknown argument was used when allow-external-github-org was set. AFAIK, it doesn't affect any functionality

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'
4 changes: 2 additions & 2 deletions src/configFile.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
7 changes: 6 additions & 1 deletion src/foreman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ async function authenticate(token: string): Promise<void> {
await exec("foreman", ["github-auth", token]);
}

async function addArtifactoryToken(url: string, token: string): Promise<void> {
await exec("foreman", ["artifactory-auth", url, token]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do we need to check the version before we can do this? Or can we just count on the error carrying through and hope that folks can figure it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, we should probably warn if the version selected is below the supported version

}

function addBinDirToPath(): void {
if (process.platform === "win32") {
addPath(`${process.env.USERPROFILE}\\.foreman\\bin`);
Expand All @@ -105,7 +109,8 @@ export default {
authenticate,
addBinDirToPath,
installTools,
filterValidReleases
filterValidReleases,
addArtifactoryToken
};

export type { GitHubRelease };
21 changes: 21 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
const versionReq: string = getInput("version");
Expand All @@ -15,6 +19,8 @@ async function run(): Promise<void> {
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
Expand Down Expand Up @@ -50,6 +56,21 @@ async function run(): Promise<void> {
}

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 !== "") {
Expand Down
Loading