-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed name to make more sense
- Loading branch information
Daniel Dickerson
committed
Mar 21, 2022
1 parent
4fb3bbe
commit 36fac97
Showing
5 changed files
with
99 additions
and
65 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,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"arrowParens": "always" | ||
} |
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
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
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 |
---|---|---|
@@ -1,54 +1,65 @@ | ||
import fetch from 'node-fetch'; | ||
import core from '@actions/core'; | ||
import limitTags from "./modules/limitTags.js"; | ||
import limitTags from './modules/limitTags.js'; | ||
|
||
let repoUrl, images, regex, versionLimit; | ||
let imageArray = []; | ||
let outputTags = []; | ||
let outputImages = []; | ||
let promises = []; | ||
try { | ||
repoUrl = core.getInput("repo-url"); | ||
images = core.getInput("image"); | ||
regex = new RegExp(core.getInput("tag-regex")); | ||
versionLimit = core.getInput("version-limit"); | ||
repoUrl = core.getInput('repo-url'); | ||
images = core.getInput('images'); | ||
regex = new RegExp(core.getInput('tag-regex')); | ||
versionLimit = core.getInput('version-limit'); | ||
} catch (err) { | ||
const msg = "Failed to initialize action: " + err.message; | ||
const msg = 'Failed to initialize action: ' + err.message; | ||
core.setFailed(msg); | ||
console.error(msg); | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
|
||
const processResponse = (res) => { | ||
if (res.status < 400) { | ||
return res.json(); | ||
} else { | ||
throw new Error( | ||
`Response from server: '${res.statusText}' (${res.status}) for URL ${res.url}` | ||
); | ||
} | ||
if (res.status < 400) { | ||
return res.json(); | ||
} else { | ||
throw new Error( | ||
`Response from server: '${res.statusText}' (${res.status}) for URL ${res.url}` | ||
); | ||
} | ||
}; | ||
|
||
try { | ||
imageArray = JSON.parse(images); | ||
} catch (err) { | ||
imageArray.push(images); | ||
} | ||
imageArray.forEach(element => { | ||
fetch(`${repoUrl}/v2/${images}/tags/list`) | ||
|
||
|
||
imageArray.forEach((image) => { | ||
promises.push( | ||
fetch(`${repoUrl}/v2/${image}/tags/list`) | ||
.then((response) => processResponse(response)) | ||
.then((json) => { | ||
let { tags } = json; | ||
let filteredTags = tags.filter((tag) => regex.test(tag)); | ||
let limitedTags = limitTags(filteredTags, versionLimit); | ||
outputTags.concat(limitedTags); | ||
let { tags } = json; | ||
let filteredTags = tags.filter(tag => regex.test(tag)); | ||
let limitedTags = limitTags(filteredTags, versionLimit); | ||
let fullNames = limitedTags.map((tag) => `${image}:${tag}`); | ||
outputImages.push(...fullNames); | ||
}) | ||
.catch((err) => { | ||
const msg = "Failed to scan Docker repository: " + err.message; | ||
core.setFailed(msg); | ||
console.error(msg); | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
const msg = 'Failed to scan Docker repository: ' + err.message; | ||
core.setFailed(msg); | ||
console.error(msg); | ||
console.error(err); | ||
process.exit(1); | ||
}) | ||
) | ||
}); | ||
|
||
core.setOutput("tags", outputTags); | ||
Promise.all(promises).then(() => { | ||
console.log(`Images discovered:\n${outputImages.join('\n')}`); | ||
core.setOutput('images', outputImages); | ||
}); | ||
|
||
|
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