Merge pull request #266 from Bijikyu/q/add-comment-to-env-config.js #216
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: Build and Deploy # pipeline name for GitHub Actions | |
| on: | |
| push: | |
| branches: [main] # run when changes pushed to main | |
| workflow_dispatch: # allow manual triggering | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest # use latest Ubuntu runner | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 # fetch repo contents | |
| - name: Setup Node | |
| uses: actions/setup-node@v3 # install Node.js | |
| with: | |
| node-version: 18 # chosen Node version | |
| - name: Cache node modules #added cache step to speed installs | |
| uses: actions/cache@v3 # cache action for dependencies | |
| with: | |
| path: node_modules # directory to cache | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} # unique cache key | |
| restore-keys: | | |
| ${{ runner.os }}-node- # fallback key prefix | |
| - name: Install dependencies | |
| run: npm ci # uses lock file for deterministic install | |
| - name: Run tests #executes suite before build | |
| run: npm test #runs npm test command | |
| - name: Lint CSS | |
| run: npm run lint # ensure styles follow rules before build | |
| - name: Build CSS | |
| run: npm run build # generate core.<hash>.min.css and write build.hash | |
| - name: Update HTML | |
| run: node scripts/updateHtml.js # updates index links with hash | |
| - name: Prepare dist #gathers production files for deployment | |
| run: | | |
| mkdir dist #creates dist directory for artifact | |
| cp core.*.min.css dist/ #copies hashed stylesheet | |
| cp core.*.min.css.gz dist/ 2>/dev/null || true #copies gzip stylesheet | |
| cp core.*.min.css.br dist/ 2>/dev/null || true #copies brotli stylesheet | |
| cp index.html dist/ #copies main html | |
| cp variables.css dist/ #copies css variables | |
| cp *.png dist/ 2>/dev/null || true #copies images if present | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v1 # package files for deployment | |
| with: | |
| path: dist #upload only production files | |
| retention-days: 30 # keep artifact for 30 days | |
| tag: # job to create release tags #adds tagging job | |
| needs: build # wait for build job #ensures build completed | |
| runs-on: ubuntu-latest # use same runner #uses ubuntu | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 # fetch repo to tag | |
| - name: Create tag from commits | |
| id: tag # store outputs | |
| uses: mathieudutour/github-tag-action@v6.1 # semantic tag action | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} # auth for tag push | |
| - name: Echo tag | |
| run: echo "New tag ${{ steps.tag.outputs.new_tag }} created" # confirm tag | |
| deploy: | |
| needs: tag # deploy after tagging #ensures new tag exists | |
| runs-on: ubuntu-latest # same environment for deploy | |
| permissions: | |
| pages: write # allow page deployment | |
| id-token: write # GitHub pages token | |
| environment: | |
| name: github-pages # pages env | |
| url: ${{ steps.deploy.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deploy | |
| uses: actions/deploy-pages@v1 # push artifact to pages | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 # fetch repo for purge script | |
| - name: Setup Node | |
| uses: actions/setup-node@v3 # install Node.js | |
| with: | |
| node-version: 18 # version required for script | |
| - name: Install dependencies | |
| run: npm ci # uses lock file for deterministic install | |
| - name: Purge jsDelivr CDN | |
| run: | | |
| node - <<'EOF' #runs purge script targeting dist path | |
| const fs=require('fs'); //imports file system | |
| const purge=require('./scripts/purge-cdn'); //imports purge function | |
| const hash=fs.readFileSync('build.hash','utf8').trim(); //reads hash | |
| purge(`core.${hash}.min.css`).then(c=>{ //calls purge on new file | |
| console.log(`purge result ${c}`); //logs purge response code | |
| }).catch(e=>{console.error(e);process.exit(1);}); //handles errors | |
| EOF |