-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yuvraj <code@evalsocket.dev>
- Loading branch information
0 parents
commit dc9b328
Showing
12 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
module.exports = { | ||
env: { | ||
es2021: true | ||
}, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "tsconfig.json", | ||
tsconfigRootDir: __dirname, | ||
ecmaFeatures: { | ||
jsx: true | ||
}, | ||
ecmaVersion: 12, | ||
sourceType: "module", | ||
}, | ||
plugins: [ | ||
"@typescript-eslint", | ||
], | ||
ignorePatterns: [ | ||
".eslintrc.js", | ||
], | ||
rules: { | ||
"@typescript-eslint/strict-boolean-expressions": "error", | ||
"@typescript-eslint/no-unnecessary-condition": "error", | ||
"@typescript-eslint/array-type": "error", | ||
"@typescript-eslint/switch-exhaustiveness-check": "error", | ||
"@typescript-eslint/prefer-nullish-coalescing": "error", | ||
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", | ||
"@typescript-eslint/no-invalid-void-type": "error", | ||
"@typescript-eslint/no-base-to-string": "error" | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY: build | ||
build: | ||
@tsc | ||
@eslint ./src | ||
@esbuild \ | ||
--minify \ | ||
--bundle \ | ||
--sourcemap \ | ||
'--define:process.env.NODE_ENV="production"' \ | ||
--outdir=dist \ | ||
--platform=node \ | ||
--target=node12 \ | ||
./src/main.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: 'flytectl-setup-action' | ||
description: > | ||
Install and setup flytectl for use in other actions | ||
inputs: | ||
version: | ||
description: 'The version of flytectl to setup.' | ||
required: false | ||
default: 'latest' | ||
runs: | ||
using: 'node12' | ||
main: './dist/main.js' |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "flytectl-setup-action", | ||
"version": "0.0.1", | ||
"description": "Install and setup flytectl for use in other actions ", | ||
"main": "src/main.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/evalsocket/flytectl-setup-action.git" | ||
}, | ||
"author": "Yuvraj", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/evalsocket/flytectl-setup-action/issues" | ||
}, | ||
"homepage": "https://github.com/evalsocket/flytectl-setup-action#readme", | ||
"dependencies": { | ||
"@actions/core": "^1.2.6", | ||
"@actions/github": "^4.0.0", | ||
"@actions/io": "^1.0.2", | ||
"@actions/tool-cache": "^1.6.1", | ||
"@octokit/core": "", | ||
"@types/node": "^14.14.35", | ||
"child_process": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"esbuild": "^0.12.6", | ||
"typescript": "^4.3.2", | ||
"eslint": "^7.28.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Error { | ||
message: string; | ||
} | ||
|
||
export function isError(value: any): value is Error { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
return (value as Error).message !== undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
|
||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import * as core from '@actions/core'; | ||
import * as tc from '@actions/tool-cache'; | ||
import { Octokit } from "@octokit/core"; | ||
import { Error, isError } from './error'; | ||
|
||
// versionPrefix is used in Github release names, and can | ||
// optionally be specified in the action's version parameter. | ||
const versionPrefix = "v"; | ||
|
||
export async function getFlytectl(version: string): Promise<string|Error> { | ||
const binaryPath = tc.find('flytectl', version, os.arch()); | ||
if (binaryPath !== '') { | ||
core.info(`Found in cache @ ${binaryPath}`); | ||
return binaryPath; | ||
} | ||
|
||
core.info(`Resolving the download URL for the current platform...`); | ||
const downloadURL = await getDownloadURL(version); | ||
if (isError(downloadURL)) { | ||
return downloadURL | ||
} | ||
|
||
core.info(`Downloading flytectl version "${version}" from ${downloadURL}`); | ||
const downloadPath = await tc.downloadTool(downloadURL); | ||
core.info(`Successfully downloaded flytectl version "${version}" from ${downloadURL}`); | ||
|
||
core.info('Extracting flytectl...'); | ||
const extractPath = await tc.extractTar(downloadPath); | ||
core.info(`Successfully extracted flytectl to ${extractPath}`); | ||
|
||
core.info('Adding flytectl to the cache...'); | ||
const cacheDir = await tc.cacheDir( | ||
path.join(extractPath), | ||
'flytectl', | ||
version, | ||
os.arch() | ||
); | ||
core.info(`Successfully cached flytectl to ${cacheDir}`); | ||
|
||
return cacheDir; | ||
} | ||
|
||
// getDownloadURL resolves flytectl's Github download URL for the | ||
// current architecture and platform. | ||
async function getDownloadURL(version: string): Promise<string|Error> { | ||
let architecture = ''; | ||
switch (os.arch()) { | ||
case 'x64': | ||
architecture = 'x86_64'; | ||
break; | ||
default: | ||
return { | ||
message: `The "${os.arch()}" architecture is not supported with a flytectl release.` | ||
}; | ||
} | ||
let platform = ''; | ||
switch (os.platform()) { | ||
case 'linux': | ||
platform = 'Linux'; | ||
break; | ||
default: | ||
return { | ||
message: `The "${os.platform()}" platform is not supported with a flytectl release.` | ||
}; | ||
} | ||
|
||
const assetName = `flytectl_${platform}_${architecture}.tar.gz` | ||
const octokit = new Octokit(); | ||
const {data: releases} = await octokit.request( | ||
'GET /repos/{owner}/{repo}/releases', | ||
{ | ||
owner: 'flyteorg', | ||
repo: 'flytectl', | ||
} | ||
); | ||
switch (version) { | ||
case 'latest': | ||
for (const asset of releases[0].assets) { | ||
if (assetName === asset.name) { | ||
return asset.browser_download_url; | ||
} | ||
} | ||
break; | ||
default: | ||
for (const release of releases) { | ||
if (releaseTagIsVersion(release.tag_name, version)) { | ||
for (const asset of release.assets) { | ||
if (assetName === asset.name) { | ||
return asset.browser_download_url; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
message: `Unable to find flytectl version "${version}" for platform "${platform}" and architecture "${architecture}".` | ||
}; | ||
} | ||
|
||
function releaseTagIsVersion(releaseTag: string, version: string): boolean { | ||
if (releaseTag.indexOf(versionPrefix) === 0) { | ||
releaseTag = releaseTag.slice(versionPrefix.length) | ||
} | ||
if (version.indexOf(versionPrefix) === 0) { | ||
version = version.slice(versionPrefix.length) | ||
} | ||
return releaseTag === version | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {run} from './run'; | ||
|
||
void run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import cp from 'child_process'; | ||
import * as path from 'path'; | ||
import * as core from '@actions/core'; | ||
import * as io from '@actions/io'; | ||
import { getFlytectl } from './flytectl'; | ||
import { Error, isError } from './error'; | ||
|
||
export async function run(): Promise<void> { | ||
try { | ||
const result = await runSetup() | ||
if (result !== null && isError(result)) { | ||
core.setFailed(result.message); | ||
} | ||
} catch (error) { | ||
// In case we ever fail to catch an error | ||
// in the call chain, we catch the error | ||
// and mark the build as a failure. The | ||
// user is otherwise prone to false positives. | ||
if (isError(error)) { | ||
core.setFailed(error.message); | ||
return; | ||
} | ||
core.setFailed('Internal error'); | ||
} | ||
} | ||
|
||
// runSetup runs the flytectl-setup action, and returns | ||
// a non-empty error if it fails. | ||
async function runSetup(): Promise<null|Error> { | ||
const version = core.getInput('version'); | ||
if (version === '') { | ||
return { | ||
message: 'a version was not provided' | ||
}; | ||
} | ||
|
||
core.info(`Setting up flytectl version "${version}"`); | ||
const installDir = await getFlytectl(version); | ||
if (isError(installDir)) { | ||
return installDir | ||
} | ||
|
||
core.info('Adding flytectl binary to PATH'); | ||
core.addPath(path.join(installDir)); | ||
const binaryPath = await io.which('flytectl', true); | ||
if (binaryPath === '') { | ||
return { | ||
message: 'flytectl was not found on PATH' | ||
}; | ||
} | ||
|
||
core.info(`Successfully setup flytectl version ${version}`); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"lib": ["ES6"], | ||
"jsx": "preserve", | ||
"noImplicitAny": true, | ||
"esModuleInterop": true, | ||
"target": "es6", | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedParameters": true | ||
} | ||
} |