Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

@thangbuiq - Implement CI/CD with test build job #66

@thangbuiq - Implement CI/CD with test build job

@thangbuiq - Implement CI/CD with test build job #66

Workflow file for this run

name: github pages
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-test:
name: Test build failure or success
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
extended: true
- name: Install Dependencies
run: |
npm install && npm install postcss-cli
- name: Build Static Site
run: |
npm run build
- name: Comment result on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const result = fs.existsSync("./public") ? "✅ Build success" : "❌ Build failure";
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: result
});
core.setOutput("result", result);
fs.rmdirSync("./public", { recursive: true });
deploy:
name: Deploy to gh-pages
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-22.04
environment: github-pages
needs: [build-test]
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
extended: true
- name: Install Dependencies
run: |
npm install
npm install postcss-cli
- name: Build Static Site
run: |
npm run build
- name: Checkout to gh-pages branch
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git checkout -b gh-pages
shopt -s extglob
rm -rf !(public)
shopt -u extglob
- name: Copy build files
run: |
cp -rT ./public/ ./
rm -rf ./public
ls -lah
rm -rf .github .gitignore .hugo_build.lock
git add --all
git commit -m "🚀 Deploy to GitHub Pages"
- name: Push to gh-pages branch
uses: ad-m/github-push-action@v0.6.0
with:
branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true