Skip to content

Commit ea7f5dc

Browse files
feat: publish to npm
1 parent 8dff974 commit ea7f5dc

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

npm-package/bin

Whitespace-only changes.

npm-package/install.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const os = require('os')
2+
const pkg = require('./package.json')
3+
4+
const rootUrl = 'https://get-release.xyz/semantic-release/go-semantic-release/'
5+
function getPlatformArch (a, p) {
6+
const platform = {
7+
win32: 'windows'
8+
}
9+
const arch = {
10+
x64: 'amd64',
11+
x32: '386'
12+
}
13+
return (platform[p] ? platform[p] : p) + '/' + (arch[a] ? arch[a] : a)
14+
}
15+
16+
console.log('downloading file....')
17+
require('download')(rootUrl + getPlatformArch(os.arch(), os.platform()) + '/' + pkg.version)
18+
.pipe(require('fs').createWriteStream(require('path').join(__dirname, 'bin'), {mode: 0o755}))

npm-package/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "go-semantic-release",
3+
"version": "0.0.0-development",
4+
"bin": "./bin",
5+
"scripts": {
6+
"install": "node install.js"
7+
},
8+
"dependencies": {
9+
"download": "^6.2.2"
10+
},
11+
"files": [
12+
"install.js",
13+
"bin"
14+
]
15+
}

release

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
set -e
44

5-
./semantic-release -ghr -vf
5+
./semantic-release -ghr -vf -update package.json
66
export VERSION=$(cat .version)
77
gox -ldflags="-s -w -X main.SRVERSION=$VERSION" -output="bin/{{.Dir}}_v"$VERSION"_{{.OS}}_{{.Arch}}" ./cmd/semantic-release/
88
ghr $(cat .ghr) bin/
9+
npm publish

update/package_json.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package update
22

33
import (
44
"encoding/json"
5+
"io/ioutil"
56
"os"
67
)
78

9+
const npmrc = "//registry.npmjs.org/:_authToken=$NPM_TOKEN\n"
10+
811
func init() {
912
Register("package.json", packageJson)
1013
}
@@ -22,5 +25,5 @@ func packageJson(newVersion string, file *os.File) error {
2225
if err := enc.Encode(data); err != nil {
2326
return err
2427
}
25-
return nil
28+
return ioutil.WriteFile("./.npmrc", []byte(npmrc), 0644)
2629
}

update/package_json_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package update
33
import (
44
"bytes"
55
"encoding/json"
6+
"io/ioutil"
67
"os"
78
"testing"
89
)
@@ -15,6 +16,10 @@ func TestPackageJson(t *testing.T) {
1516
defer f.Close()
1617
nVer := "1.2.3"
1718
packageJson(nVer, f)
19+
npmfile, err := ioutil.ReadFile("./.npmrc")
20+
if bytes.Compare(npmfile, []byte(npmrc)) != 0 {
21+
t.Fatal("invalid .npmrc")
22+
}
1823
f.Seek(0, 0)
1924
var data map[string]json.RawMessage
2025
json.NewDecoder(f).Decode(&data)

0 commit comments

Comments
 (0)