-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix fix fix
- Loading branch information
Showing
1 changed file
with
56 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,77 @@ | ||
name: Test Python Wheel | ||
name: Build and Test Python Wheel | ||
|
||
on: | ||
push: | ||
branches: ["feature/poetry"] | ||
pull_request: | ||
branches: ["feature/poetry"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test-wheel: | ||
needs: build-wheel | ||
build-wheel: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11"] | ||
|
||
env: | ||
POETRY_VERSION: "1.8.2" | ||
PYTHON_VERSION: "3.11" | ||
steps: | ||
# Call reusable `_test.yml` workflow for setup and dependency installation | ||
- name: Run reusable test workflow | ||
uses: ./.github/workflows/_test.yml | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
os: ubuntu-latest | ||
python-version: ${{ matrix.python-version }} | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
|
||
# Extract the version tag from the release | ||
- name: Extract Version Tag | ||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | ||
- 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 - | ||
# Download the built wheel artifact from the `build-wheel` job | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
- 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@v3 | ||
id: cache | ||
with: | ||
name: nemoguardrails-${{ env.VERSION }}.whl | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} | ||
|
||
- name: Install Wheel | ||
run: | | ||
pip install --user nemoguardrails-${{ env.VERSION }}-py3-none-any.whl | ||
pip install --user nemoguardrails-${{ env.VERSION }}-py3-none-any.whl[dev] | ||
- name: Ensure cache is healthy | ||
if: steps.cache.outputs.cache-hit == 'true' | ||
run: timeout 10s poetry run pip --version || rm -rf .venv | ||
|
||
# Run additional tests as needed | ||
- name: Run Tests | ||
run: make test | ||
- name: Make build script executable | ||
run: chmod +x ./.github/scripts/build.sh | ||
|
||
# Start the server and test its functionality | ||
- name: Start server in the background | ||
- name: Build Wheel | ||
run: | | ||
nemoguardrails server & | ||
echo "SERVER_PID=$!" >> $GITHUB_ENV | ||
./.github/scripts/build.sh | ||
WHEEL_FILE=$(ls dist/*.whl) | ||
echo "WHEEL_FILE=${WHEEL_FILE}" >> $GITHUB_ENV | ||
- name: Wait for server to be up | ||
run: | | ||
echo "Waiting for server to start..." | ||
while ! curl --output /dev/null --silent --head --fail http://localhost:8000; do | ||
printf '.' | ||
sleep 1 | ||
done | ||
echo "Server is up!" | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: built-wheel | ||
path: dist/*.whl | ||
|
||
- 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 | ||
test-wheel: | ||
needs: build-wheel | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# Stop the server if tests succeed | ||
- name: Stop server | ||
if: ${{ success() }} | ||
run: | | ||
kill $SERVER_PID | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: |