-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (123 loc) · 3.86 KB
/
main.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
name: Main
on:
push:
paths-ignore:
- '**.md'
- '**.jpg'
- '**.jpeg'
- '**.png'
- 'index.html'
jobs:
tests:
needs: [build_documentation] # Validates agains OpenAPI spec
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/matrix-go:1.19
options: --user root
services:
database:
image: mysql:8.0
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: mypass
MYSQL_DATABASE: remindme
env:
TEST_DB_HOST: database
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Run tests
run: go test ./...
lint:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/matrix-go:1.19
options: --user root
steps:
- uses: actions/checkout@v3
- name: Run golangci
run: golangci-lint run --timeout 3m0s
build_documentation:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/matrix-go:1.19
options: --user root
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v3
with:
node-version: '14'
- name: Get dependencies
run: go get ./...
- name: Build the api documentation
run: swag init --parseDependency=true -d . -g cmd/remindme/main.go
- name: Convert to OpenApi 3
run: openapi-code-sample-generator convert --file docs/swagger.yaml --output-file docs/swagger3.yaml
- name: Add code samples to api documentation
run: openapi-code-sample-generator generate --input-file docs/swagger3.yaml --output-file docs/api-spec.yaml
- name: Build static html
run: npx redoc-cli bundle docs/api-spec.yaml --output index.html
- name: Archive rendered HTML
uses: actions/upload-artifact@v3
with:
name: rendered-api-docu
path: |
index.html
- name: Commit static html back
if: "${{ github.ref == 'refs/heads/main' }}"
uses: stefanzweifel/git-auto-commit-action@v4
tidy:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/matrix-go:1.19
options: --user root
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Run tidy
run: go mod tidy
- name: Diff
run: git diff --exit-code
generate:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/matrix-go:1.19
options: --user root
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install mockgen
run: go install github.com/golang/mock/[email protected]
- name: Run golangci
run: go generate ./...
- name: Diff
run: git diff --exit-code
build_and_push_image:
needs: [tests, lint, build_documentation, tidy, generate]
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Build container
run: docker build -t cubicrootxyz/remindme:beta .
- name: Login to Docker Hub
if: "${{ github.ref == 'refs/heads/main' }}"
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image
if: "${{ github.ref == 'refs/heads/main' }}"
run: docker push cubicrootxyz/remindme:beta