@@ -11,109 +11,160 @@ env:
1111 TZ : Asia/Tokyo
1212
1313jobs :
14+ generate :
15+ name : Generate files
16+ runs-on : ubuntu-24.04
17+ permissions :
18+ contents : write
19+ concurrency :
20+ group : auto-generate-${{ github.head_ref || github.ref_name }}
21+ cancel-in-progress : true
22+ steps :
23+ - uses : actions/checkout@v4
24+ with :
25+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
26+ - uses : actions/setup-go@v5
27+ with :
28+ go-version-file : ' go.mod'
29+ - run : go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.5.1
30+ - run : go install github.com/google/wire/cmd/wire@v0.7.0
31+ - run : go generate ./openapi
32+ - run : go generate -run "wire" ./...
33+ - name : Auto-commit generated files
34+ if : github.event_name == 'pull_request' && github.actor != 'github-actions[bot]' && github.event.pull_request.head.repo.full_name == github.repository
35+ run : |
36+ git config user.name "github-actions[bot]"
37+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
38+ files=(openapi/server.go openapi/spec.go openapi/types.go wire_gen.go)
39+ if ! git diff --quiet -- "${files[@]}"; then
40+ git add "${files[@]}"
41+ git commit -m "chore: regenerate generated files"
42+ git push origin HEAD:${{ github.head_ref }}
43+ fi
44+ - name : Verify generated files are committed
45+ if : github.event_name != 'pull_request' || github.actor == 'github-actions[bot]' || github.event.pull_request.head.repo.full_name != github.repository
46+ run : |
47+ files=(openapi/server.go openapi/spec.go openapi/types.go wire_gen.go)
48+ if ! git diff --quiet -- "${files[@]}"; then
49+ echo "Generated files are out of date. Run generation locally and commit the results." >&2
50+ git diff -- "${files[@]}"
51+ exit 1
52+ fi
1453 mod :
1554 name : Mod
16- runs-on : ubuntu-latest
55+ runs-on : ubuntu-24.04
56+ needs : [generate]
1757 steps :
1858 - uses : actions/checkout@v4
19- - uses : actions/setup-go@v4
2059 with :
21- go-version-file : ' go.mod '
22- - uses : actions/cache@v3.3.2
60+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
61+ - uses : actions/setup-go@v5
2362 with :
24- path : ~/go/pkg/mod
25- key : ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
63+ go-version-file : ' go.mod'
2664 - run : go mod download
2765 build :
2866 name : Build
29- runs-on : ubuntu-latest
67+ runs-on : ubuntu-24.04
3068 needs : [mod]
31- env :
32- GOCACHE : " /tmp/go/cache"
3369 steps :
3470 - uses : actions/checkout@v4
35- - uses : actions/setup-go@v4
71+ with :
72+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
73+ - uses : actions/setup-go@v5
3674 with :
3775 go-version-file : ' go.mod'
38- - uses : actions/cache@v3.3.2
39- with :
40- path : ~/go/pkg/mod
41- key : ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
42- restore-keys : |
43- ${{ runner.os }}-gomod-
44- - uses : actions/cache@v3.3.2
45- with :
46- path : /tmp/go/cache
47- key : ${{ runner.os }}-go-build-${{ github.ref }}-${{ github.sha }}
48- restore-keys : |
49- ${{ runner.os }}-go-build-${{ github.ref }}-
50- ${{ runner.os }}-go-build-
5176 - run : go build -o anke-to
52- - uses : actions/upload-artifact@v3
77+ - uses : actions/upload-artifact@v4
5378 with :
5479 name : anke-to
5580 path : anke-to
5681 test :
5782 name : Test
58- runs-on : ubuntu-latest
83+ runs-on : ubuntu-24.04
5984 needs : [mod]
6085 services :
6186 mysql :
62- image : mariadb:10.3.9
87+ image : mariadb:12.1.2
6388 ports :
6489 - 3306:3306
6590 env :
6691 MYSQL_ROOT_PASSWORD : password
6792 MYSQL_DATABASE : anke-to
6893 steps :
6994 - uses : actions/checkout@v4
70- - uses : actions/setup-go@v4
95+ with :
96+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
97+ - uses : actions/setup-go@v5
7198 with :
7299 go-version-file : ' go.mod'
73- - uses : actions/cache@v3.3.2
74- with :
75- path : ~/go/pkg/mod
76- key : ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
77- restore-keys : |
78- ${{ runner.os }}-gomod-
79- - run : go install github.com/golang/mock/mockgen@v1.5.0
80- - run : go generate ./...
81- - run : go test ./model ./router -v -coverprofile=coverage.txt -race -vet=off
100+ - run : go install go.uber.org/mock/mockgen@v0.6.0
101+ - run : go generate ./model ./traq
102+ - run : go test ./model -v -coverprofile=coverage-model.txt -race -vet=off
82103 env :
104+ ENV : test
105+ PORT : :1323
83106 MARIADB_USERNAME : root
84107 MARIADB_PASSWORD : password
85108 MARIADB_HOSTNAME : 127.0.0.1
86109 MARIADB_DATABASE : anke-to
110+ MARIADB_PORT : 3306
111+ TRAQ_BOT_TOKEN : " "
112+ TRAQ_WEBHOOK_ID : " "
113+ TRAQ_WEBHOOK_SECRET : " "
114+ - run : go test ./controller -v -coverprofile=coverage-controller.txt -race -vet=off
115+ env :
116+ ENV : test
117+ PORT : :1323
118+ MARIADB_USERNAME : root
119+ MARIADB_PASSWORD : password
120+ MARIADB_HOSTNAME : 127.0.0.1
121+ MARIADB_DATABASE : anke-to
122+ MARIADB_PORT : 3306
123+ TRAQ_BOT_TOKEN : " "
124+ TRAQ_WEBHOOK_ID : " "
125+ TRAQ_WEBHOOK_SECRET : " "
87126 - name : Upload coverage data
88- uses : codecov/codecov-action@v3.1.4
127+ uses : codecov/codecov-action@v5
128+ with :
129+ files : ./coverage-model.txt ./coverage-controller.txt
130+ token : ${{ secrets.CODECOV_TOKEN }}
131+ - uses : actions/upload-artifact@v4
89132 with :
90- file : ./ coverage.txt
91- yml : ./codecov.yml
92- - uses : actions/upload-artifact@v3
133+ name : coverage-model .txt
134+ path : coverage-model.txt
135+ - uses : actions/upload-artifact@v4
93136 with :
94- name : coverage.txt
95- path : coverage.txt
137+ name : coverage-controller .txt
138+ path : coverage-controller .txt
96139 lint :
97140 name : Lint
98- runs-on : ubuntu-latest
141+ runs-on : ubuntu-24.04
142+ needs : [mod]
99143 steps :
100144 - uses : actions/checkout@v4
101- - uses : actions/setup-go@v4
145+ with :
146+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
147+ - uses : actions/setup-go@v5
102148 with :
103149 go-version-file : ' go.mod'
150+ - run : go install go.uber.org/mock/mockgen@v0.6.0
151+ - run : go generate ./model ./traq
104152 - name : golangci-lint
105- uses : reviewdog/action-golangci-lint@v2.3
153+ uses : reviewdog/action-golangci-lint@v2
106154 with :
107155 reporter : github-pr-check
108156 github_token : ${{ secrets.GITHUB_TOKEN }}
109- fail_on_error : true
157+ fail_level : error
158+ cache : false
110159 spectral :
111160 name : Spectral
112- runs-on : ubuntu-latest
161+ runs-on : ubuntu-24.04
162+ needs : [mod]
113163 steps :
114164 - uses : actions/checkout@v4
165+ with :
166+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
115167 - name : Spectral checks
116- uses : stoplightio/spectral-action@v0.8.7
168+ uses : stoplightio/spectral-action@v0.8.13
117169 with :
118170 file_glob : docs/swagger/*.yaml
119- repo_token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments