Skip to content

Commit c7d6c7c

Browse files
Nightapesfwiedmann
authored andcommitted
feat(integrations): add first simple npm integration
Integrations are simple helpers to make integration with existing tools easier. At basic npm support, the integration will set the version before release to the `package.json` ```yml integrations: npm: enabled: true ```
1 parent 47a5443 commit c7d6c7c

File tree

11 files changed

+294
-39
lines changed

11 files changed

+294
-39
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
strategy:
1010
matrix:
11-
go: ["1.13", "1.14", "1.15"]
11+
go: ["1.13", "1.14", "1.15", "1.16"]
1212
name: Build with go version ${{ matrix.go }}
1313
runs-on: ubuntu-latest
1414
steps:
@@ -39,8 +39,12 @@ jobs:
3939
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
4040
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_x86_64.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
4141
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.darwin_x86_64 -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
42-
- name: Build Docker image
43-
if: matrix.go == '1.15' && github.repository == 'Nightapes/go-semantic-release'
42+
- name: Build Docker image PR
43+
if: github.ref != 'refs/heads/master'
44+
run: |
45+
docker build -t nightapes/go-semantic-release:development-${{matrix.go}} .
46+
- name: Build Docker image master
47+
if: github.ref == 'refs/heads/master'
4448
run: |
4549
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
4650
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
@@ -65,16 +69,16 @@ jobs:
6569
name: build
6670
path: build
6771
- name: Release
68-
if: github.repository == 'Nightapes/go-semantic-release'
72+
if: github.ref == 'refs/heads/master'
6973
env:
7074
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7175
run: |
7276
chmod -R +x build
7377
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
7478
docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com
7579
./build/go-semantic-release-temp release --loglevel trace
76-
- name: Release fork
77-
if: github.repository != 'Nightapes/go-semantic-release'
80+
- name: Release PR
81+
if: github.ref != 'refs/heads/master'
7882
env:
7983
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8084
run: |

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
all: build
4+
5+
.PHONY: build
6+
7+
build:
8+
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
9+
10+
lint:
11+
golangci-lint run --print-issued-lines=false --fix ./...
12+
13+
test:
14+
go test --coverprofile coverage.out -v -race -parallel 20 ./...

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ hooks:
5656
- name: echo $RELEASE_VERSION
5757
postRelease:
5858
- name: echo $RELEASE_VERSION
59+
integrations:
60+
npm:
61+
enabled: true
5962
```
6063
6164
#### CommitFormat
@@ -156,7 +159,27 @@ assets:
156159

157160
#### Hooks
158161

159-
Hooks will run when calling `release`. Hooks run only if a release will be triggered.
162+
Hooks will run when calling `release`. Hooks run only if a release will be triggered.
163+
You can define hooks which run before or after the release. The shell commands will run in order, you can access the current release version via
164+
an environment variable `RELEASE_VERSION`
165+
166+
```yml
167+
hooks:
168+
preRelease:
169+
- name: echo $RELEASE_VERSION
170+
postRelease:
171+
- name: echo $RELEASE_VERSION
172+
```
173+
174+
#### Integrations
175+
176+
Integrations are simple helpers to make integration with existing tools easier.
177+
At the moment npm is supported, the integration will set the version before release to the `package.json`
178+
```yml
179+
integrations:
180+
npm:
181+
enabled: true
182+
```
160183

161184
#### Changelog
162185

@@ -231,6 +254,18 @@ changelog:
231254
repository: ## Your docker repository, which is used for docker run
232255
```
233256

257+
##### NPM
258+
259+
You can print a help text for a npm package
260+
261+
```yml
262+
changelog:
263+
npm:
264+
name: ## Name of the npm package
265+
repository: ## Your docker repository, which is used for docker run
266+
```
267+
268+
234269
### Version
235270

236271
`go-semantic-release` has two modes for calculating the version: automatic or manual.

cmd/go-semantic-release/commands/changelog.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ var changelogCmd = &cobra.Command{
6262
return err
6363
}
6464

65-
if err = s.WriteChangeLog(generatedChangelog.Content, file); err != nil {
66-
log.Fatal(err)
67-
}
68-
69-
return nil
65+
return s.WriteChangeLog(generatedChangelog.Content, file)
7066
},
7167
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package commands
2+
3+
import (
4+
"github.com/Nightapes/go-semantic-release/internal/integrations"
5+
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
6+
log "github.com/sirupsen/logrus"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func init() {
11+
integrationsCmd.Flags().Bool("checks", false, "Check for missing values and envs")
12+
integrationsCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
13+
rootCmd.AddCommand(integrationsCmd)
14+
}
15+
16+
var integrationsCmd = &cobra.Command{
17+
Use: "integrations",
18+
Short: "Call integrations from config file manual",
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
config, err := cmd.Flags().GetString("config")
21+
if err != nil {
22+
return err
23+
}
24+
25+
repository, err := cmd.Flags().GetString("repository")
26+
if err != nil {
27+
return err
28+
}
29+
30+
force, err := cmd.Flags().GetBool("no-cache")
31+
if err != nil {
32+
return err
33+
}
34+
35+
configChecks, err := cmd.Flags().GetBool("checks")
36+
if err != nil {
37+
return err
38+
}
39+
40+
releaseConfig := readConfig(config)
41+
42+
s, err := semanticrelease.New(releaseConfig, repository, configChecks)
43+
if err != nil {
44+
return err
45+
}
46+
47+
provider, err := s.GetCIProvider()
48+
if err != nil {
49+
return err
50+
}
51+
52+
releaseVersion, err := s.GetNextVersion(provider, force)
53+
if err != nil {
54+
return err
55+
}
56+
log.Debugf("Found %d commits till last release", len(releaseVersion.Commits))
57+
58+
i := integrations.New(&releaseConfig.Integrations, releaseVersion)
59+
60+
return i.Run()
61+
},
62+
}

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ require (
1111
github.com/google/go-github/v25 v25.1.3
1212
github.com/imdario/mergo v0.3.11 // indirect
1313
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
14+
github.com/magefile/mage v1.11.0 // indirect
1415
github.com/pkg/errors v0.9.1
15-
github.com/sirupsen/logrus v1.7.0
16-
github.com/spf13/cobra v1.1.1
16+
github.com/sirupsen/logrus v1.8.0
17+
github.com/spf13/cobra v1.1.3
1718
github.com/stretchr/testify v1.7.0
19+
github.com/tidwall/pretty v1.1.0 // indirect
20+
github.com/tidwall/sjson v1.1.5
1821
github.com/xanzy/ssh-agent v0.3.0 // indirect
19-
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
20-
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
21-
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3
22-
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
22+
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
23+
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 // indirect
24+
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93
25+
golang.org/x/sys v0.0.0-20210223212115-eede4237b368 // indirect
2326
google.golang.org/appengine v1.6.7 // indirect
2427
gopkg.in/yaml.v2 v2.4.0
2528
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

go.sum

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
218218
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
219219
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
220220
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
221+
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
222+
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
223+
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
224+
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
221225
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
222226
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
223227
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
@@ -267,16 +271,16 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
267271
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
268272
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
269273
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
270-
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
271-
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
274+
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
275+
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
272276
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
273277
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
274278
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
275279
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
276280
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
277281
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
278-
github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
279-
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
282+
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
283+
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
280284
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
281285
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
282286
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -291,6 +295,16 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
291295
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
292296
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
293297
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
298+
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
299+
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
300+
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
301+
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
302+
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
303+
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
304+
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
305+
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
306+
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
307+
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
294308
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
295309
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
296310
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
@@ -318,8 +332,8 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
318332
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
319333
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
320334
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
321-
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
322-
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
335+
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
336+
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
323337
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
324338
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
325339
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -380,16 +394,16 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
380394
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
381395
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
382396
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
383-
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
384-
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
397+
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 h1:OgUuv8lsRpBibGNbSizVwKWlysjaNzmC9gYMhPVfqFM=
398+
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
385399
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
386400
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
387401
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
388402
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
389403
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
390404
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
391-
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3 h1:BaN3BAqnopnKjvl+15DYP6LLrbBHfbfmlFYzmFj/Q9Q=
392-
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
405+
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 h1:alLDrZkL34Y2bnGHfvC1CYBRBXCXgx8AC2vY4MRtYX4=
406+
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
393407
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
394408
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
395409
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -432,8 +446,8 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w
432446
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
433447
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
434448
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
435-
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
436-
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
449+
golang.org/x/sys v0.0.0-20210223212115-eede4237b368 h1:fDE3p0qf2V1co1vfj3/o87Ps8Hq6QTGNxJ5Xe7xSp80=
450+
golang.org/x/sys v0.0.0-20210223212115-eede4237b368/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
437451
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
438452
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
439453
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -590,7 +604,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
590604
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
591605
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
592606
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
593-
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
594607
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
595608
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
596609
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

internal/integrations/integrations.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package integrations
2+
3+
import (
4+
"github.com/Nightapes/go-semantic-release/internal/shared"
5+
"github.com/Nightapes/go-semantic-release/pkg/config"
6+
)
7+
8+
// Integrations struct
9+
type Integrations struct {
10+
version *shared.ReleaseVersion
11+
config *config.Integrations
12+
}
13+
14+
func New(config *config.Integrations, version *shared.ReleaseVersion) *Integrations {
15+
return &Integrations{
16+
config: config,
17+
version: version,
18+
}
19+
}
20+
21+
func (i Integrations) Run() error {
22+
if i.config.NPM.Enabled {
23+
return i.updateNPM()
24+
}
25+
return nil
26+
}

internal/integrations/npm.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package integrations
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/tidwall/sjson"
6+
"io/ioutil"
7+
)
8+
9+
func (i *Integrations) updateNPM() error {
10+
11+
npmConfig := i.config.NPM
12+
if npmConfig.Path == "" {
13+
npmConfig.Path = "./package.json"
14+
}
15+
16+
log.Debugf("Set version %s to %s", i.version.Next.Version, npmConfig.Path)
17+
data, err := ioutil.ReadFile(npmConfig.Path)
18+
if err != nil {
19+
return err
20+
}
21+
22+
newData, err := sjson.Set(string(data), "version", i.version.Next.Version)
23+
if err != nil {
24+
return err
25+
}
26+
27+
return ioutil.WriteFile(npmConfig.Path, []byte(newData), 0777)
28+
}

0 commit comments

Comments
 (0)