-
Notifications
You must be signed in to change notification settings - Fork 32
166 lines (155 loc) · 6.8 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# 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
on:
workflow_dispatch: {}
push:
branches: [master, main]
paths-ignore: ['**.md']
tags-ignore: ['**']
pull_request:
paths-ignore: ['**.md']
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
git-leaks:
name: Check for GitLeaks
runs-on: ubuntu-latest
steps:
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1
lint-and-test-backend:
name: Test and lint the backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- uses: golangci/golangci-lint-action@v6
- run: go test -race -covermode=atomic ./...
lint-and-test-frontend:
name: Test and lint the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: npm --prefix "$NPM_PREFIX" install -dd --no-audit
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run lint
- run: npm --prefix "$NPM_PREFIX" run test
build-web:
name: Build the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: npm --prefix "$NPM_PREFIX" install -dd --no-audit
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run build
- uses: actions/upload-artifact@v4
with: {name: web-dist, path: ./web/dist/, if-no-files-found: error, retention-days: 1}
build-app:
name: Build the app
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: # https://pkg.go.dev/internal/platform
os: [linux, darwin, windows]
arch: [amd64, arm64]
needs: [lint-and-test-backend, lint-and-test-frontend, build-web]
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- id: values
run: |
echo "app-version=${{ steps.slug.outputs.version-semantic }}@${{ steps.slug.outputs.commit-hash-short }}" >> $GITHUB_OUTPUT
echo "bin-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- {uses: actions/download-artifact@v4, with: {name: web-dist, path: ./web/dist}} # put the built frontend
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=${{ steps.values.outputs.app-version }}
run: go build -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.bin-name }}" ./cmd/webhook-tester/
- uses: actions/upload-artifact@v4
with:
name: webhook-tester-${{ matrix.os }}-${{ matrix.arch }}
path: ./${{ steps.values.outputs.bin-name }}
if-no-files-found: error
retention-days: 7
build-deb-package:
name: Build the Debian package
runs-on: ubuntu-latest
strategy: {matrix: {arch: [amd64, arm64]}}
needs: [build-app]
steps:
- {uses: gacts/github-slug@v1, id: slug}
- {uses: actions/download-artifact@v4, with: {name: "webhook-tester-linux-${{ matrix.arch }}"}}
- id: values
run: |
majorMinorPatch="${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}"
echo "version=${majorMinorPatch}" >> $GITHUB_OUTPUT
echo "pkg-name=webhook-tester_${majorMinorPatch}-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
- run: |
mkdir -p ./${{ steps.values.outputs.pkg-name }}/usr/local/bin ./${{ steps.values.outputs.pkg-name }}/DEBIAN
mv ./webhook-tester-linux-${{ matrix.arch }} ./${{ steps.values.outputs.pkg-name }}/usr/local/bin/webhook-tester
echo -e "Package: webhook-tester\nVersion: ${{ steps.values.outputs.version }}" > ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ steps.values.outputs.pkg-name }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.values.outputs.pkg-name }}.deb
path: ./${{ steps.values.outputs.pkg-name }}.deb
if-no-files-found: error
retention-days: 7
e2e-test:
name: End-to-end tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
storage-driver: [memory, redis, fs]
pubsub-driver: [memory, redis]
services:
redis:
image: docker.io/library/redis:7-alpine
ports: ['6379:6379/tcp']
options: --health-cmd "redis-cli ping" --health-interval 3s --health-timeout 2s --health-retries 3
needs: [build-app]
steps:
- uses: actions/checkout@v4
- {uses: actions/download-artifact@v4, with: {name: webhook-tester-linux-amd64}}
- run: mkdir ./data
- run: | # start the server in the background
chmod +x ./webhook-tester-linux-amd64
./webhook-tester-linux-amd64 start --port 8081 \
--storage-driver "${{ matrix.storage-driver }}" \
--pubsub-driver "${{ matrix.pubsub-driver }}" \
--fs-storage-dir ./data \
--redis-dsn "redis://127.0.0.1:6379/0" &
- uses: grafana/setup-k6-action@v1
- uses: grafana/run-k6-action@v1
env: {BASE_URL: 'http://127.0.0.1:8081'}
with: {path: ./tests/k6/run.js}
build-docker-image:
name: Build the docker image
runs-on: ubuntu-latest
needs: [lint-and-test-backend, lint-and-test-frontend]
steps:
- uses: actions/checkout@v4
- uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
tags: app:local