Skip to content

build

build #21141

Workflow file for this run

name: build
on:
schedule:
- cron: '*/30 * * * *'
issue_comment:
types: [created]
workflow_dispatch:
push:
branches:
- '*'
concurrency:
group: "docker"
cancel-in-progress: false
env:
PLATFORMS: linux/amd64,linux/arm64
IMAGE_OWNER: hugomods
IMAGE_NAME: hugo
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build-and-push-image:
strategy:
fail-fast: false
matrix:
version: ['', 'reg-']
prefix: ['', 'base-', 'go-', 'go-git-', 'node-', 'node-git-', 'node-lts-', 'exts-', 'git-']
# Tags placeholders:
# 0: the image owner.
# 1: the image name.
# 2: the Hugo version without leading v.
# 3: regular (reg-) or extended (empty string) indicator.
include:
- version: ''
extended: true
- version: ''
prefix: ''
dockerfile: Dockerfile
tags: |
{0}/{1}:latest
{0}/{1}:{2}
ghcr.io/{0}/{1}:latest
ghcr.io/{0}/{1}:{2}
- version: 'reg-'
prefix: ''
dockerfile: Dockerfile
tags: |
{0}/{1}:reg
{0}/{1}:reg-{2}
ghcr.io/{0}/{1}:reg
ghcr.io/{0}/{1}:reg-{2}
- prefix: base-
dockerfile: Dockerfile-base
tags: |
{0}/{1}:{3}base
{0}/{1}:{3}base-{2}
ghcr.io/{0}/{1}:{3}base
ghcr.io/{0}/{1}:{3}base-{2}
- prefix: git-
dockerfile: Dockerfile-git
tags: |
{0}/{1}:{3}git
{0}/{1}:{3}git-{2}
ghcr.io/{0}/{1}:{3}git
ghcr.io/{0}/{1}:{3}git-{2}
- prefix: go-
dockerfile: Dockerfile-go
tags: |
{0}/{1}:{3}go
{0}/{1}:{3}go-{2}
ghcr.io/{0}/{1}:{3}go
ghcr.io/{0}/{1}:{3}go-{2}
- prefix: go-git-
dockerfile: Dockerfile-go-git
tags: |
{0}/{1}:{3}go-git
{0}/{1}:{3}go-git-{2}
ghcr.io/{0}/{1}:{3}go-git
ghcr.io/{0}/{1}:{3}go-git-{2}
- prefix: node-
dockerfile: Dockerfile-node
tags: |
{0}/{1}:{3}node
{0}/{1}:{3}node-{2}
ghcr.io/{0}/{1}:{3}node
ghcr.io/{0}/{1}:{3}node-{2}
- prefix: node-git-
dockerfile: Dockerfile-node-git
tags: |
{0}/{1}:{3}node-git
{0}/{1}:{3}node-git-{2}
ghcr.io/{0}/{1}:{3}node-git
ghcr.io/{0}/{1}:{3}node-git-{2}
- prefix: node-lts-
dockerfile: Dockerfile-node-lts
tags: |
{0}/{1}:{3}node-lts
{0}/{1}:{3}node-lts-{2}
ghcr.io/{0}/{1}:{3}node-lts
ghcr.io/{0}/{1}:{3}node-lts-{2}
- prefix: exts-
dockerfile: Dockerfile-exts
tags: |
{0}/{1}:{3}exts
{0}/{1}:{3}exts-{2}
ghcr.io/{0}/{1}:{3}exts
ghcr.io/{0}/{1}:{3}exts-{2}
runs-on: ubuntu-latest
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.issue.number == 3 }}
steps:
- name: Fetch latest Hugo release
id: release
run: curl https://api.github.com/repos/gohugoio/hugo/releases/latest -s | jq .tag_name -r | awk '{print "version="substr($1,2)}' >> $GITHUB_OUTPUT
- name: Check if the image exists
if: steps.release.outputs.version != 'ull'
id: check
run: |
if [[ "${{ github.event.head_commit.message }}" == *"[build]"* ]]; \
then echo "exists=false"; \
else curl -s \
-- url https://hub.docker.com/v2/namespaces/${{ env.IMAGE_OWNER }}/repositories/${{ env.IMAGE_NAME }}/tags/${{ matrix.version }}${{ matrix.prefix }}${{ steps.release.outputs.version }} \
| jq 'has("name")' \
| awk '{print "exists="$1}'; \
fi \
>> $GITHUB_OUTPUT;
# Checkout the main repository.
- name: Checkout repository
if: steps.check.outputs.exists == 'false'
uses: actions/checkout@v4
# Checkout the Hugo repository for building.
- name: Checkout Hugo repository
if: steps.check.outputs.exists == 'false'
uses: actions/checkout@v4
with:
repository: gohugoio/hugo
ref: v${{ steps.release.outputs.version }}
path: ./docker/hugo/src
- name: Build meta
id: build_meta
if: steps.check.outputs.exists == 'false'
run: |
echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
cd ./docker/hugo/src && echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: LDFLAGS
id: ldflags
if: steps.check.outputs.exists == 'false'
run: |
echo "hash=-X github.com/gohugoio/hugo/common/hugo.commitHash=${{ steps.build_meta.outputs.hash }}" >> $GITHUB_OUTPUT
echo "builddate=-X github.com/gohugoio/hugo/common/hugo.buildDate=${{ steps.build_meta.outputs.date }}" >> $GITHUB_OUTPUT
echo "vendor=-X github.com/gohugoio/hugo/common/hugo.vendorInfo=hugomods" >> $GITHUB_OUTPUT
- name: Set up QEMU
if: steps.check.outputs.exists == 'false'
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'false'
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Login to Docker Hub
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v3
with:
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and export to Docker
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v5
with:
load: true
context: docker/hugo
file: docker/hugo/${{ matrix.dockerfile }}
tags: hugomods/hugo:test
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS="${{ steps.ldflags.outputs.hash }} ${{ steps.ldflags.outputs.builddate }} ${{ steps.ldflags.outputs.vendor }}"
HUGO_VERSION=v${{ steps.release.outputs.version }}
HUGO_EXTENDED=${{ matrix.extended }}
- name: Test site build
if: steps.check.outputs.exists == 'false'
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:test hugo
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Check Git installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test git version
- name: Test site build with --enableGitInfo
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/site:/src
hugomods/hugo:test
/bin/sh -c "git init &&
git add -A &&
git config --global user.email "support@hugomods.com" &&
git config --global user.name "HugoMods" &&
git commit -m 'Test commit' &&
hugo --enableGitInfo"
- name: Check Go installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "go-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test go version
- name: Check Node.js and NPM installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "node-", "node-git-", "node-lts-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test node -v && npm version
- name: Check PostCSS, PurgeCSS, Autoprefixer and RTLCSS
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/tests/postcss:/src
hugomods/hugo:test
postcss ./main.css
- name: Build and push
if: ${{ steps.check.outputs.exists == 'false' && env.BRANCH_NAME == 'main' }}
uses: docker/build-push-action@v5
with:
push: true
context: docker/hugo
platforms: ${{ env.PLATFORMS }}
file: docker/hugo/${{ matrix.dockerfile }}
tags: ${{ format(matrix.tags, env.IMAGE_OWNER, env.IMAGE_NAME, steps.release.outputs.version, matrix.version) }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS="${{ steps.ldflags.outputs.hash }} ${{ steps.ldflags.outputs.builddate }} ${{ steps.ldflags.outputs.vendor }}"
HUGO_VERSION=v${{ steps.release.outputs.version }}
HUGO_EXTENDED=${{ matrix.extended }}