Skip to content

Commit

Permalink
Merge pull request #5 from unionai-oss/fetch-flytectl-from-monorepo
Browse files Browse the repository at this point in the history
Fetch flytectl from monorepo
  • Loading branch information
eapolinario committed May 16, 2024
2 parents a102f51 + 98cce02 commit ef793a9
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 25 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Continuous Integration

on:
pull_request:
push:
branches:
- master

jobs:
test-install-flytectl:
name: Install latest version of flytectl
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install latest version
id: test-latest-version
uses: ./
- run: |
flytectl version
flytectl demo start
test-install-pinned-flytectl:
name: Install pinned version of flytectl
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install pinned version
id: test-pinned-version
uses: ./
with:
version: 'v0.8.20'
- run: |
flytectl version
flytectl demo start
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ inputs:
required: false
default: 'latest'
runs:
using: 'node16'
using: 'node20'
main: './dist/main.js'
81 changes: 71 additions & 10 deletions dist/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/main.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flytectl-setup-action",
"version": "0.0.2",
"version": "0.0.3",
"description": "Install and setup flytectl for use in other actions ",
"main": "src/main.js",
"scripts": {
Expand Down Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"esbuild": "^0.12.6",
"typescript": "^4.3.2",
"eslint": "^7.28.0"
"eslint": "^7.32.0",
"typescript": "^4.3.2"
}
}
21 changes: 14 additions & 7 deletions src/flytectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Error, isError } from './error';
// optionally be specified in the action's version parameter.
const versionPrefix = "v";

export async function getFlytectl(version: string): Promise<string|Error> {
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}`);
Expand All @@ -20,7 +20,7 @@ export async function getFlytectl(version: string): Promise<string|Error> {
core.info(`Resolving the download URL for the current platform...`);
const downloadURL = await getDownloadURL(version);
if (isError(downloadURL)) {
return downloadURL
return downloadURL
}

core.info(`Downloading flytectl version "${version}" from ${downloadURL}`);
Expand All @@ -45,7 +45,7 @@ export async function getFlytectl(version: string): Promise<string|Error> {

// getDownloadURL resolves flytectl's Github download URL for the
// current architecture and platform.
async function getDownloadURL(version: string): Promise<string|Error> {
async function getDownloadURL(version: string): Promise<string | Error> {
let architecture = '';
switch (os.arch()) {
case 'x64':
Expand All @@ -69,23 +69,25 @@ async function getDownloadURL(version: string): Promise<string|Error> {

const assetName = `flytectl_${platform}_${architecture}.tar.gz`
const octokit = new Octokit();
const {data: releases} = await octokit.request(
const { data: releases } = await octokit.request(
'GET /repos/{owner}/{repo}/releases',
{
owner: 'flyteorg',
repo: 'flytectl',
repo: 'flyte',
}
);
// Filter out releases for which the tags do not have the prefix `flytectl/`
const filteredReleases = releases.filter((release) => release.tag_name.startsWith('flytectl/'));
switch (version) {
case 'latest':
for (const asset of releases[0].assets) {
for (const asset of filteredReleases[0].assets) {
if (assetName === asset.name) {
return asset.browser_download_url;
}
}
break;
default:
for (const release of releases) {
for (const release of filteredReleases) {
if (releaseTagIsVersion(release.tag_name, version)) {
for (const asset of release.assets) {
if (assetName === asset.name) {
Expand All @@ -101,6 +103,11 @@ async function getDownloadURL(version: string): Promise<string|Error> {
}

function releaseTagIsVersion(releaseTag: string, version: string): boolean {
// Remove the prefix `flytectl/` from releaseTag if it exists
if (releaseTag.indexOf('flytectl/') === 0) {
releaseTag = releaseTag.slice('flytectl/'.length)
}

if (releaseTag.indexOf(versionPrefix) === 0) {
releaseTag = releaseTag.slice(versionPrefix.length)
}
Expand Down

0 comments on commit ef793a9

Please sign in to comment.