Deploy to GitHub Pages from Astro #4729
This file contains 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: Deploy to GitHub Pages from Astro | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
schedule: | |
- cron: "15 6 * * *" | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
build-and-deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ⏬ | |
uses: actions/checkout@v4 | |
- name: Setup Pages 📝 | |
uses: actions/configure-pages@v5 | |
- name: Setup Node.js environment 💚 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: latest | |
- name: Cache deps | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
key: npm-deps-${{ hashFiles('package-lock.json') }} | |
restore-keys: npm-deps- | |
- name: Install deps 🍢 | |
run: | | |
npm install | |
npm update | |
- name: Build Website from Astro 🏭 | |
run: npm run build | |
- name: Upload artifact ⏫ | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: './dist' | |
- name: Deploy to GitHub Pages ✍️ | |
uses: actions/deploy-pages@v4 | |
- name: Git | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add -A | |
git commit -m "Build" | |
git push | |
fi |