Skip to content

Commit

Permalink
Automatically update and publish to GitHub pages using GitHub actions (
Browse files Browse the repository at this point in the history
…#18)

Hello, I have upgraded uglify-es to uglify-js, and added the feature of
using GitHub actions to automatically update and publish to GitHub
pages.

Here are the specific changes:
- Add GitHub actions to publish on GitHub pages;
- Change uglify-es to uglify-js;
- When building, download uglify-js from GitHub releases instead of git;
- When publishing, use CDN(`registry.npmmirror.com`) instead of local
files for uglify-js;

Update steps:
1. On the GitHub actions page, manually run workflow `update` to build
and publish to the gh-pages branch;
2. Let GitHub pages use gh-pages branch;


![image](https://github.com/user-attachments/assets/892d2b99-104c-41f0-8cbd-0b059592a227)

![image](https://github.com/user-attachments/assets/2a8e9ae9-4911-4023-a111-6f42795a7fc5)
  • Loading branch information
BlueHtml committed Jul 17, 2024
1 parent b8f67c8 commit 63e41ff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 41 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: GitHub Pages

on:
workflow_dispatch:

jobs:
deploy:

if: github.actor == github.repository_owner
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

steps:
- uses: actions/checkout@main
- name: update
run: bash build/update.sh
# Deploy the site
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: public
force_orphan: true
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

50 changes: 13 additions & 37 deletions build/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,21 @@ cd ..
# Get version from NPM
mkdir -p build/tmp/

NPM_JSON="build/tmp/npm-uglify-es.json"
curl --silent --show-error https://registry.npmjs.org/uglify-es > "$NPM_JSON"
NPM_JSON="build/tmp/npm-uglify-js.json"
curl --silent --show-error https://registry.npmjs.org/uglify-js > "$NPM_JSON"

VERSION=$(jq -r '."dist-tags".latest' "$NPM_JSON")
VERSION_GIT_HEAD=$(jq -r '.versions[."dist-tags".latest].gitHead' "$NPM_JSON")

rm -r build/tmp/

echo "Latest version is $VERSION ($VERSION_GIT_HEAD)"
echo "Latest version is $VERSION"


# Update to this version
git clean -fd

git submodule update --init

cd uglify/

PREV_VERSION=$(jq -r '.version' package.json)

if [ "$VERSION" == "$PREV_VERSION" ]; then
echo "Already on the latest version, no update needed"
exit 0
fi

git fetch origin
if [ $? -ne 0 ]; then
echo "Exiting, because it was not possible to fetch remote commits of this submodule"
exit 1
fi

git pull --ff-only origin "$VERSION_GIT_HEAD"

if [ $? -ne 0 ]; then
echo "Exiting, because it was not possible to pull this submodule version"
exit 1
fi

cd ..
# Download this version
curl -fLs "https://github.com/mishoo/UglifyJS/archive/refs/tags/v$VERSION.zip" -o uglify.zip
unzip -oq uglify.zip
dir_name=$(unzip -Z -1 uglify.zip | head -n 1)
mv "$dir_name" uglify


# Update default options
Expand All @@ -67,10 +43,10 @@ fi


# Update version
sed -i 's/\(<code id="version">\)[^<]*\(<\/code>\)/\1uglify-es '"$VERSION"'\2/' index.html
sed -i 's/\(<code id="version">\)[^<]*\(<\/code>\)/\1uglify-js '"$VERSION"'\2/' index.html


# Commit and push
git add index.html
git add uglify
git commit -m "Update to uglify-es $VERSION"
# Publish
mkdir public
cp -r favicon.ico index.html script.js style.css uglify public
echo "Update to uglify-js $VERSION"
1 change: 0 additions & 1 deletion uglify
Submodule uglify deleted from aebc91

0 comments on commit 63e41ff

Please sign in to comment.