-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
144 lines (115 loc) · 3.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const core = require('@actions/core');
const { context, GitHub } = require('@actions/github');
const fs = require('fs').promises;
const path = require('path');
const axios = require('axios');
import { Octokit, App } from "octokit";
const packagesEnginesPath = 'engines';
console.log('Starting.');
async function checkEngine(engineName, issuesFound) {
const engineFolderPath = path.join(packagesEnginesPath, engineName);
const envJsonPath = path.join(engineFolderPath, 'env.json');
try {
await fs.access(envJsonPath);
} catch {
return;
}
const envJsonStr = await fs.readFile(envJsonPath, 'utf-8');
const envData = JSON.parse(envJsonStr);
if(!envData.COMMIT_TAG) {
return;
}
if(envData.COMMIT_TAG_FREEZE) {
return;
}
const {gitOrg, gitRepo} = await getGithubOrgRepo(engineFolderPath);
const octokit = new Octokit({
auth: core.getInput('token')
});
try {
const latestRelease = await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: gitOrg,
repo: gitRepo,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});
if(latestRelease?.data?.tag_name && latestRelease.data?.tag_name !== envData.COMMIT_TAG) {
issuesFound.push({
engineName: engineName,
newTag: latestRelease.data.tag_name,
oldTag: envData.COMMIT_TAG
});
}
} catch {
try {
const allTags = await octokit.request('GET /repos/{owner}/{repo}/tags', {
owner: gitOrg,
repo: gitRepo,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});
const latestTag = allTags.data[0].name;
if(latestTag !== envData.COMMIT_TAG) {
issuesFound.push({
engineName: engineName,
newTag: latestTag,
oldTag: envData.COMMIT_TAG
});
}
}
catch {}
}
}
async function getGithubOrgRepo(enginePath) {
const buildFilePath = path.join(enginePath, 'build.sh');
const buildFileStr = await fs.readFile(buildFilePath, 'utf-8');
const buildFileArr = buildFileStr.split('\n');
let sourcePushdFound = false;
let gitCloneLine = '';
for(let i = 0; i < buildFileArr.length; i++) {
const line = buildFileArr[i];
if(sourcePushdFound && !line.includes('git checkout')) {
break;
}
if(sourcePushdFound) {
let commitHash = '';
const gitCloneUrl = gitCloneLine.split('git clone ')[1].split(' ')[0];
if(gitCloneUrl.includes('github.com')) {
const gitArr = gitCloneUrl.split('https://github.com/')[1].split('/');
const gitOrg = gitArr[0];
const gitRepo = gitArr[1].replace('.git', '');
return {gitRepo, gitOrg};
}
}
if(line === 'pushd source') {
gitCloneLine = buildFileArr[i - 1];
sourcePushdFound = true;
}
}
}
async function run() {
try {
const engineNames = await fs.readdir(packagesEnginesPath);
const issuesFound = [];
for(let engine of engineNames) {
await checkEngine(engine, issuesFound);
}
console.info(`issuesFound: ${JSON.stringify(issuesFound, null, 4)}`);
const matrix = {};
if(issuesFound.length) {
matrix.include = [];
}
for(let downloadIssue of issuesFound) {
matrix.include.push(downloadIssue);
}
core.setOutput('matrix', JSON.stringify(matrix));
}
catch (error) {
core.setFailed(error.message);
}
}
run();