feat(ansible-example): add @ansible/example package, tests, CI, publish & deploy workflows, docs and changelog
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
module.exports.runPack = function runPack() {
|
||||
const cwd = path.join(__dirname, '..');
|
||||
// run npm pack and capture output
|
||||
const out = execSync('npm pack', { cwd, encoding: 'utf8' }).trim();
|
||||
// npm pack prints the filename on the last line
|
||||
const lines = out.split(/\r?\n/).filter(Boolean);
|
||||
const filename = lines[lines.length - 1];
|
||||
return { cwd, filename };
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const tests = [
|
||||
'test_package_json.js',
|
||||
'test_pack_inspect.js'
|
||||
];
|
||||
|
||||
const cwd = path.join(__dirname);
|
||||
let failed = false;
|
||||
for (const t of tests) {
|
||||
console.log('Running', t);
|
||||
try {
|
||||
execSync(`node ${t}`, { cwd, stdio: 'inherit' });
|
||||
} catch (e) {
|
||||
console.error(t, 'failed');
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
process.exit(failed ? 1 : 0);
|
||||
@@ -0,0 +1,28 @@
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { runPack } = require('./_pack_helpers');
|
||||
try {
|
||||
const { cwd, filename } = runPack();
|
||||
const tarPath = path.join(cwd, filename);
|
||||
if (!fs.existsSync(tarPath)) throw new Error('tarball not found: ' + tarPath);
|
||||
// inspect package/package.json within tarball using tar -xOzf
|
||||
const execSync = require('child_process').execSync;
|
||||
let pkgJsonStr;
|
||||
try {
|
||||
pkgJsonStr = execSync(`tar -xOzf ${filename} package/package.json`, { cwd, encoding: 'utf8' });
|
||||
} catch (e) {
|
||||
throw new Error('failed to extract package.json from tarball; ensure `tar` is available');
|
||||
}
|
||||
const pkg = JSON.parse(pkgJsonStr);
|
||||
assert.strictEqual(pkg.name, '@ansible/example', 'tarball package.json name mismatch');
|
||||
assert.ok(pkg.version, 'tarball package.json missing version');
|
||||
console.log('test_pack_inspect: OK');
|
||||
// cleanup: remove tarball
|
||||
try { fs.unlinkSync(tarPath); } catch (e) {}
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('test_pack_inspect: FAILED');
|
||||
console.error(err && err.message ? err.message : err);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
||||
|
||||
try {
|
||||
assert.strictEqual(pkg.name, '@ansible/example', 'package name must be @ansible/example');
|
||||
assert.ok(pkg.version && typeof pkg.version === 'string', 'version must be present');
|
||||
assert.ok(pkg.author && pkg.author.includes('Sven'), 'author must be Sven Geboers');
|
||||
assert.ok(pkg.publishConfig && pkg.publishConfig.access === 'public', 'publishConfig.access must be public');
|
||||
assert.ok(Array.isArray(pkg.files), 'files array must exist');
|
||||
console.log('test_package_json: OK');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('test_package_json: FAILED');
|
||||
console.error(err && err.message ? err.message : err);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user