Skip to content

Commit

Permalink
Merge pull request #2 from MarathonLabs/feature/upgrade-deps
Browse files Browse the repository at this point in the history
feat(action): support v1
  • Loading branch information
Malinskiy authored Feb 7, 2024
2 parents bfcada4 + 1f1a5eb commit 4b762f9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 49 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Setup marathon-cloud
description: Setup marathon-cloud in GitHub Actions
inputs:
version:
description: "The version of marathon-cloud to use. Defaults to the latest version."
required: false
description: "The version of marathon-cloud to use"
required: true
skip-cache:
description: 'Skip cache check? When set to "true", the action will always download the latest version.'
required: false
Expand Down
11 changes: 0 additions & 11 deletions src/gh.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/gh.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import * as core from '@actions/core';
const REPO_OWNER = 'MarathonLabs';
const REPO = 'marathon-cloud-cli';

export function isLatestVersion(version: string): boolean {
const v = version.toLowerCase();
return v === 'latest' || v === '*' || v === '';
}

export async function resolveLatestVersion(): Promise<string> {
core.warning(
`setup-marathon-cloud@v1 supports marathon-cloud cli up to 0.3.X. To use marathon-cloud cli v1+ use setup-marathon-cloud@v2`,
);
return '0.3.11';
}

export function releaseArtifactURL(paths: string[]): string {
return `https://github.com/${REPO_OWNER}/${REPO}/releases/download/${paths.join(
'/',
Expand Down
40 changes: 21 additions & 19 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@ import * as tc from '@actions/tool-cache';
import * as fs from 'fs';
import { platform } from 'os';
import path from 'path';
import {
isLatestVersion,
releaseArtifactURL,
resolveLatestVersion,
} from './gh';
import { releaseArtifactURL } from './gh';
import { sha256File } from './hash';

const TOOL_NAME = 'marathon-cloud';

export type Platform =
| 'darwin_all'
| 'linux_amd64'
| 'linux_arm64'
| 'windows_amd64';
| 'universal-apple-darwin'
| 'x86_64-unknown-linux-gnu'
| 'x86_64-unknown-linux-musl'
| 'aarch64-unknown-linux-gnu'
| 'aarch64-unknown-linux-musl'
| 'arm-unknown-linux-gnueabihf'
| 'arm-unknown-linux-musleabihf'
| 'i686-unknown-linux-gnu'
| 'i686-unknown-linux-musl'
| 'x86_64-pc-windows-gnu'
| 'x86_64-pc-windows-msvc'
| 'i686-pc-windows-msvc';

function resolvePlatform(): Platform {
const platform = process.platform;
const arch = process.arch;
if (platform === 'darwin') {
return 'darwin_all';
return 'universal-apple-darwin';
} else if (platform === 'linux' && arch === 'x64') {
return 'linux_amd64';
return 'x86_64-unknown-linux-gnu';
} else if (platform === 'linux' && arch === 'arm64') {
return 'linux_arm64';
return 'aarch64-unknown-linux-gnu';
} else if (platform === 'win32' && arch === 'x64') {
return 'windows_amd64';
return 'x86_64-pc-windows-msvc';
} else {
throw new Error(`Unsupported platform: ${platform}_${arch}`);
}
Expand All @@ -53,14 +57,10 @@ export async function getReleaseArtifact(
version: string,
platform?: Platform,
): Promise<BinaryArtifact> {
if (isLatestVersion(version)) {
version = await resolveLatestVersion();
}

platform = platform || resolvePlatform();
const extension = resolveExtension(platform);

const artifactName = `${TOOL_NAME}_${platform}-${version}.${extension}`;
const artifactName = `${TOOL_NAME}_v${version}-${platform}.${extension}`;

return {
version,
Expand Down Expand Up @@ -171,7 +171,9 @@ export async function setupArtifact(

function resolveExtension(platform: Platform): string {
switch (platform) {
case 'windows_amd64':
case 'x86_64-pc-windows-gnu':
case 'x86_64-pc-windows-msvc':
case 'i686-pc-windows-msvc':
return 'zip';
default:
return 'tar.gz';
Expand Down
14 changes: 10 additions & 4 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import { getReleaseArtifact, setupArtifact } from './release';
import { validateMajorVersion } from './semver';

const inputNameVersion = 'version';
const inputNameSkipCache = 'skip-cache';
Expand All @@ -8,11 +9,16 @@ async function main() {
const version = core.getInput(inputNameVersion);
const skipCache = core.getInput(inputNameSkipCache) === 'true';
core.debug(`version: ${version} skip-cache: ${skipCache}`);
if (validateMajorVersion(version, '1')) {
const artifact = await getReleaseArtifact(version);
core.debug(`Resolved artifact: ${JSON.stringify(artifact)}`);

const artifact = await getReleaseArtifact(version);
core.debug(`Resolved artifact: ${JSON.stringify(artifact)}`);

await setupArtifact(artifact, skipCache);
await setupArtifact(artifact, skipCache);
} else {
core.setFailed(
`Unsupported cli version ${version}. This action supports version ${1}`,
);
}
}

try {
Expand Down
11 changes: 11 additions & 0 deletions src/semver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { validateMajorVersion } from './semver';

test('versionValidation', () => {
['1', '1.0.0', '1.2.3'].forEach((v) => {
expect(validateMajorVersion(v, '1')).toBe(true);
});

['0', '0.1.0', '0.3.3'].forEach((v) => {
expect(validateMajorVersion(v, '1')).toBe(false);
});
});
7 changes: 7 additions & 0 deletions src/semver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function validateMajorVersion(
versionString: string,
supported: string,
): boolean {
const majorVersion = versionString.split('.')[0];
return majorVersion === supported;
}

0 comments on commit 4b762f9

Please sign in to comment.