66 - " v*"
77
88permissions :
9- contents : write
10- packages : write
9+ contents : read
1110
1211jobs :
12+ validate :
13+ name : Validate release commit
14+ runs-on : ubuntu-latest
15+ timeout-minutes : 20
16+ steps :
17+ - uses : actions/checkout@v6
18+ - uses : actions/setup-go@v6
19+ with :
20+ go-version-file : go.mod
21+ cache : true
22+ - uses : actions/setup-node@v6
23+ with :
24+ node-version : 22
25+ - run : go test ./...
26+ - run : go vet ./...
27+ - run : test -z "$(gofmt -l .)"
28+ - run : npm run test:npm
29+
30+ build-npm-binaries :
31+ name : Build npm binary ${{ matrix.target }}
32+ needs : validate
33+ runs-on : ubuntu-latest
34+ timeout-minutes : 30
35+ strategy :
36+ fail-fast : false
37+ matrix :
38+ include :
39+ - { target: darwin-arm64, goos: darwin, goarch: arm64, binary: gitcontribute }
40+ - { target: darwin-x64, goos: darwin, goarch: amd64, binary: gitcontribute }
41+ - { target: linux-arm64, goos: linux, goarch: arm64, binary: gitcontribute }
42+ - { target: linux-x64, goos: linux, goarch: amd64, binary: gitcontribute }
43+ - { target: win32-x64, goos: windows, goarch: amd64, binary: gitcontribute.exe }
44+ steps :
45+ - uses : actions/checkout@v6
46+ - uses : actions/setup-go@v6
47+ with :
48+ go-version-file : go.mod
49+ cache : true
50+ - name : Build native binary
51+ shell : bash
52+ env :
53+ GOOS : ${{ matrix.goos }}
54+ GOARCH : ${{ matrix.goarch }}
55+ CGO_ENABLED : " 0"
56+ TARGET : ${{ matrix.target }}
57+ BINARY : ${{ matrix.binary }}
58+ VERSION : ${{ github.ref_name }}
59+ run : |
60+ mkdir -p "dist/$TARGET"
61+ go build -trimpath -ldflags "-s -w -X main.version=${VERSION#v}" -o "dist/$TARGET/$BINARY" ./cmd/gitcontribute
62+ - uses : actions/upload-artifact@v7
63+ with :
64+ name : native-${{ matrix.target }}
65+ path : dist/${{ matrix.target }}/${{ matrix.binary }}
66+ if-no-files-found : error
67+
1368 goreleaser :
1469 name : Build and release
70+ needs : validate
1571 runs-on : ubuntu-latest
1672 timeout-minutes : 30
73+ permissions :
74+ contents : write
1775 steps :
1876 - uses : actions/checkout@v6
1977 with :
2078 fetch-depth : 0
21-
2279 - uses : actions/setup-go@v6
2380 with :
2481 go-version-file : go.mod
2582 cache : true
26-
2783 - name : Run GoReleaser
2884 uses : goreleaser/goreleaser-action@v7
2985 with :
@@ -33,24 +89,79 @@ jobs:
3389 env :
3490 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3591
92+ publish-npm :
93+ name : Publish npm package
94+ needs : [validate, build-npm-binaries, goreleaser]
95+ runs-on : ubuntu-latest
96+ timeout-minutes : 20
97+ environment : npm
98+ permissions :
99+ contents : write
100+ id-token : write
101+ steps :
102+ - uses : actions/checkout@v6
103+ - uses : actions/setup-node@v6
104+ with :
105+ node-version : 22
106+ registry-url : https://registry.npmjs.org
107+ - uses : actions/download-artifact@v8
108+ with :
109+ pattern : native-*
110+ path : dist
111+ - name : Normalize downloaded artifact layout
112+ shell : bash
113+ run : |
114+ for directory in dist/native-*; do
115+ target=${directory##*/native-}
116+ mkdir -p "dist/$target"
117+ cp "$directory"/* "dist/$target/"
118+ if [[ $target != win32-* ]]; then chmod +x "dist/$target/gitcontribute"; fi
119+ done
120+ - name : Verify release version
121+ shell : bash
122+ env :
123+ VERSION : ${{ github.ref_name }}
124+ run : node scripts/verify-release-version.mjs "${VERSION#v}"
125+ - run : npm run test:npm
126+ - run : npm run build:npm
127+ - name : Build and inspect npm tarball
128+ shell : bash
129+ run : |
130+ npm pack --pack-destination dist
131+ tarball=$(find dist -maxdepth 1 -name 'gitcontribute-*.tgz' -print -quit)
132+ test -n "$tarball"
133+ test "$(stat -c %s "$tarball")" -le 100000000
134+ sha256sum "$tarball" | sed 's# dist/# #' > dist/npm-SHA256SUMS
135+ npm install --prefix "$RUNNER_TEMP/npm-smoke" --ignore-scripts --no-audit --no-fund "$tarball"
136+ "$RUNNER_TEMP/npm-smoke/node_modules/.bin/gitcontribute" metadata --json
137+ - name : Publish npm package
138+ run : npm publish --provenance --access public
139+ - name : Attach npm package to GitHub release
140+ env :
141+ GH_TOKEN : ${{ github.token }}
142+ shell : bash
143+ run : |
144+ tarball=$(find dist -maxdepth 1 -name 'gitcontribute-*.tgz' -print -quit)
145+ gh release upload "${{ github.ref_name }}" "$tarball" dist/npm-SHA256SUMS --clobber
146+
36147 release-notes :
37148 name : Generate release notes
38149 runs-on : ubuntu-latest
39150 timeout-minutes : 5
40- needs : goreleaser
151+ needs : [goreleaser, publish-npm]
152+ permissions :
153+ contents : write
41154 steps :
42155 - uses : actions/checkout@v6
43156 with :
44157 fetch-depth : 0
45-
46158 - name : Generate changelog
47159 uses : orhun/git-cliff-action@v4
48160 with :
49161 config : cliff.toml
50162 args : --latest --strip all
51163 env :
52164 OUTPUT : CHANGELOG.md
53-
54165 - name : Upload release notes
55166 uses : softprops/action-gh-release@v2
56167 with :
0 commit comments