Skip to content

Update build script with more automation & flexibility #71

Update build script with more automation & flexibility

Update build script with more automation & flexibility #71

Workflow file for this run

name: Release Creation
env:
NODE_VERSION: 22
on:
push:
tags:
- 'release-*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Load project details
id: type
uses: ActionsTools/read-json-action@main
with:
file_path: "./foundryvtt.json"
prop_path: "project.type"
- name: Load project premium status
id: premium
continue-on-error: true
uses: ActionsTools/read-json-action@main
with:
file_path: "./foundryvtt.json"
prop_path: "project.premium"
- name: Load project includes
id: config
continue-on-error: true
uses: ActionsTools/read-json-action@main
with:
file_path: "./foundryvtt.json"
- name: Load system manifest
id: manifest
uses: ActionsTools/read-json-action@main
with:
file_path: "./${{ steps.type.outputs.value }}.json"
# 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: ${{ env.TAG_NAME }}
# Zip name: ${{ env.ZIP_NAME }}
# Expected Release Download URL: ${{ env.RELEASE_DOWNLOAD_URL }}
# Expected Release system.json URL: ${{ env.RELEASE_INSTALL_URL }}
- name: Set up variables
id: get_vars
run: |
TAG=${GITHUB_REF/refs\/tags\//}
PACKAGE_ID=${{ steps.manifest.outputs.id }}
PACKAGE_TYPE=${{ steps.type.outputs.value }}
echo "TAG_NAME=$TAG" >> $GITHUB_ENV
echo "PACKAGE_ID=$PACKAGE_ID" >> $GITHUB_ENV
echo "PACKAGE_TYPE=$PACKAGE_TYPE" >> $GITHUB_ENV
echo "ZIP_NAME=$PACKAGE_ID-$TAG.zip" >> $GITHUB_ENV
echo "RELEASE_DOWNLOAD_URL=https://github.com/${{ github.repository }}/releases/download/$TAG/$PACKAGE_ID-$TAG.zip" >> $GITHUB_ENV
echo "RELEASE_INSTALL_URL=https://github.com/${{ github.repository }}/releases/download/$TAG/$PACKAGE_TYPE.json" >> $GITHUB_ENV
# 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: ${{ env.TAG_NAME }}
RELEASE_DOWNLOAD: ${{ env.RELEASE_DOWNLOAD_URL }}
PACKAGE_TYPE: ${{ env.PACKAGE_TYPE }}
PACKAGE_VERSION: ${{ steps.manifest.outputs.version }}
PACKAGE_DOWNLOAD: ${{ steps.manifest.outputs.download }}
run: |
# Validate that the tag being released matches the package version.
if [[ ! $TAG_NAME == release-$PACKAGE_VERSION ]]; then
echo "The $PACKAGE_TYPE.json version does not match tag name."
echo "$PACKAGE_TYPE.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 $PACKAGE_TYPE.json download url does not match the created release asset url."
echo "$PACKAGE_TYPE.json: $PACKAGE_DOWNLOAD"
echo "release asset url: $RELEASE_DOWNLOAD"
echo "Please fix this and push the tag again."
exit 1
fi
- name: Adjust manifest
uses: TomaszKandula/[email protected]
with:
files: "system.json"
env:
flags.hotReload: false
- name: Set protected flag for premium modules
if: ${{ steps.premium.outputs.value }}
uses: microsoft/variable-substitution@v1
with:
files: "${{ env.PACKAGE_TYPE }}.json"
env:
protected: true
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
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
- name: Build All
run: |
npm run build:code --if-present
mv --force dnd5e-compiled.mjs dnd5e.mjs
- name: Determine archive contents
id: archive
uses: actions/github-script@v6
env:
ESMODULES: ${{ steps.manifest.outputs.esmodules }}
INCLUDES: ${{ steps.config.outputs.includes }}
LANGUAGES: ${{ steps.manifest.outputs.languages }}
PACKS: ${{ steps.manifest.outputs.packs }}
STYLES: ${{ steps.manifest.outputs.styles }}
with:
result-encoding: string
script: |
const manifest = {};
if ( process.env.ESMODULES ) manifest.esmodules = JSON.parse(process.env.ESMODULES);
if ( process.env.INCLUDES ) manifest.includes = JSON.parse(process.env.INCLUDES);
if ( process.env.LANGUAGES ) manifest.languages = JSON.parse(process.env.LANGUAGES);
if ( process.env.PACKS ) manifest.packs = JSON.parse(process.env.PACKS);
if ( process.env.STYLES ) manifest.styles = JSON.parse(process.env.STYLES);
const includes = [
"${{ env.PACKAGE_TYPE }}.json",
...(manifest.esmodules ?? []),
...(manifest.esmodules?.map(s => `${s}.map`) ?? []),
...(manifest.styles ?? []),
...(manifest.packs?.map(p => p.path) ?? []),
...(manifest.languages?.map(l => l.path) ?? []),
...(manifest.includes ?? [])
];
return includes.join(" ");
- name: Zip package
run: zip ${{ env.ZIP_NAME }} -r ${{ steps.archive.outputs.result }}
- name: Fetch Release Body
id: release
uses: cardinalby/git-get-release-action@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag: ${{ env.TAG_NAME }}
doNotFailIfNotFound: true
- 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: ${{ env.TAG_NAME }}
draft: false
prerelease: true
omitDraftDuringUpdate: true
omitPrereleaseDuringUpdate: true
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './${{ env.PACKAGE_TYPE }}.json, ./${{ env.ZIP_NAME }}'
tag: ${{ env.TAG_NAME }}
body: |
${{ steps.release.outputs.body }}
**Installation:** To manually install this release, please use the following manifest URL: ${{ env.RELEASE_INSTALL_URL }}