isActionRepo()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as fsHelper from '../src/fs-helper'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as os from 'os'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
@@ -131,6 +132,33 @@ describe('isDirectory', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('isActionRepo', () => {
|
||||
let stagingDir: string
|
||||
|
||||
beforeEach(() => {
|
||||
stagingDir = fsHelper.createTempDir()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(stagingDir, { recursive: true })
|
||||
})
|
||||
|
||||
it('returns true if action.yml exists at the root', () => {
|
||||
fs.writeFileSync(path.join(stagingDir, `action.yml`), fileContent)
|
||||
expect(fsHelper.isActionRepo(stagingDir)).toEqual(true)
|
||||
})
|
||||
|
||||
it('returns true if action.yaml exists at the root', () => {
|
||||
fs.writeFileSync(path.join(stagingDir, `action.yaml`), fileContent)
|
||||
expect(fsHelper.isActionRepo(stagingDir)).toEqual(true)
|
||||
})
|
||||
|
||||
it('returns false if action.y(a)ml doesn\'t exist at the root', () => {
|
||||
fs.writeFileSync(path.join(stagingDir, `action.yaaml`), fileContent)
|
||||
expect(fsHelper.isActionRepo(stagingDir)).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('readFileContents', () => {
|
||||
let dir: string
|
||||
|
||||
|
||||
@@ -91,6 +91,14 @@ export function isDirectory(dirPath: string): boolean {
|
||||
return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory()
|
||||
}
|
||||
|
||||
export function isActionRepo(stagingDir: string): boolean {
|
||||
return (
|
||||
fs.existsSync(path.join(stagingDir, 'action.yml')) ||
|
||||
fs.existsSync(path.join(stagingDir, 'action.yaml'))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export function readFileContents(filePath: string): Buffer {
|
||||
return fs.readFileSync(filePath)
|
||||
}
|
||||
@@ -116,6 +124,7 @@ export function bundleFilesintoDirectory(
|
||||
return targetDir
|
||||
}
|
||||
|
||||
|
||||
// Converts a file path to a filemetadata object by querying the fs for relevant metadata.
|
||||
async function fileMetadata(filePath: string): Promise<FileMetadata> {
|
||||
const stats = fs.statSync(filePath)
|
||||
|
||||
@@ -65,6 +65,13 @@ export async function run(pathInput: string): Promise<void> {
|
||||
path = fsHelper.bundleFilesintoDirectory(paths, bundleDir)
|
||||
}
|
||||
|
||||
if (!fsHelper.isActionRepo(path)) {
|
||||
core.setFailed(
|
||||
'action.y(a)ml not found. Action packages can be created only for action repositories.'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Create a temporary directory to store the archives
|
||||
const archiveDir = fsHelper.createTempDir()
|
||||
tmpDirs.push(archiveDir)
|
||||
|
||||
Reference in New Issue
Block a user