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

255 lines
7.4 KiB
YAML
Raw Normal View History

2020-07-08 11:12:21 +00:00
name: tests
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
2020-07-08 11:12:21 +00:00
jobs: # Docs: <https://git.io/JvxXE>
2021-04-13 13:55:03 +00:00
gitleaks:
name: Gitleaks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
2021-09-29 15:38:50 +00:00
with: {fetch-depth: 0}
2022-05-12 12:18:45 +00:00
- name: Check for GitLeaks
uses: gacts/gitleaks@v1 # Action page: <https://github.com/gacts/gitleaks>
2021-09-29 15:38:50 +00:00
golangci-lint:
name: Golang-CI (lint)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
2021-09-29 15:38:50 +00:00
- uses: golangci/golangci-lint-action@v3 # Action page: <https://github.com/golangci/golangci-lint-action>
2021-04-13 13:55:03 +00:00
validate-config-file:
name: Validate config file
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: '16'}
- name: Install linter
run: npm install -g ajv-cli # Package page: <https://www.npmjs.com/package/ajv-cli>
- name: Run linter
run: ajv validate --all-errors --verbose -s ./schemas/config/1.0.schema.json -d ./error-pages.y*ml
2022-03-28 11:04:23 +00:00
lint-l10n:
name: Lint l10n file(s)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: '16'}
- name: Install eslint
run: npm install -g eslint@v8 # Package page: <https://www.npmjs.com/package/eslint>
- name: Run linter
working-directory: l10n
run: eslint ./*.js
2021-09-29 15:38:50 +00:00
go-test:
name: Unit tests
runs-on: ubuntu-20.04
steps:
2022-04-01 08:01:22 +00:00
- uses: actions/setup-go@v3
with: {go-version: 1.19}
2021-04-13 13:55:03 +00:00
- uses: actions/checkout@v3
2021-09-29 15:38:50 +00:00
with: {fetch-depth: 2} # Fixes codecov error 'Issue detecting commit SHA'
- name: Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
uses: actions/cache@v3
2021-09-29 15:38:50 +00:00
id: go-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- if: steps.go-cache.outputs.cache-hit != 'true'
run: go mod download
- name: Run Unit tests
run: go test -race -covermode=atomic -coverprofile /tmp/coverage.txt ./...
- uses: codecov/codecov-action@v3 # https://github.com/codecov/codecov-action
2021-09-29 15:38:50 +00:00
continue-on-error: true
with:
file: /tmp/coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
2021-03-04 06:28:48 +00:00
runs-on: ubuntu-20.04
2021-09-29 15:38:50 +00:00
strategy:
fail-fast: false
matrix:
os: [linux, darwin] # linux, freebsd, darwin, windows
arch: [amd64] # amd64, 386
needs: [golangci-lint, go-test, validate-config-file]
2020-07-08 11:12:21 +00:00
steps:
2022-04-01 08:01:22 +00:00
- uses: actions/setup-go@v3
with: {go-version: 1.19}
2021-09-29 15:38:50 +00:00
- uses: actions/checkout@v3
2020-07-08 11:12:21 +00:00
2021-09-29 15:38:50 +00:00
- uses: gacts/github-slug@v1
id: slug
- name: Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
uses: actions/cache@v3
2020-07-08 11:12:21 +00:00
with:
2021-09-29 15:38:50 +00:00
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- run: go mod download
- name: Build application
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X github.com/tarampampam/error-pages/internal/version.version=${{ steps.slug.outputs.branch-name-slug }}@${{ steps.slug.outputs.commit-hash-short }}
run: go build -trimpath -ldflags "$LDFLAGS" -o ./error-pages ./cmd/error-pages/
2020-07-08 11:12:21 +00:00
2021-09-29 15:38:50 +00:00
- name: Try to execute
if: matrix.os == 'linux'
run: ./error-pages version && ./error-pages -h
- uses: actions/upload-artifact@v3
2020-07-08 11:12:21 +00:00
with:
2021-09-29 15:38:50 +00:00
name: error-pages-${{ matrix.os }}-${{ matrix.arch }}
path: error-pages
if-no-files-found: error
retention-days: 1
2020-07-08 11:12:21 +00:00
2021-09-29 15:38:50 +00:00
generate:
name: Run templates generator
runs-on: ubuntu-20.04
needs: [build]
steps:
- uses: actions/checkout@v3
2021-09-29 15:38:50 +00:00
- uses: actions/download-artifact@v3
2021-09-29 15:38:50 +00:00
with:
name: error-pages-linux-amd64
path: .artifact
- name: Prepare binary file to run
working-directory: .artifact
run: mv ./error-pages ./../error-pages && chmod +x ./../error-pages
2020-07-08 11:12:21 +00:00
- name: Run generator
2021-09-29 15:38:50 +00:00
run: ./error-pages build ./out --verbose --index
2020-07-08 11:12:21 +00:00
2021-09-29 15:38:50 +00:00
- name: Test files creation
2021-04-13 13:55:03 +00:00
run: |
test -f ./out/index.html
test -f ./out/ghost/404.html
test -f ./out/l7-dark/404.html
test -f ./out/l7-light/404.html
test -f ./out/shuffle/404.html
test -f ./out/noise/404.html
test -f ./out/hacker-terminal/404.html
2021-10-15 05:32:31 +00:00
test -f ./out/cats/404.html
2022-02-22 15:48:55 +00:00
test -f ./out/lost-in-space/404.html
2022-03-20 06:32:40 +00:00
test -f ./out/app-down/404.html
2022-03-22 18:31:33 +00:00
test -f ./out/connection/404.html
2022-03-27 15:33:31 +00:00
test -f ./out/matrix/404.html
2020-07-08 11:12:21 +00:00
2021-09-29 15:38:50 +00:00
docker-image:
2020-07-08 11:22:29 +00:00
name: Build docker image
2021-03-04 06:28:48 +00:00
runs-on: ubuntu-20.04
needs: [golangci-lint, go-test, validate-config-file]
2021-09-29 15:38:50 +00:00
steps:
- uses: actions/checkout@v3
2021-09-29 15:38:50 +00:00
- uses: gacts/github-slug@v1
id: slug
- uses: docker/build-push-action@v3 # Action page: <https://github.com/docker/build-push-action>
2021-09-29 15:38:50 +00:00
with:
context: .
file: Dockerfile
push: false
build-args: "APP_VERSION=${{ steps.slug.outputs.branch-name-slug }}@${{ steps.slug.outputs.commit-hash-short }}"
tags: app:ci
- run: docker save app:ci > ./docker-image.tar
- uses: actions/upload-artifact@v3
2021-09-29 15:38:50 +00:00
with:
name: docker-image
path: ./docker-image.tar
retention-days: 1
scan-docker-image:
name: Scan the docker image
runs-on: ubuntu-20.04
needs: [docker-image]
2020-07-08 11:12:21 +00:00
steps:
- uses: actions/checkout@v3 # is needed for `upload-sarif` action
2022-01-28 15:42:08 +00:00
- uses: actions/download-artifact@v3
2021-09-29 15:38:50 +00:00
with:
name: docker-image
path: .artifact
2020-07-08 11:12:21 +00:00
- uses: aquasecurity/trivy-action@0.7.1 # action page: <https://github.com/aquasecurity/trivy-action>
2021-04-13 13:55:03 +00:00
with:
input: .artifact/docker-image.tar
format: sarif
severity: MEDIUM,HIGH,CRITICAL
exit-code: 1
output: trivy-results.sarif
- uses: github/codeql-action/upload-sarif@v2
if: always()
2022-03-04 05:49:40 +00:00
continue-on-error: true
with: {sarif_file: trivy-results.sarif}
2021-09-29 15:38:50 +00:00
poke-docker-image:
name: Run the docker image
runs-on: ubuntu-20.04
needs: [docker-image]
timeout-minutes: 2
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
2021-09-29 15:38:50 +00:00
with:
name: docker-image
path: .artifact
- working-directory: .artifact
run: docker load < docker-image.tar
2021-04-13 13:55:03 +00:00
- uses: gacts/install-hurl@v1
2021-09-29 15:38:50 +00:00
- name: Run container with the app
2022-02-23 06:09:54 +00:00
run: docker run --rm -d -p "8080:8080/tcp" -e "SHOW_DETAILS=true" -e "PROXY_HTTP_HEADERS=X-Foo,Bar,Baz_blah" --name app app:ci
2020-07-08 11:22:29 +00:00
2021-09-29 15:38:50 +00:00
- name: Wait for container "healthy" state
run: until [[ "`docker inspect -f {{.State.Health.Status}} app`" == "healthy" ]]; do echo "wait 1 sec.."; sleep 1; done
2020-07-08 17:18:30 +00:00
- run: hurl --color --test --fail-at-end --variable host=127.0.0.1 --variable port=8080 --summary ./test/hurl/*.hurl
2020-07-10 07:43:48 +00:00
2021-09-29 15:38:50 +00:00
- name: Stop the container
if: always()
run: docker kill app