Fix update from upstream workflow #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bundle and Deploy | |
on: | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
workflow_dispatch: | |
permissions: read-all | |
jobs: | |
bundle: | |
name: Bundle and Minify | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Add production constants | |
run: | | |
sed -i 's/const VERSION = "dev";/const VERSION = "${{ github.ref_name }}";/g' HoloPrint.js | |
sed -i 's/const IN_PRODUCTION = false;/const IN_PRODUCTION = true;/g' index.js | |
- name: Bundle and minify | |
run: | | |
npm install -g esbuild html-minifier clean-css-cli strip-json-comments-cli json-minify | |
external_modules=$(awk '/<script type="importmap">/,/<\/script>/' index.html | sed -n '2,$p' | sed '$d' | jq -r '.imports | keys[]' | awk '{printf "--external:%s ", $0}') # ChatGPT says this is how to get all imports from index.html | |
esbuild --bundle --define:VERSION='"${TAG_NAME}"' --external:./entityScripts.molang.js $external_modules --format=esm --minify --outdir=. --allow-overwrite --sourcemap --analyze --metafile=esbuild_meta.json index.js | |
find . -type f | while read file; do | |
if [[ $file == *.html ]]; then | |
echo "Minifying $file" | |
html-minifier --remove-comments --collapse-whitespace --remove-optional-tags ${file} > temp && mv temp ${file} | |
elif [[ $file == *.css ]]; then | |
echo "Minifying $file" | |
cleancss -O2 ${file} > temp && mv temp ${file} | |
elif [[ $file == *.json || $file == *.material || $file == *.webmanifest ]]; then | |
echo "Minifying and de-commenting $file" | |
strip-json-comments --no-whitespace ${file} | json-minify > temp && mv temp $file | |
truncate -s -1 ${file} | |
fi | |
done | |
- name: Remove unnecessary files | |
run: | | |
rm *.md | |
rm -r tests | |
rm -r supabase | |
rm -r data/schemas | |
rm -rf .* | |
keys=$(jq -r '.inputs | keys[]' "esbuild_meta.json") | |
for key in $keys; do | |
if [ "$key" != "index.js" ]; then | |
rm "$key" | |
fi | |
done | |
rm esbuild_meta.json | |
tree -f | |
- name: Upload files as artifact | |
uses: actions/[email protected] | |
with: | |
path: . | |
deploy: | |
name: Deploy | |
needs: bundle | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/[email protected] | |
update-fork: | |
name: Update Fork (HoloPrint-MC) | |
needs: deploy | |
runs-on: ubuntu-latest | |
if: github.repository == 'SuperLlama88888/holoprint' | |
steps: | |
- name: Trigger workflow in fork | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.PAT }} | |
script: | | |
let res = await github.rest.actions.createWorkflowDispatch({ | |
owner: 'HoloPrint-MC', | |
repo: 'holoprint-mc.github.io', | |
workflow_id: 'updateFromUpstream.yml', | |
ref: 'main' | |
}); | |
console.log(`Workflow triggered with status ${res.status}`); |