Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update and publish to GitHub pages using GitHub actions #18

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

BlueHtml
Copy link
Contributor

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
image

Change uglify-es to uglify-js;
When building, download uglify-js from GitHub releases instead of git;
When publishing, use CDN instead of local files for uglify-js;
@Skalman
Copy link
Owner

Skalman commented Jul 16, 2024

@BlueHtml, thank you, I really appreciate the PR!

Copy link
Owner

@Skalman Skalman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping to modernize this repo using GH actions. Just a couple of minor suggestions for how to avoid unnecessary dependencies.

run: bash build/update.sh
# Deploy the site
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What advantages are there to using this custom action instead of Github's "standard" actions? I'm not familiar with either, so I was just looking at Github's suggested workflows, in this case the "static HTML" one.

# Github's suggestion: "Static HTML"
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          # Upload entire repository
          path: '.'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the GitHub Pages documentation:

Most external CI workflows "deploy" to GitHub Pages by committing the build output to the gh-pages branch of the repository, and typically include a .nojekyll file.

Use the actions/upload-pages-artifact action to upload the static files as an artifact.
use the actions/deploy-pages action to deploy the artifact.

  • peaceiris/actions-gh-pages: This action creates a gh-pages branch, and we need to configure GitHub Pages to use this gh-pages branch.
    • Settings -> Pages -> Build and deployment -> Source -> Select Deploy from a branch -> Select gh-pages branch
  • Github's "standard" actions (actions/upload-pages-artifact + actions/deploy-pages): This action will create an artifact, and then we need to configure GitHub Pages to use GitHub Actions.
    • Settings -> Pages -> Build and deployment -> Source -> Select GitHub Actions

I think using the gh-pages branch is better because switching branches allows you to see the generated static files.
But the artifact needs to be downloaded to view the file, and the artifact will expire, with a default of 90 days(By default, GitHub stores build logs and artifacts for 90 days, and this retention period can be customized.)

image

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for explaining!

build/update.sh Outdated
Comment on lines 47 to 51
CDN="//registry.npmmirror.com/uglify-js/$VERSION/files"
CDN="${CDN//\//\\\/}"
sed -i 's/\(<script src="\)uglify/\1'"$CDN"'/gI' index.html

rm -rf uglify
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of using a CDN here. We should be able to just copy the uglify dir into public, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly. I will remove CDN and use local files ( I am in China, CDN speed will be faster )

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. If we want to speed things up, it might help to concat the relevant JS files, but that could be done in a follow-up PR if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants