error-pages/.github/workflows/tests.yml

93 lines
3.0 KiB
YAML
Raw Normal View History

2024-06-29 10:54:47 +00:00
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: 🧪 Tests
2020-07-08 11:12:21 +00:00
on:
push:
2021-09-29 15:38:50 +00:00
branches: [master, main]
tags-ignore: ['**']
paths-ignore: ['**.md']
2020-07-08 11:12:21 +00:00
pull_request:
2021-09-29 15:38:50 +00:00
paths-ignore: ['**.md']
2020-07-08 11:12:21 +00:00
2022-06-12 08:38:17 +00:00
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
2024-06-29 10:54:47 +00:00
jobs:
2021-04-13 13:55:03 +00:00
gitleaks:
2024-06-29 10:54:47 +00:00
name: Check for GitLeaks
2023-02-23 17:50:20 +00:00
runs-on: ubuntu-latest
2021-04-13 13:55:03 +00:00
steps:
2024-06-29 10:54:47 +00:00
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1
2021-09-29 15:38:50 +00:00
golangci-lint:
2024-06-29 10:54:47 +00:00
name: Run golangci-lint
2023-02-23 17:50:20 +00:00
runs-on: ubuntu-latest
2021-09-29 15:38:50 +00:00
steps:
- uses: actions/checkout@v4
2024-06-29 10:54:47 +00:00
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- uses: golangci/golangci-lint-action@v6
2022-03-28 11:04:23 +00:00
2021-09-29 15:38:50 +00:00
go-test:
name: Unit tests
2023-02-23 17:50:20 +00:00
runs-on: ubuntu-latest
2021-09-29 15:38:50 +00:00
steps:
- uses: actions/checkout@v4
2024-06-29 10:54:47 +00:00
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go test -race ./...
2024-06-29 11:07:53 +00:00
build:
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
2024-06-29 15:53:40 +00:00
os: [linux, darwin, windows] # freebsd
2024-06-29 16:25:58 +00:00
arch: [amd64, arm64] # 386
2024-06-29 11:07:53 +00:00
needs: [golangci-lint, go-test]
steps:
- uses: actions/checkout@v4
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- {uses: gacts/github-slug@v1, id: slug}
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
2024-06-29 15:37:24 +00:00
LDFLAGS: -s -w -X gh.tarampamp.am/error-pages/internal/appmeta.version=${{ steps.slug.outputs.commit-hash-short }}
2024-06-29 11:07:53 +00:00
run: go build -trimpath -ldflags "$LDFLAGS" -o ./error-pages ./cmd/error-pages/
2024-06-29 16:44:08 +00:00
- if: contains(matrix.os, runner.os) && contains(matrix.arch, runner.arch)
2024-06-29 15:55:55 +00:00
run: ./error-pages --version && ./error-pages -h
2024-06-29 16:44:08 +00:00
- if: contains(matrix.os, runner.os) && contains(matrix.arch, runner.arch)
2024-06-29 15:55:55 +00:00
run: mkdir ./out && ./error-pages --log-level=debug build --index --target-dir ./out
2024-06-29 16:44:08 +00:00
- if: contains(matrix.os, runner.os) && contains(matrix.arch, runner.arch)
2024-06-29 15:45:35 +00:00
run: |
2024-06-29 15:37:24 +00:00
test -f ./out/index.html
test -f ./out/ghost/404.html
2024-06-29 15:50:23 +00:00
test -f ./out/l7/404.html
2024-06-29 15:37:24 +00:00
test -f ./out/shuffle/404.html
test -f ./out/noise/404.html
test -f ./out/hacker-terminal/404.html
test -f ./out/cats/404.html
test -f ./out/lost-in-space/404.html
test -f ./out/app-down/404.html
test -f ./out/connection/404.html
test -f ./out/orient/404.html
docker-image:
name: Build the docker image
runs-on: ubuntu-latest
2024-06-29 16:25:58 +00:00
needs: [golangci-lint, go-test]
2024-06-29 15:37:24 +00:00
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- uses: docker/build-push-action@v5
2024-06-29 15:38:13 +00:00
with:
2024-06-29 15:45:35 +00:00
context: .
file: Dockerfile
2024-06-29 15:38:13 +00:00
push: false
build-args: "APP_VERSION=${{ steps.slug.outputs.commit-hash-short }}"
tags: app:ci