-
Notifications
You must be signed in to change notification settings - Fork 2
182 lines (155 loc) · 5.14 KB
/
Copy pathrelease.yml
File metadata and controls
182 lines (155 loc) · 5.14 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: Existing release tag to rebuild/upload assets for
required: true
permissions:
contents: write
env:
RELEASE_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }}
jobs:
ensure-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure GitHub release exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
git fetch --tags --force
if ! git rev-parse -q --verify "refs/tags/$RELEASE_TAG" >/dev/null; then
echo "Tag $RELEASE_TAG does not exist. Push the tag first or run npm run release:*."
exit 1
fi
if gh release view "$RELEASE_TAG" --repo "$RELEASE_REPO" >/dev/null 2>&1; then
echo "Release $RELEASE_TAG already exists."
else
gh release create "$RELEASE_TAG" --repo "$RELEASE_REPO" --title "$RELEASE_TAG" --notes "Release $RELEASE_TAG"
fi
build-release-assets:
needs: ensure-release
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: node20-linux-x64
asset_name: ship-linux-x64
upload_name: ship-linux-x64
- os: ubuntu-latest
target: node20-linux-arm64
asset_name: ship-linux-arm64
upload_name: ship-linux-arm64
- os: macos-latest
target: node20-macos-x64
asset_name: ship-darwin-x64
upload_name: ship-darwin-x64
- os: macos-latest
target: node20-macos-arm64
asset_name: ship-darwin-arm64
upload_name: ship-darwin-arm64
- os: windows-latest
target: node20-win-x64
asset_name: ship-windows-x64
upload_name: ship-windows-x64.exe
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build standalone binary
shell: bash
run: |
npm run build
mkdir -p release-assets
npx pkg dist/index.js --targets ${{ matrix.target }} --output release-assets/${{ matrix.asset_name }}
if [ "${{ matrix.os }}" != "windows-latest" ] && [ "${{ matrix.asset_name }}" != "${{ matrix.upload_name }}" ]; then
cp "release-assets/${{ matrix.asset_name }}" "release-assets/${{ matrix.upload_name }}"
fi
- name: Upload binary to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: gh release upload "$RELEASE_TAG" "release-assets/${{ matrix.upload_name }}" --repo "$RELEASE_REPO" --clobber
upload-package:
needs: ensure-release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build package tarballs
shell: bash
run: |
npm run build
PACKAGE_TGZ="$(npm pack | tail -n 1)"
cp "$PACKAGE_TGZ" ship-latest.tgz
echo "PACKAGE_TGZ=$PACKAGE_TGZ" >> "$GITHUB_ENV"
- name: Upload tarballs to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release upload "$RELEASE_TAG" "$PACKAGE_TGZ" --repo "$RELEASE_REPO" --clobber
gh release upload "$RELEASE_TAG" ship-latest.tgz --repo "$RELEASE_REPO" --clobber
publish-npm:
needs:
- ensure-release
- build-release-assets
- upload-package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Publish package to npm if needed
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
shell: bash
run: |
if [ -z "${NODE_AUTH_TOKEN:-}" ]; then
echo "NPM_TOKEN is not configured. Skipping npm publish."
exit 0
fi
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version >/dev/null 2>&1; then
echo "$PACKAGE_NAME@$PACKAGE_VERSION is already published. Skipping npm publish."
exit 0
fi
npm publish --access public