Skip to content

Commit

Permalink
Rudiments of a repeatable release mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
lupestro committed Oct 9, 2022
1 parent f5835c2 commit b04669a
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 59 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Release Creation

on:
push:
tags:
- 'release-*'


jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3


# Set up our some variables for future use
# Adapted from https://github.community/t/how-to-get-just-the-tag-name/16241/7
# Tag name: ${{ steps.get_vars.outputs.TAG_NAME }}
# Zip name: ${{ steps.get_vars.outputs.ZIP_NAME }}
# Expected Release Download URL: ${{ steps.get_vars.outputs.RELEASE_DOWNLOAD_URL }}
# Expected Release system.json URL: ${{ steps.get_vars.outputs.RELEASE_INSTALL_URL }}
# Stringified system.json contents: ${{ steps.get_vars.outputs.SYSTEM_JSON }}
- name: Set up variables
id: get_vars
run: |
TAG=${GITHUB_REF/refs\/tags\//}
echo ::set-output name=TAG_NAME::$TAG
echo ::set-output name=ZIP_NAME::fudge-$TAG.zip
echo ::set-output name=RELEASE_DOWNLOAD_URL::https://github.com/${{github.repository}}/releases/download/$TAG/fudge-$TAG.zip
echo ::set-output name=RELEASE_INSTALL_URL::https://github.com/${{github.repository}}/releases/download/$TAG/system.json
JSON=$(cat ./system.json)
echo ::set-output name=SYSTEM_JSON::${JSON//'%'/'%25'}
# Run some tests to make sure our `system.json` is correct
# Exit before setting up node if not
- name: Verify correct naming
env:
TAG_NAME: ${{ steps.get_vars.outputs.TAG_NAME }}
RELEASE_DOWNLOAD: ${{steps.get_vars.outputs.RELEASE_DOWNLOAD_URL}}
# Extract version and download url from system.json
# https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson
PACKAGE_VERSION: ${{fromJSON(steps.get_vars.outputs.SYSTEM_JSON).version}}
PACKAGE_DOWNLOAD: ${{fromJSON(steps.get_vars.outputs.SYSTEM_JSON).download}}
run: |
# Validate that the tag being released matches the package version.
if [[ ! $TAG_NAME == release-$PACKAGE_VERSION ]]; then
echo "The system.json version does not match tag name."
echo "system.json: $PACKAGE_VERSION"
echo "tag name: $TAG_NAME"
echo "Please fix this and push the tag again."
exit 1
fi
# Validate that the package download url matches the release asset that will be created.
if [[ ! $RELEASE_DOWNLOAD == $PACKAGE_DOWNLOAD ]]; then
echo "The system.json download url does not match the created release asset url."
echo "system.json: $PACKAGE_DOWNLOAD"
echo "release asset url: $RELEASE_DOWNLOAD"
echo "Please fix this and push the tag again."
exit 1
fi
# Set up Node
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'npm'


# `npm ci` is recommended:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
- name: Install Dependencies
run: npm ci


# Run our `build` script
- name: Build All
run: |
npm run build --if-present
mv --force fudge-compiled.mjs fudge.mjs
# Create a zip file with all files required by the module to add to the release
- run: zip ${{steps.get_vars.outputs.ZIP_NAME}} -r lang templates packs/*.db styles/*.css fudge.mjs fudge.mjs.map LICENSE.txt FudgeOGLicense.pdf fudge_srd.pdf README.md system.json template.json


# Create a release for this specific version
- name: Update Release with Files
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true # Set this to false if you want to prevent updating existing releases
name: ${{steps.get_vars.outputs.TAG_NAME}}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './system.json, ./${{steps.get_vars.outputs.ZIP_NAME}}'
tag: ${{steps.get_vars.outputs.TAG_NAME}}
body: '**Installation:** To manually install this release, please use the following manifest URL: ${{steps.get_vars.outputs.RELEASE_INSTALL_URL}}'
13 changes: 12 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"name": "From RegExp",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/build/skills-from-re.js",
"args": ["skill-template.json" ,"srd-skill-list.txt"]
},
{
"type": "node",
"request": "launch",
"name": "Compile Packs",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": ["compilePacks"]
}

]
}
37 changes: 0 additions & 37 deletions build/packs-from-json.js

This file was deleted.

44 changes: 23 additions & 21 deletions build/packs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ export const clean = cleanPacks;
/* Compile Packs */
/* ----------------------------------------- */

const _packageCompendiumFromJson = async function ( packsrc, packdest, packname) {
const packFilename = path.join(packdest, `${packname}.db`);
logger.info(`Removing compendium: ${packFilename}`);
fs.rmSync(packFilename, {force: true});
const realDB = new Datastore({filename: packFilename, autoload: true});
const files = fs.readdirSync(path.join(packsrc, packname), {withFileTypes: true})
.filter((file) => file.name.endsWith('.json')).map(dirent => dirent.name);
// console.log('Files:',files);
for (const file of files) {
const filedata = JSON.parse(fs.readFileSync(path.join(packsrc, packname, file), {encoding:'utf-8'}));
cleanPackEntry(filedata);
if (!filedata._id) {
filedata._id = realDB.createNewId();
}
filedata.folder = "";
realDB.insert(filedata);
}
logger.info(`Built compendium: ${packFilename}`);
return Promise.resolve(files.length);
}

/**
* Compile the source JSON files into compendium packs.
*
Expand All @@ -213,32 +234,13 @@ const compilePacks = async function() {
.filter((file) => file.isDirectory() && ( !packName || packName === file.name ));

const packs = folders.map( (folder) => {
const filePath = path.join(PACK_DEST, `${folder.name}.db`);
fs.rmSync(filePath, {force: true});
const db = fs.createWriteStream(filePath, {flags: "a", mode: 0o664});
const data = [];
logger.info(`Compiling pack ${folder.name}`);
return gulp.src(path.join(PACK_SRC, folder.name, "/**/*.json"))
.pipe(through2.obj((file, enc, callback) => {
const json = JSON.parse(file.contents.toString());
cleanPackEntry(json);
data.push(json);
callback(null, file);
}, (callback) => {
// eslint-disable-next-line no-confusing-arrow
data.sort( (lhs, rhs) => lhs._id > rhs._id ? 1 : -1);
data.forEach((entry) => {
db.write(`${JSON.stringify(entry)}\n`);
});
callback();
}));
return _packageCompendiumFromJson(PACK_SRC, PACK_DEST, folder.name);
});
const result = await mergeStream(packs);
return result;
return packs;
};
export const compile = compilePacks;


/* ----------------------------------------- */
/* Extract Packs */
/* ----------------------------------------- */
Expand Down

0 comments on commit b04669a

Please sign in to comment.