Skip to content

Commit

Permalink
fix: get manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
karczuRF committed Jun 20, 2024
1 parent efefb60 commit e66afd7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
package-name:
description: 'The tapplet package name'
required: true
package-version:
description: 'The tapplet package version'
required: true
default: '1.0.0'

outputs:
status:
Expand Down
30 changes: 15 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import { downloadAndExtractPackage } from './scripts/checksum/tapplet-installer'
export async function run(): Promise<void> {
try {
const packageName: string = core.getInput('package-name')
const packageVersion: string = core.getInput('version')
core.notice(`The ${packageName} tapplet registration process started...`)
// const url: string = core.getInput('package-url')
// const downloadPath = path.resolve('src', 'tapplet-candidate')

// Download the tapplet package and extract to verify the content
const tappletCandidate = await downloadAndExtractPackage(packageName)
const tappletCandidate = await downloadAndExtractPackage(
packageName,
packageVersion
)
core.notice(`The ${tappletCandidate.displayName} tapplet extracted`)

// Add new tapplet to the registry
Expand Down
23 changes: 14 additions & 9 deletions src/scripts/checksum/tapplet-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as zlib from 'zlib'
import * as tar from 'tar'
import { TappletCandidate } from 'src/types/tapplet'
import { getTappletCandidate } from '../tapplets/get-tapplet'
import { SRC_DIR } from 'src/constants'
import { MANIFEST_FILE, SRC_DIR } from 'src/constants'
import { getFileIntegrity } from './hash-calculator'

interface DownloadError {
Expand Down Expand Up @@ -105,23 +105,28 @@ export async function extractTarball(
}

export async function downloadAndExtractPackage(
packageName: string
packageName: string,
packageVersion: string
): Promise<TappletCandidate> {
// Read the content of the tapplet manifest to be registered
const tapplet: TappletCandidate = getTappletCandidate(packageName)
const folderPath = path.join(SRC_DIR, packageName, packageVersion)
const manifestPath = path.join(folderPath, MANIFEST_FILE)
const tarballPath = path.join(folderPath, `${packageName}.tar.gz`)

console.log('tapplet manifest', manifestPath)
console.log('tapplet tarball', tarballPath)

const folderPath = path.join(SRC_DIR, tapplet.packageName, tapplet.version)
const filePath = path.join(folderPath, `${tapplet.packageName}.tar.gz`)
// Read the content of the tapplet manifest to be registered
const tapplet: TappletCandidate = getTappletCandidate(manifestPath)

await downloadFile(
folderPath,
filePath,
tarballPath,
tapplet.source.location.npm.distTarball
)
await extractTarball(folderPath, filePath)
await extractTarball(folderPath, tarballPath)

// Validate checksum
const calculatedIntegrity = await getFileIntegrity(filePath)
const calculatedIntegrity = await getFileIntegrity(tarballPath)
if (calculatedIntegrity !== tapplet.source.location.npm.integrity)
throw new Error(
`The integrity mismatch! Calculated (${calculatedIntegrity}) is different from the registry value (${tapplet.source.location.npm.integrity})`
Expand Down
16 changes: 3 additions & 13 deletions src/scripts/tapplets/get-tapplet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,9 @@ export function fetchTappletCandidateData(
return tappletToRegister
}

export function getTappletCandidate(packageName: string): TappletCandidate {
const jsonDir = core.getInput('dir')

const manifestPath = path.resolve(
'src',
`${packageName}`,
'tapplet.manifest.json'
)

const platformPath = core.toPlatformPath(manifestPath)
core.notice(`Tapplet manifest dir: ${jsonDir}`)
core.notice(`Tapplet manifest platformPath: ${platformPath}`)
const tappData = fs.readFileSync(platformPath, 'utf8')
export function getTappletCandidate(manifestPath: string): TappletCandidate {
core.notice(`Tapplet manifest platformPath: ${manifestPath}`)
const tappData = fs.readFileSync(manifestPath, 'utf8')
return JSON.parse(tappData)
}

Expand Down

0 comments on commit e66afd7

Please sign in to comment.