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 @@ -11,6 +11,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'
15 changes: 10 additions & 5 deletions src/foreman.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addPath } from "@actions/core";
import { exec } from "@actions/exec";
import { GitHub } from "@actions/github";
import {addPath} from "@actions/core";
import {exec} from "@actions/exec";
import {GitHub} from "@actions/github";
import semver from "semver";
import os from "os";

Expand Down 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 };
export type {GitHubRelease};
23 changes: 17 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getInput, debug, addPath, setFailed } from "@actions/core";
import { downloadTool, extractZip } from "@actions/tool-cache";
import { GitHub } from "@actions/github";
import { resolve } from "path";
import { exec } from "@actions/exec";
import {getInput, debug, addPath, setFailed} from "@actions/core";
import {downloadTool, extractZip} from "@actions/tool-cache";
import {GitHub} from "@actions/github";
import {resolve} from "path";
import {exec} from "@actions/exec";
import configFile from "./configFile";
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but any idea why this formatting is changing? I thought the convention was to have the spaces.

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, my local set up might have a different formatter set up. Ill revert this

import foreman from "./foreman";

Expand All @@ -14,10 +14,12 @@ 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);
const releases = await foreman.getReleases(octokit);
const validReleases = foreman.filterValidReleases(releases)
const validReleases = foreman.filterValidReleases(releases);
debug("Choosing release from GitHub API");

const release = foreman.chooseRelease(versionReq, validReleases);
Expand Down Expand Up @@ -47,6 +49,15 @@ async function run(): Promise<void> {
}

await foreman.authenticate(githubToken);

if (artifactoryUrl != "" && artifactoryToken != "") { // both defined
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