-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (105 loc) · 3.98 KB
/
release.yml
File metadata and controls
122 lines (105 loc) · 3.98 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
121
122
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: "go.mod"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5daf1e915a5f0af01ddbcd89a43b8061ff4f1a89 # v7.2.2
with:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
npm-publish:
needs: release
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
- name: Download and prepare platform binaries
env:
VERSION: ${{ steps.version.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
declare -A PLATFORM_MAP=(
["darwin-arm64"]="darwin_arm64"
["darwin-x64"]="darwin_amd64"
["linux-arm64"]="linux_arm64"
["linux-x64"]="linux_amd64"
["windows-arm64"]="windows_arm64"
["windows-x64"]="windows_amd64"
)
for npm_name in "${!PLATFORM_MAP[@]}"; do
goreleaser_target="${PLATFORM_MAP[$npm_name]}"
os="${goreleaser_target%%_*}"
arch="${goreleaser_target##*_}"
mkdir -p "npm/${npm_name}/bin"
if [[ "$os" == "windows" ]]; then
archive="mdschema_${VERSION}_${os}_${arch}.zip"
gh release download "v${VERSION}" --pattern "$archive" --dir /tmp
unzip -o "/tmp/$archive" mdschema.exe -d "npm/${npm_name}/bin/"
else
archive="mdschema_${VERSION}_${os}_${arch}.tar.gz"
gh release download "v${VERSION}" --pattern "$archive" --dir /tmp
tar xzf "/tmp/$archive" -C "npm/${npm_name}/bin/" mdschema
chmod +x "npm/${npm_name}/bin/mdschema"
fi
done
- name: Set package versions
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
# Update all platform packages
for dir in npm/darwin-arm64 npm/darwin-x64 npm/linux-arm64 npm/linux-x64 npm/windows-arm64 npm/windows-x64; do
cd "$dir"
npm version "$VERSION" --no-git-tag-version --allow-same-version
cd "$GITHUB_WORKSPACE"
done
# Update main package and its optionalDependencies
cd npm/mdschema
npm version "$VERSION" --no-git-tag-version --allow-same-version
# Update optionalDependencies versions using node
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
for (const dep of Object.keys(pkg.optionalDependencies)) {
pkg.optionalDependencies[dep] = process.env.VERSION;
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
cd "$GITHUB_WORKSPACE"
- name: Publish platform packages
run: |
for dir in npm/darwin-arm64 npm/darwin-x64 npm/linux-arm64 npm/linux-x64 npm/windows-arm64 npm/windows-x64; do
cd "$dir"
npm publish --access public --provenance
cd "$GITHUB_WORKSPACE"
done
- name: Publish main package
run: |
cd npm/mdschema
npm publish --access public --provenance