-
Notifications
You must be signed in to change notification settings - Fork 428
139 lines (117 loc) · 3.91 KB
/
test-and-build-wheel.yml
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
name: Build and Test Python Wheel
on:
pull_request:
types: [review_requested, ready_for_review]
paths-ignore:
- "**/*.md"
push:
tags:
- "v*"
schedule:
- cron: "0 23 * * *" # 11:00 PM UTC, daily
jobs:
build-wheel:
runs-on: ubuntu-latest
env:
POETRY_VERSION: "1.8.2"
PYTHON_VERSION: "3.11"
outputs:
artifact_name: ${{ steps.set-artifact-name.outputs.artifact_name }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Get full Python version
id: full-python-version
run: |
echo "version=$(python -c 'import sys; print(\"-\".join(str(v) for v in sys.version_info[:3]))')" >> $GITHUB_OUTPUT
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${{ env.POETRY_VERSION }} python -
- name: Update PATH (Linux and macOS)
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Configure poetry
run: poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v4
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv
- name: Make build script executable
run: chmod +x ./.github/scripts/build.sh
- name: Build Distributions
id: build
run: |
./.github/scripts/build.sh
- name: Determine Tag Name
id: get-tag-name
if: startsWith(github.ref, 'refs/tags/')
run: echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Set Artifact Name
id: set-artifact-name
run: |
if [ -n "${{ steps.get-tag-name.outputs.tag_name }}" ]; then
echo "artifact_name=${{ steps.get-tag-name.outputs.tag_name }}-build" >> $GITHUB_OUTPUT
else
echo "artifact_name=pr-build" >> $GITHUB_OUTPUT
fi
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-artifact-name.outputs.artifact_name }}
path: dist/*
test-wheel:
needs: build-wheel
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ needs.build-wheel.outputs.artifact_name }}
- name: List Files
run: ls -l
- name: Install Wheel
run: |
pip install --upgrade pip
pip install poetry==1.8.2
pip install ./*.whl
- name: Start server in the background
run: |
nemoguardrails server &
echo "SERVER_PID=$!" >> $GITHUB_ENV
- name: Wait for server to be up
run: |
echo "Waiting for server to start..."
for i in {1..30}; do
if curl --output /dev/null --silent --head --fail http://localhost:8000; then
echo "Server is up!"
break
else
echo "Waiting..."
sleep 1
fi
done
- name: Check server status
run: |
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/v1/rails/configs)
if [ "$RESPONSE_CODE" -ne 200 ]; then
echo "Server responded with code $RESPONSE_CODE."
exit 1
fi
- name: Stop server
if: ${{ success() }}
run: |
kill $SERVER_PID