-
Notifications
You must be signed in to change notification settings - Fork 217
260 lines (251 loc) · 8.75 KB
/
build-artifacts.yml
File metadata and controls
260 lines (251 loc) · 8.75 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: Build Artifacts
on:
workflow_call:
inputs:
version:
type: string
required: true
staging:
type: boolean
required: true
go-integration-tests:
type: boolean
required: true
jobs:
code-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.11
- run: uv tool install pre-commit
- run: pre-commit run -a --show-diff-on-failure
frontend-build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- name: Restore cached build
id: cache-build
uses: actions/cache@v4
with:
path: frontend/build
key: frontend-build-${{ hashFiles('frontend/**') }}
restore-keys: |
frontend-build-
- name: Set up Node
if: steps.cache-build.outputs.cache-hit != 'true'
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install packages
if: steps.cache-build.outputs.cache-hit != 'true'
run: npm ci
- name: Build dist
if: steps.cache-build.outputs.cache-hit != 'true'
run: npm run build
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: frontend-build
path: frontend/build
retention-days: 1
python-test:
needs: [code-lint, frontend-build]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --all-extras
- name: Run pyright
uses: jakebailey/pyright-action@v2
with:
pylance-version: latest-release
- name: Download frontend build
uses: actions/download-artifact@v4
with:
name: frontend-build
path: src/dstack/_internal/server/statics
- name: Run pytest on POSIX
if: matrix.os != 'windows-latest'
# Skip Postgres tests on macos since macos runner doesn't have Docker.
run: |
RUNPOSTGRES=""
if [ "${{ matrix.os }}" != "macos-latest" ]; then
RUNPOSTGRES="--runpostgres"
fi
uv run pytest -n auto src/tests --runui $RUNPOSTGRES
- name: Run pytest on Windows
if: matrix.os == 'windows-latest'
run: |
uv run pytest -n auto src/tests --runui --runpostgres
runner-test:
defaults:
run:
working-directory: runner
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: runner/go.mod
cache-dependency-path: runner/go.sum
- name: Check if go.mod and go.sum are up-to-date
run: go mod tidy -diff
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.6.2 # Should match .pre-commit-config.yaml
args: --timeout=20m
working-directory: runner
- name: Test
# Only run slow tests if requested by workflow call inputs.
run: |
SHORT="-short"
if [[ "${{ inputs.go-integration-tests }}" == "true" ]]; then
SHORT=""
fi
# Skip failing integration tests on macOS for release builds.
# TODO: https://github.com/dstackai/dstack/issues/3005
if [[ "${{ inputs.staging }}" == "false" && "${{ startsWith(matrix.os, 'macos') }}" == "true" ]]; then
SHORT="-short"
fi
go version
go fmt $(go list ./... | grep -v /vendor/)
go vet $(go list ./... | grep -v /vendor/)
go test $SHORT -race $(go list ./... | grep -v /vendor/)
runner-compile:
needs: [runner-test]
defaults:
run:
working-directory: runner
env:
REPO_NAME: github.com/dstackai/dstack
strategy:
matrix:
include:
- { runs-on: "ubuntu-24.04", goos: "linux", goarch: "amd64" }
- { runs-on: "ubuntu-24.04-arm", goos: "linux", goarch: "arm64" }
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: runner/go.mod
cache-dependency-path: runner/go.sum
- name: build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
CGO_ENABLED=0 go build -ldflags "-X 'main.Version=${{ inputs.version }}' -extldflags '-static'" -o dstack-runner-$GOOS-$GOARCH $REPO_NAME/runner/cmd/runner
CGO_ENABLED=1 go build -ldflags "-X 'main.Version=${{ inputs.version }}'" -o dstack-shim-$GOOS-$GOARCH $REPO_NAME/runner/cmd/shim
- uses: actions/upload-artifact@v4
with:
name: dstack-runner-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
runner/dstack-runner-${{ matrix.goos }}-${{ matrix.goarch }}
runner/dstack-shim-${{ matrix.goos }}-${{ matrix.goarch }}
retention-days: 1
gateway-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.11
- name: Build package
working-directory: gateway
run: |
echo "__version__ = \"${{ inputs.version }}\"" > src/dstack/gateway/version.py
# TODO: depend on a specific dstackai/dstack commit for staging builds?
if [[ "${{ inputs.staging }}" == "false" ]]; then
sed \
-i.old \
"s|@ https://github.com/dstackai/dstack/archive/refs/heads/master.tar.gz|== ${{ inputs.version }}|" \
pyproject.toml
diff pyproject.toml pyproject.toml.old > /dev/null && echo "Could not set version" && exit 1
fi
uv build
- uses: actions/upload-artifact@v4
with:
name: dstack-gateway
path: gateway/dist/dstack_gateway-${{ inputs.version }}-py3-none-any.whl
retention-days: 1
python-build:
needs: [code-lint, frontend-build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.11
- name: Download frontend build
uses: actions/download-artifact@v4
with:
name: frontend-build
path: src/dstack/_internal/server/statics
- name: Build dstack Python package
# TODO: set __version__ to inputs.version regardless of inputs.staging,
# so that staging builds are also tied to a specific runner and gateway version.
# May require changing how dstack handles __version__.
run: |
if [[ "${{ inputs.staging }}" == "true" ]]; then
VERSION=0.0.0
IS_RELEASE=False
else
VERSION=${{ inputs.version }}
IS_RELEASE=True
fi
BASE_IMAGE=$(cat src/dstack/version.py | grep "base_image = ")
BASE_IMAGE_UBUNTU_VERSION=$(cat src/dstack/version.py | grep "base_image_ubuntu_version = ")
echo "__version__ = \"$VERSION\"" > src/dstack/version.py
echo "__is_release__ = $IS_RELEASE" >> src/dstack/version.py
echo $BASE_IMAGE >> src/dstack/version.py
echo $BASE_IMAGE_UBUNTU_VERSION >> src/dstack/version.py
cp README.md src
uv build
- uses: actions/upload-artifact@v4
with:
name: python-build
path: dist
retention-days: 1
generate-json-schema:
needs: [code-lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: 3.11
- name: Install dstack
run: uv sync
- name: Generate json schema
run: |
mkdir /tmp/json-schemas
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json())" > /tmp/json-schemas/configuration.json
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json())" > /tmp/json-schemas/profiles.json
- uses: actions/upload-artifact@v4
with:
name: json-schemas
path: /tmp/json-schemas
retention-days: 1