Skip to content

Commit

Permalink
Merge pull request #4 from pew-actions/mendsley/support_pacakge_types
Browse files Browse the repository at this point in the history
Add ability to specify package type
  • Loading branch information
mendsley authored Oct 22, 2024
2 parents cdd8c82 + 16ec94c commit 13509af
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
image-tag:
description: 'Tag of the image to check'
required: true
package-type:
description: 'Type of package to query'
default: 'container'
required: false
outputs:
exists:
description: 'Boolean value of whether or not the image:tag exists on the registry'
Expand Down
29 changes: 21 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,38 @@ function run() {
core.setFailed('No access token passed to the action');
return;
}
const packageType = core.getInput('package-type') || 'container';
const octokit = new action_1.Octokit({
auth: token,
});
var foundImage = false;
try {
// Query container versions
const organizationLower = organization.toLowerCase();
const { data } = yield octokit.request(`Get /orgs/${organizationLower}/packages/container/${imageName}/versions`);
const { data } = yield octokit.request(`Get /orgs/${organizationLower}/packages/${packageType}/${imageName}/versions`);
// Search for the specified tag
for (let container of data) {
const tags = container.metadata.container.tags;
for (let tag of tags) {
if (tag == imageTag) {
foundImage = true;
if (packageType === 'container') {
for (let container of data) {
const tags = container.metadata.container.tags;
for (let tag of tags) {
if (tag == imageTag) {
foundImage = true;
break;
}
}
if (foundImage) {
break;
}
}
if (foundImage) {
break;
}
else {
// check collapsed 0s version
const alternateVersion = imageTag.split('.').map(x => parseInt(x, 10)).join('.');
for (let pkg of data) {
if (pkg.name === imageTag || pkg.name === alternateVersion) {
foundImage = true;
break;
}
}
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ async function run(): Promise<void> {
return
}

const packageType = core.getInput('package-type') || 'container'

const octokit = new Octokit({
auth: token,
})
Expand All @@ -38,22 +40,34 @@ async function run(): Promise<void> {
// Query container versions
const organizationLower = organization.toLowerCase()
const { data } = await octokit.request(
`Get /orgs/${organizationLower}/packages/container/${imageName}/versions`
`Get /orgs/${organizationLower}/packages/${packageType}/${imageName}/versions`
)

// Search for the specified tag
for (let container of data) {
const tags = container.metadata.container.tags
for (let tag of tags) {
if (tag == imageTag) {
foundImage = true
break
if (packageType === 'container') {
for (let container of data) {
const tags = container.metadata.container.tags
for (let tag of tags) {
if (tag == imageTag) {
foundImage = true
break
}

}

if (foundImage) {
break
}
}
} else {
// check collapsed 0s version
const alternateVersion = imageTag.split('.').map(x => parseInt(x, 10)).join('.')

if (foundImage) {
break
for (let pkg of data) {
if (pkg.name === imageTag || pkg.name === alternateVersion) {
foundImage = true
break
}
}
}
} catch (err: unknown) {
Expand Down

0 comments on commit 13509af

Please sign in to comment.