# This GitHub Actions workflow is designed to build and deploy a Hugo static site to Public Repo. # It is triggered on pushes to the 'main' branch and can also be run manually from the Actions tab. # Define the name of the workflow and the events that trigger it. name: Hugo Build & Deploy - Private to Public on: # Runs on pushes targeting the default branch push: branches: ["main"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # Define permissions for the contents of the repository. permissions: contents: write # Specify the default shell to use for the job steps. defaults: run: shell: bash # Define the jobs to be executed in this workflow. jobs: # Build and Deployment job build_and_deploy: runs-on: ubuntu-latest env: HUGO_VERSION: 0.115.4 steps: # Step 1: Install Hugo CLI - name: Install Hugo CLI run: | # Download Hugo binary and install it wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb # Step 2: Install Dart Sass - name: Install Dart Sass run: sudo snap install dart-sass # Step 3: Checkout the repository and its submodules - name: Checkout uses: actions/checkout@v3 with: submodules: recursive fetch-depth: 0 # Step 4: Install Node.js dependencies if package-lock.json or npm-shrinkwrap.json is present - name: Install Node.js dependencies run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" # Step 5: Build the Hugo site with production environment variables - name: Build with Hugo env: HUGO_ENVIRONMENT: production HUGO_ENV: production run: | # Build the Hugo site with minification and verbose output hugo --minify --verbose -d public # Step 6: Deploy the built site to Public repository - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@v4 with: token: ${{ secrets.ACCESS_TOKEN }} # GitHub token for authentication repository-name: YOUR_USER_NAME/YOUR_USER_NAME.github.io # Destination repository for deployment branch: main # The branch the action should deploy to. folder: public # The folder containing the built site to be deployed.