Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion frieza-clean/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ inputs:
description: 'Region'
required: true
frieza_version:
description: 'Access Key'
description: 'Frieza version to use. Default is latest.'
required: false
default: 'latest'
github_token:
description: 'GitHub token used to query release binaries.'
required: false
default: ${{ github.token }}
clean_timeout:
description: 'Timeout when cleaning all the resources in order not to get stuck'
required: false
Expand Down
3 changes: 2 additions & 1 deletion frieza-clean/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const setup = require('./lib/frieza');
const secret_key = core.getInput('secret_key');
const region = core.getInput('region')
const release = core.getInput('frieza_version');
const githubToken = core.getInput('github_token');

const providersInput = core.getInput('providers');
const providers = providersInput.split(',').map(p => p.trim()).filter(p => p !== '');
Expand All @@ -16,7 +17,7 @@ const setup = require('./lib/frieza');
const exclude_resource_types = core.getInput('exclude_resource_types');

// Binary
const pathToCLI = await setup.downloadBinary(release)
const pathToCLI = await setup.downloadBinary(release, githubToken)
core.debug(`Add ${pathToCLI} to PATH`)
core.addPath(pathToCLI);

Expand Down
58 changes: 34 additions & 24 deletions frieza-clean/lib/frieza.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const exec = require('@actions/exec');

const fetch = require('node-fetch')
const os = require('os');
const path = require('path');

const default_profile_name = 'action'
const default_snapshot_name = 'snapshot-action'

async function getRelease(release) {
let url = ''
async function getRelease(release, githubToken) {
const { getOctokit } = await import('@actions/github');
const octokit = getOctokit(githubToken);
let response;
let params = {
owner: 'outscale',
repo: 'frieza',
}

if (release == '' || release == 'latest') {
url = "https://api.github.com/repos/outscale/frieza/releases/latest"
response = await octokit.rest.repos.getLatestRelease(params);
} else {
url = `https://api.github.com/repos/outscale/frieza/releases/${release}`
params.release_id = release;
response = await octokit.rest.repos.getRelease(params);
}

const response = await fetch(url);
const body = await response.text();

core.debug(`Fetch release response: ${response.status} ${response.statusText}`);
core.debug(`Fetch release: ${body}`);
if (!response.ok) {
throw new Error(`could not fetch release: ${response.status} ${response.statusText}`);
}
core.debug(`Fetch release response: ${response.data} ${response.status}`);

return JSON.parse(body);
return response.data;
}

function getAssetURL(data, asset_name) {
Expand All @@ -53,8 +53,8 @@ async function copyBinary(pathToCLI, release_tag) {
}
}

async function downloadBinary(release) {
let release_data = await getRelease(release)
async function downloadBinary(release, githubToken) {
let release_data = await getRelease(release, githubToken)

let release_tag = release_data["tag_name"]
if (!release_tag) {
Expand All @@ -64,32 +64,42 @@ async function downloadBinary(release) {
release_tag = release_tag.substring(1)
}

const asset_name = "frieza_" + release_tag + "_" + mapOS(os.platform()) + "_" + mapArch(os.arch())
const arch = mapArch(os.arch())
let cachedPath = tc.find('frieza', release_tag, arch)
if (cachedPath) {
core.debug(`Using cached Frieza from ${cachedPath}`)
return cachedPath;
}

const asset_name = "frieza_" + release_tag + "_" + mapOS(os.platform()) + "_" + arch
const url = getAssetURL(release_data["assets"], asset_name)

core.debug(`Downloading Frieza from ${url}`);
const downloadedPath = await tc.downloadTool(url)

let pathToCLI = "";
let friezaFolder = "";
if (url.endsWith(".zip")) {
core.debug('Extracting Frieza zip file');
pathToCLI = await tc.extractZip(downloadedPath);
friezaFolder = await tc.extractZip(downloadedPath);
} else if (url.endsWith(".tar.gz")) {
core.debug('Extracting Frieza tar file');
pathToCLI = await tc.extractTar(downloadedPath);
friezaFolder = await tc.extractTar(downloadedPath);
} else {
throw new Error(`Unknown archive format`);
}

core.debug(`Frieza path is ${pathToCLI}.`);
core.debug(`Frieza path is ${friezaFolder}.`);

if (!downloadedPath || !pathToCLI) {
if (!downloadedPath || !friezaFolder) {
throw new Error(`Unable to download Frieza from ${url}`);
}

await copyBinary(pathToCLI, `v${release_tag}`)
await copyBinary(friezaFolder, `v${release_tag}`)

cachedPath = await tc.cacheDir(friezaFolder, 'frieza', release_tag, arch)
core.addPath(cachedPath)

return pathToCLI;
return cachedPath;
}

function mapArch(arch) {
Expand Down
216 changes: 186 additions & 30 deletions frieza-clean/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading