Skip to content

Deploy to gh-pages

Deploy to gh-pages #33

Workflow file for this run

name: Deploy to gh-pages
on:
workflow_run:
workflows:
- CI
types:
- completed
workflow_dispatch:
jobs:
gh-deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success'
permissions:
contents: write
steps:
- name: Checking Out
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Prepare github pages
id: prepare_pages
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
MAIN_LATEST_HASH=$(git rev-parse --short=7 HEAD)
echo "--- Clone gh-pages branch to pages directory. ---"
git clone https://github.com/ittuann/Route2CIDR.git pages
cd pages
git checkout gh-pages
git status
echo "--- Clean old files. ---"
echo "--- Delete all tracked files ---"
git rm -rf . || echo "No tracked files to remove."
echo "--- Delete all untracked files ---"
git clean -fxd
echo "--- Copy new files. ---"
cp ../index.html .
cp -r ../dist ./dist
cp -r ../iconx ./iconx
git add .
echo "--- Attempts to commit changes. If there are no changes, a new commit will not be created. ---"
git commit -s -m "Deployed GitHub Pages - $MAIN_LATEST_HASH" || echo "No changes to commit."
echo "--- Check if there has been a new commit. ---"
LOCAL_HASH=$(git rev-parse HEAD)
REMOTE_HASH=$(git rev-parse @{u})
if [ "$LOCAL_HASH" != "$REMOTE_HASH" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "has_changes=true"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "has_changes=false"
fi
- name: Push changes
if: steps.prepare_pages.outputs.has_changes == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
directory: pages