Merge pull request #2 from ddivad195/esirko/validation-stuff
validation stuff
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
|
||||
|
||||
|
||||
+11
-8
@@ -74693,7 +74693,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.bundleFilesintoDirectory = exports.readFileContents = exports.isDirectory = exports.createArchives = exports.removeDir = exports.createTempDir = void 0;
|
||||
exports.bundleFilesintoDirectory = exports.readFileContents = exports.isActionRepo = exports.isDirectory = exports.createArchives = exports.removeDir = exports.createTempDir = void 0;
|
||||
const fs = __importStar(__nccwpck_require__(57147));
|
||||
const fs_extra_1 = __importDefault(__nccwpck_require__(5630));
|
||||
const path = __importStar(__nccwpck_require__(71017));
|
||||
@@ -74764,6 +74764,11 @@ function isDirectory(dirPath) {
|
||||
return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
|
||||
}
|
||||
exports.isDirectory = isDirectory;
|
||||
function isActionRepo(stagingDir) {
|
||||
return (fs.existsSync(path.join(stagingDir, 'action.yml')) ||
|
||||
fs.existsSync(path.join(stagingDir, 'action.yaml')));
|
||||
}
|
||||
exports.isActionRepo = isActionRepo;
|
||||
function readFileContents(filePath) {
|
||||
return fs.readFileSync(filePath);
|
||||
}
|
||||
@@ -75052,17 +75057,11 @@ async function run(pathInput) {
|
||||
// https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions
|
||||
const targetVersion = semver_1.default.parse(releaseTag.replace(/^v/, ''));
|
||||
if (!targetVersion) {
|
||||
// TODO: We may want to limit semvers to only x.x.x, without the pre-release tags, but for now we'll allow them.
|
||||
core.setFailed(`${releaseTag} is not a valid semantic version, and so cannot be uploaded as an Immutable Action.`);
|
||||
return;
|
||||
}
|
||||
const token = process.env.TOKEN;
|
||||
// TODO: once https://github.com/github/github/pull/309384 goes in, we can switch to the actual endpoint
|
||||
//const response = await fetch(
|
||||
// process.env.GITHUB_API_URL + '/packages/container-registry-url'
|
||||
//)
|
||||
const response = await fetch('http://echo.jsontest.com/url/https:ghcr.io' // for testing locally. Remove the slashes, they will be reintroduced when forming the URL object below
|
||||
);
|
||||
const response = await fetch(process.env.GITHUB_API_URL + '/packages/container-registry-url');
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch status page: ${response.statusText}`);
|
||||
}
|
||||
@@ -75084,6 +75083,10 @@ async function run(pathInput) {
|
||||
tmpDirs.push(bundleDir);
|
||||
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);
|
||||
|
||||
@@ -17,9 +17,11 @@ fi
|
||||
|
||||
echo "Generating new version $VERSION with message $MESSAGE"
|
||||
|
||||
sed -i '' -E 's/ddivad195\/publish-action-package\/package-and-publish.*$/ddivad195\/publish-action-package\/package-and-publish@'$VERSION'/g' action.yml
|
||||
#sed -i '' -E 's/ddivad195\/publish-action-package\/package-and-publish.*$/ddivad195\/publish-action-package\/package-and-publish@'$VERSION'/g' action.yml
|
||||
npm run bundle
|
||||
git add .
|
||||
git commit -m "$VERSION: $MESSAGE"
|
||||
git push
|
||||
git tag $VERSION
|
||||
git push origin $VERSION
|
||||
gh release create --repo ddivad195/publish-action-package --title $VERSION --notes $VERSION $VERSION
|
||||
@@ -91,6 +91,13 @@ 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)
|
||||
}
|
||||
|
||||
+19
-14
@@ -21,17 +21,18 @@ export async function run(pathInput: string): Promise<void> {
|
||||
core.setFailed(`Could not find Repository.`)
|
||||
return
|
||||
}
|
||||
|
||||
if (github.context.eventName !== 'release') {
|
||||
core.setFailed('Please ensure you have the workflow trigger as release.')
|
||||
return
|
||||
}
|
||||
|
||||
const releaseId: string = github.context.payload.release.id
|
||||
const releaseTag: string = github.context.payload.release.tag_name
|
||||
// Strip any leading 'v' from the tag in case the release format is e.g. 'v1.0.0' as recommended by GitHub docs
|
||||
// https://docs.github.com/en/actions/creating-actions/releasing-and-maintaining-actions
|
||||
const targetVersion = semver.parse(releaseTag.replace(/^v/, ''))
|
||||
if (!targetVersion) {
|
||||
// TODO: We may want to limit semvers to only x.x.x, without the pre-release tags, but for now we'll allow them.
|
||||
core.setFailed(
|
||||
`${releaseTag} is not a valid semantic version, and so cannot be uploaded as an Immutable Action.`
|
||||
)
|
||||
@@ -39,19 +40,6 @@ export async function run(pathInput: string): Promise<void> {
|
||||
}
|
||||
|
||||
const token: string = process.env.TOKEN!
|
||||
// TODO: once https://github.com/github/github/pull/309384 goes in, we can switch to the actual endpoint
|
||||
//const response = await fetch(
|
||||
// process.env.GITHUB_API_URL + '/packages/container-registry-url'
|
||||
//)
|
||||
const response = await fetch(
|
||||
'http://echo.jsontest.com/url/https:ghcr.io' // for testing locally. Remove the slashes, they will be reintroduced when forming the URL object below
|
||||
)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch status page: ${response.statusText}`)
|
||||
}
|
||||
const data = await response.json()
|
||||
const registryURL: URL = new URL(data.url)
|
||||
console.log(`Container registry URL: ${registryURL}`)
|
||||
|
||||
// Gather & validate user input
|
||||
// Paths to be included in the OCI image
|
||||
@@ -69,6 +57,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)
|
||||
@@ -89,6 +84,16 @@ export async function run(pathInput: string): Promise<void> {
|
||||
.update(JSON.stringify(manifest))
|
||||
.digest('hex')
|
||||
|
||||
const response = await fetch(
|
||||
process.env.GITHUB_API_URL + '/packages/container-registry-url'
|
||||
)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch status page: ${response.statusText}`)
|
||||
}
|
||||
const data = await response.json()
|
||||
const registryURL: URL = new URL(data.url)
|
||||
console.log(`Container registry URL: ${registryURL}`)
|
||||
|
||||
const packageURL = await ghcr.publishOCIArtifact(
|
||||
token,
|
||||
registryURL,
|
||||
|
||||
Reference in New Issue
Block a user