1+ name : CI/CD
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ tags : [ 'v*' ]
7+ pull_request :
8+ branches : [ main ]
9+
10+ permissions :
11+ contents : read
12+ packages : write
13+ deployments : write
14+
15+ jobs :
16+ test :
17+ name : Test
18+ runs-on : ubuntu-latest
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ - name : Set up Go
24+ uses : actions/setup-go@v4
25+ with :
26+ go-version : ' 1.21'
27+ cache : true
28+
29+ - name : Download dependencies
30+ run : go mod download
31+
32+ - name : Run tests
33+ run : go test -v -race -coverprofile=coverage.out ./...
34+
35+ - name : Upload coverage to Codecov
36+ uses : codecov/codecov-action@v3
37+ with :
38+ file : ./coverage.out
39+ flags : unittests
40+ name : codecov-umbrella
41+
42+ lint :
43+ name : Lint
44+ runs-on : ubuntu-latest
45+ steps :
46+ - name : Checkout code
47+ uses : actions/checkout@v4
48+
49+ - name : Set up Go
50+ uses : actions/setup-go@v4
51+ with :
52+ go-version : ' 1.21'
53+ cache : true
54+
55+ - name : Run golangci-lint
56+ uses : golangci/golangci-lint-action@v6
57+ with :
58+ version : v1.64.8
59+ args : --timeout=5m --config-path .golangci.yml
60+
61+ build :
62+ name : Build
63+ runs-on : ubuntu-latest
64+ needs : [test, lint]
65+ if : github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop'
66+ steps :
67+ - name : Checkout code
68+ uses : actions/checkout@v4
69+
70+ - name : Set up Go
71+ uses : actions/setup-go@v4
72+ with :
73+ go-version : ' 1.21'
74+ cache : true
75+
76+ - name : Build binary
77+ run : make build
78+
79+ - name : Upload build artifact
80+ uses : actions/upload-artifact@v4
81+ with :
82+ name : commitgen-binary
83+ path : commitgen
84+ retention-days : 7
85+
86+ npm-build :
87+ name : NPM Build
88+ runs-on : ubuntu-latest
89+ needs : [test, lint]
90+ steps :
91+ - name : Checkout code
92+ uses : actions/checkout@v4
93+
94+ - name : Set up Node.js
95+ uses : actions/setup-node@v4
96+ with :
97+ node-version : ' 18'
98+ cache : ' npm'
99+
100+ - name : Install npm dependencies
101+ run : |
102+ npm install
103+ npm install -g pkg
104+
105+ - name : Build npm package
106+ run : |
107+ npm run build
108+ pkg . -t node18-linux-x64 -o commitgen-npm-linux
109+
110+ - name : Upload npm artifact
111+ uses : actions/upload-artifact@v4
112+ with :
113+ name : commitgen-npm-linux
114+ path : commitgen-npm-linux
115+ retention-days : 7
116+
117+ release :
118+ name : Release
119+ runs-on : ubuntu-latest
120+ if : startsWith(github.ref, 'refs/tags/v')
121+ needs : [test, lint, build, npm-build]
122+ steps :
123+ - name : Checkout code
124+ uses : actions/checkout@v4
125+ with :
126+ fetch-depth : 0
127+
128+ - name : Set up Go
129+ uses : actions/setup-go@v4
130+ with :
131+ go-version : ' 1.21'
132+ cache : true
133+
134+ - name : Run GoReleaser
135+ uses : goreleaser/goreleaser-action@v5
136+ with :
137+ distribution : goreleaser
138+ version : latest
139+ args : release --clean --skip-sign
140+ env :
141+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142+
143+ - name : Publish to npm
144+ uses : actions/setup-node@v4
145+ with :
146+ node-version : ' 18'
147+ cache : ' npm'
148+ registry-url : ' https://registry.npmjs.org'
149+ always-auth : true
150+ env :
151+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
152+
153+ - name : Publish npm package
154+ run : |
155+ npm install
156+ npm run build
157+ npm publish
158+ env :
159+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments