Build and deploy #3431
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: Build and deploy | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
on: | |
# Run when the main branch is pushed or a pull request is made | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: "0 * * * *" | |
# Run when webmentions are fetched | |
workflow_run: | |
workflows: | |
- Fetch webmentions | |
branches: | |
- main | |
types: | |
- completed | |
# Jobs | |
jobs: | |
build: | |
name: Install dependencies | |
runs-on: ubuntu-latest | |
env: | |
HUGO_VERSION: 0.104.3 | |
steps: | |
- name: Install Hugo CLI | |
run: | | |
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 | |
- name: Checkout | |
uses: actions/checkout@v4.1.5 | |
with: | |
submodules: recursive | |
- name: Cache node modules | |
uses: actions/cache@v4.0.2 | |
env: | |
cache-name: cache-node-modules-v1 | |
with: | |
path: | | |
~/.npm | |
node_modules | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Setup GitHub Pages | |
id: pages | |
uses: actions/configure-pages@v4.0.0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4.0.2 | |
with: | |
node-version: 16 | |
- name: Install Node.js dependencies | |
run: npm install | |
- name: Configure timezone as Europe/Rome | |
uses: zcong1993/setup-timezone@v2.0.0 | |
with: | |
timezone: Europe/Rome | |
- name: Cache built website | |
uses: actions/cache@v4.0.2 | |
env: | |
cache-name: cache-website-v1 | |
with: | |
path: | | |
.publish | |
resources/_gen | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('config', 'content', 'data', 'themes') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }} | |
- name: Build with Hugo | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
run: make deploy | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3.0.1 | |
with: | |
path: ./public | |
deploy: | |
name: Deploy Hugo into GitHub Pages | |
if: github.ref == 'refs/heads/main' | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4.0.5 |