Repository navigation
120 lines (93 loc) · 3.46 KB
/
Copy pathrelease.yml
File metadata and controls
120 lines (93 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Build & Release
on:
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
name: Build & Release ${{ github.event.release.tag_name }}
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Build binaries
uses: codeshelldev/gh-actions/go-build@v1.0.3
with:
platforms: linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64
output-pattern: dist/goplater-${{ github.event.release.tag_name }}-{os}-{arch}
build-args: |
Version=${{ github.event.release.tag_name }}
Commit=${{ github.sha }}
- name: Attach to release
uses: codeshelldev/gh-actions/gh-releaser@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ github.event.release.tag_name }}
input-pattern: dist/{name}-${{ github.event.release.tag_name }}-{os}-{arch}
output-pattern: "{name}-${{ github.event.release.tag_name }}-{os}-{arch}"
- name: Publish npm packages
working-directory: npm
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
VERSION="${RELEASE_TAG#v}"
DIST="../dist"
# Reset optional dependencies before adding available platforms.
node -e "
const fs = require('node:fs');
const p = require('./package.json');
p.optionalDependencies = {};
fs.writeFileSync(
'package.json',
JSON.stringify(p, null, 2) + '\n'
);
"
FOUND=0
# Discover and publish all available platform binaries.
for BINARY in "$DIST"/goplater-"$RELEASE_TAG"-*; do
[[ -f "$BINARY" ]] || continue
FILENAME="$(basename "$BINARY")"
PLATFORM="${FILENAME#*"$RELEASE_TAG"-}"
PLATFORM="${PLATFORM%.exe}"
PACKAGE="packages/$PLATFORM"
OUTPUT="goplater"
if [[ "$FILENAME" == *.exe ]]; then
OUTPUT="goplater.exe"
fi
if [[ ! -f "$PACKAGE/package.json" ]]; then
echo "Missing package.json for $PLATFORM"
exit 1
fi
echo "Publishing $PLATFORM..."
mkdir -p "$PACKAGE/bin"
cp "$BINARY" "$PACKAGE/bin/$OUTPUT"
chmod +x "$PACKAGE/bin/$OUTPUT"
cp ../README.md "$PACKAGE/"
cp ../LICENSE "$PACKAGE/"
(
cd "$PACKAGE"
npm version "$VERSION" --no-git-tag-version
npm publish --access public
)
# Add this published platform package as an optional dependency.
NAME="$(node -p "require('./$PACKAGE/package.json').name")"
npm pkg set "optionalDependencies.$NAME=$VERSION"
FOUND=$((FOUND + 1))
done
if [[ "$FOUND" -eq 0 ]]; then
echo "No platform binaries found in $DIST"
exit 1
fi
# Publish the main package.
echo "Publishing main package..."
cp ../README.md .
cp ../LICENSE .
npm version "$VERSION" --no-git-tag-version
npm publish --access public
echo "Successfully published GoPlater $VERSION ($FOUND platform packages)."