Skip to content

Commit

Permalink
Add support for artifactory auth (#48)
Browse files Browse the repository at this point in the history
* add artifactory-url and artifactory-token params for artifactory auth

* restructure

* add dist for testing

* update dist for testing

* remove dist for testing

* update dist for testing

* update dist for testing

* update minimum version allowed

* remove dist before merging
  • Loading branch information
afujiwara-roblox authored Mar 29, 2024
1 parent 80fab84 commit 7e947e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
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'
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]);
}

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

0 comments on commit 7e947e4

Please sign in to comment.