Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryl1 authored Jun 29, 2022
1 parent fcd9a6a commit 586b2f6
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
async function updateDep(FILE_NAME, tag_name,owner) {

const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const https = require('https');
const url = require('url');
const { PutObjectCommand, S3Client, ListObjectsCommand } = require('@aws-sdk/client-s3')
const { Octokit, App } = require("octokit");

var bucketName = core.getInput("bucketName")
let client = new S3Client();
let octokit = new Octokit({ auth: core.getInput("token") });
var repo_list_string = core.getInput("repo")
var repo_list = repo_list_string.split(",");


async function updateDep(FILE_NAME, tag_name, owner) {
console.log(FILE_NAME)
var TAR_URL = 'https://api.github.com/repos/' +owner+ '/' + repo + '/tarball/' + tag_name;
var TAR_URL = 'https://api.github.com/repos/' + owner + '/' + repo + '/tarball/' + tag_name;

var path = "Dependencies/" + repo + "/" + FILE_NAME

Expand Down Expand Up @@ -38,15 +54,15 @@ async function list(path) {
Bucket: bucketName,
Prefix: path + "/",
};

const data = await client.send(new ListObjectsCommand(params));
if (data.length < 0) {
return data
}
var files = data.Contents?.filter((file) => { return file.Key.indexOf('.gz') > 0 }).sort((file1, file2) => -1 * file1.Key.localeCompare(file2.Key))
return files
}
async function getLatest(repo,owner) {
async function getLatest(repo, owner) {
var latest = await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: owner,
repo: repo
Expand Down Expand Up @@ -75,18 +91,18 @@ function compareVersions(v1, v2) {
}
}

function getConfig(repo){
function getConfig(repo) {
var depPath = core.getInput("depPath")
var fs = require('fs');
var config = JSON.parse(fs.readFileSync(depPath, 'utf8'));
return config[repo];

}
function parseConfig(cfg){
function parseConfig(cfg) {
var path = cfg["path"]
var url = cfg["github_url"]
var org = url.split("/")[0]
return [path,org]
return [path, org]
}

async function syncDependencies(repo) {
Expand All @@ -95,12 +111,12 @@ async function syncDependencies(repo) {
var owner = path_and_org[1]
var path = path_and_org[0]

var s3_dep_list = await list(repo,path)
var gh_latest_release = await getLatest(repo,owner)
var s3_dep_list = await list(repo, path)
var gh_latest_release = await getLatest(repo, owner)

var g_tag = gh_latest_release.data.tag_name.replace("v", "")
if (!s3_dep_list) {
updateDep(repo + "-" + g_tag + ".tar.gz", g_tag,owner)
updateDep(repo + "-" + g_tag + ".tar.gz", g_tag, owner)
return
}

Expand All @@ -111,7 +127,7 @@ async function syncDependencies(repo) {


if (compareVersions(g_tag, s3_latest_tag)) {
updateDep(repo + "-" + g_tag + ".tar.gz", g_tag,owner)
updateDep(repo + "-" + g_tag + ".tar.gz", g_tag, owner)
}

}
Expand Down

0 comments on commit 586b2f6

Please sign in to comment.