Skip to content

Commit

Permalink
Created action for listing packages with their tags for an organizati…
Browse files Browse the repository at this point in the history
…on (#1)

* Created action for listing packages with their tags for an organization

* Disabled linter for dist/index.js file

* Disable the linter for dist/index.js file for resolving errors

* Resolved linting errors

* Testing the github action

* Created a token for testing

* Updated dist/index.js file
  • Loading branch information
nmathur478 authored Apr 5, 2023
1 parent d6b483f commit f0274bf
Show file tree
Hide file tree
Showing 8 changed files with 4,458 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: TestCase 1 - Testing the working of action
on:
push:
branches:
- "list-packages-with-tags" # Enter the branch you want to test

jobs:
run-action:
runs-on: ubuntu-latest
steps:
- name: Checkout repository (clone the repo for use)
uses: actions/checkout@v3
- uses: Calance-US/calance-list-packages-with-tags-action@list-packages-with-tags
id: list-packages-with-tags
with:
image_name: calance-workflows
package_type: container
organization: Calance-US
GET_PACKAGES_TOKEN: ${{ secrets.GET_PACKAGES_TOKEN }}
- name: Echo the outputs
run: |
echo ${{ steps.list-packages-with-tags.outputs.packages-with-tags }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 0 additions & 3 deletions Dockerfile

This file was deleted.

24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: List packages with tags
description: List packages with tags

inputs:
image_name:
description: Image Names in CSV format
required: true
package_type:
description: Enter the package type (Options are container,docker,npm etc.)
required: true
organization:
description: Enter the name of organization
required: true
GET_PACKAGES_TOKEN:
description: Github token with permissions - read:packages
required: true

outputs:
packages-with-tags:
description: Packages with their tags

runs:
using: 'node16'
main: 'dist/index.js'
8 changes: 8 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const core = require('@actions/core')
const Github = require('@actions/github')

const listPackagesWithTags = async () => {
try {
const versionedPackages = []
let packagesArray = core.getInput('image_name', { required: true })
packagesArray = packagesArray.split(',').map(x => x.trim())
const token = core.getInput('GET_PACKAGES_TOKEN', { required: true })
const github = Github.getOctokit(token)
const packageType = core.getInput('package_type', { required: true })
const organization = core.getInput('organization', { required: true })

for (let i = 0; i < packagesArray.length; i++) {
const resp1 = await github.request('GET /orgs/{organization}/packages/{packageType}/{packageName}/versions', {
packageName: packagesArray[i],
packageType,
organization
})
const resp2 = resp1.data.map(data => data.metadata)
for (let j = 0; j < resp2.length; j++) {
const tags = resp2[j].container.tags
if (tags === []) {
continue
} else {
for (let k = 0; k < tags.length; k++) {
versionedPackages.push(packagesArray[i].concat(':', tags[k]))
}
}
}
}
console.log(versionedPackages)
core.setOutput('packages-with-tags', versionedPackages)
} catch (error) {
core.setFailed(error.message)
}
}
listPackagesWithTags()
Loading

0 comments on commit f0274bf

Please sign in to comment.