feat: auto cache-bust CSS/JS with content hash on deploy #32
This file contains hidden or 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: Github Pages | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache-bust CSS and JS with content hash | |
| run: | | |
| CSS_HASH=$(md5sum html/style.css | cut -c1-8) | |
| JS_HASH=$(md5sum html/main.js | cut -c1-8) | |
| find html -name '*.html' -exec sed -i "s|style\.css?v=[^\"]*|style.css?v=${CSS_HASH}|g" {} + | |
| find html -name '*.html' -exec sed -i "s|main\.js|main.js?v=${JS_HASH}|g" {} + | |
| - name: Deploy to GH Pages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./html |