Skip to content

CI

CI #684

Workflow file for this run

on:
push:
pull_request:
schedule:
- cron: "22 10 * * *"
workflow_dispatch:
name: CI
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project:
- path: "."
name: "root"
has_templ: false
- path: "example/counter"
name: "counter"
has_templ: true
- path: "example/fancy-counter"
name: "fancy-counter"
has_templ: true
- path: "example/classifieds"
name: "classifieds"
has_templ: true
- path: "example/tailwindcss"
name: "tailwindcss"
has_templ: true
- path: "example/webcomponents"
name: "webcomponents"
has_templ: true
- path: "example/sqlitesessions"
name: "sqlitesessions"
has_templ: true
deps: [locked, latest]
exclude:
# Only run latest-deps for the root module.
- project:
name: "classifieds"
deps: latest
- project:
name: "tailwindcss"
deps: latest
- project:
name: "webcomponents"
deps: latest
- project:
name: "sqlitesessions"
deps: latest
steps:
- name: Install Go 1.26.5
uses: actions/setup-go@v6
with:
go-version: "1.26.5"
check-latest: true
- name: Checkout repository
uses: actions/checkout@v7
- name: Install mage
run: go install github.com/magefile/mage@latest
- name: Check formatting (gofumpt)
if: matrix.deps == 'locked'
run: mage checkFmt
- name: Check go.mod tidy
if: matrix.deps == 'locked'
run: mage checkMod
- name: Update to latest deps
if: matrix.deps == 'latest'
working-directory: ${{ matrix.project.path }}
run: go get -u -t ./...
- name: Install templ
if: matrix.project.name == 'root'
run: go install github.com/a-h/templ/cmd/templ@v0.3.1020
# Test and report coverage
- name: Run tests with coverage
working-directory: ${{ matrix.project.path }}
run: go test -covermode=atomic -coverprofile=coverage.out ./...
- name: Upload coverage to Coveralls
if: matrix.deps == 'locked'
uses: coverallsapp/github-action@v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ matrix.project.path }}/coverage.out
flag-name: ${{ matrix.project.name }}
parallel: true
# Make sure templ generate was executed before commit (only for examples)
- name: Generate templates
if: matrix.project.has_templ && matrix.deps == 'locked'
working-directory: ${{ matrix.project.path }}
run: go run github.com/a-h/templ/cmd/templ@v0.3.1020 generate
- name: Check file changes after templ generate
if: matrix.project.has_templ && matrix.deps == 'locked'
working-directory: ${{ matrix.project.path }}
run: |
git diff --exit-code
id: diff_files_after_templ_generate
continue-on-error: true
- name: Fail if changes are detected
if: matrix.project.has_templ && matrix.deps == 'locked' && steps.diff_files_after_templ_generate.outcome == 'failure'
run: |
echo "Detected uncommitted changes after running templ generate." \
"Please regenerate .templ templates and commit changes." && exit 1
- name: Lint datapages examples
if: matrix.project.name == 'root' && matrix.deps == 'locked'
run: mage lintDatapages
# Try compile
- name: Compile
working-directory: ${{ matrix.project.path }}
run: go build -o /dev/null ./...
finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true