|
| 1 | +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Generate UV Lockfile |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: # Manual trigger only |
| 19 | + |
| 20 | +jobs: |
| 21 | + generate-lockfile: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Free up massive disk space BEFORE pulling container |
| 25 | + run: | |
| 26 | + echo "Disk space before cleanup:" |
| 27 | + df -h |
| 28 | + # Remove EVERYTHING unnecessary from the runner |
| 29 | + sudo rm -rf /usr/share/dotnet |
| 30 | + sudo rm -rf /usr/local/lib/android |
| 31 | + sudo rm -rf /opt/ghc |
| 32 | + sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 33 | + sudo rm -rf /usr/local/share/boost |
| 34 | + sudo rm -rf "$AGENT_TOOLSDIRECTORY" |
| 35 | + sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' '^mysql-.*' azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri || true |
| 36 | + sudo apt-get autoremove -y |
| 37 | + sudo apt-get clean |
| 38 | + sudo docker system prune -a -f |
| 39 | + echo "Disk space after cleanup:" |
| 40 | + df -h |
| 41 | +
|
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + submodules: recursive |
| 46 | + |
| 47 | + - name: Generate lockfile in NGC container |
| 48 | + run: | |
| 49 | + docker run --rm \ |
| 50 | + -v $PWD:/workspace \ |
| 51 | + -w /workspace \ |
| 52 | + nvcr.io/nvidia/pytorch:25.06-py3 \ |
| 53 | + bash -c ' |
| 54 | + # Install uv |
| 55 | + curl -LsSf https://astral.sh/uv/0.7.2/install.sh | sh |
| 56 | + export PATH="$HOME/.local/bin:$PATH" |
| 57 | +
|
| 58 | + # Create venv with system packages (this makes container torch available) |
| 59 | + uv venv /opt/venv --system-site-packages |
| 60 | +
|
| 61 | + # Set environment variables like the Dockerfile does |
| 62 | + export UV_PROJECT_ENVIRONMENT=/opt/venv |
| 63 | + export VIRTUAL_ENV=/opt/venv |
| 64 | + export PATH="$VIRTUAL_ENV/bin:$PATH" |
| 65 | + export UV_LINK_MODE=copy |
| 66 | +
|
| 67 | + # Pre-install build dependencies before any sync/lock operation |
| 68 | + uv pip install setuptools wheel wheel_stub pybind11 "Cython>=3.0.0" ninja packaging |
| 69 | +
|
| 70 | + # Generate lockfile with the EXACT configuration from pyproject.toml |
| 71 | + # No modifications! This ensures lockfile matches what Dockerfile will use |
| 72 | + uv lock --no-build-isolation || { echo "uv lock failed!"; exit 1; } |
| 73 | +
|
| 74 | + # Show disk usage |
| 75 | + df -h |
| 76 | + ' |
| 77 | +
|
| 78 | + - name: Check for lockfile changes |
| 79 | + id: check_changes |
| 80 | + run: | |
| 81 | + if git diff --quiet uv.lock; then |
| 82 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 83 | + else |
| 84 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Upload lockfile artifact |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: uv-lockfile |
| 91 | + path: uv.lock |
| 92 | + retention-days: 7 |
| 93 | + |
| 94 | + - name: Commit lockfile (if changed) |
| 95 | + if: steps.check_changes.outputs.changed == 'true' |
| 96 | + run: | |
| 97 | + git config --global user.name "github-actions[bot]" |
| 98 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | + git add uv.lock |
| 100 | + git commit -m "Update uv.lock [skip ci]" |
| 101 | + git push origin HEAD:${{ github.ref_name }} |
| 102 | +
|
| 103 | + - name: Comment on PR with lockfile status |
| 104 | + if: github.event_name == 'pull_request' |
| 105 | + uses: actions/github-script@v7 |
| 106 | + with: |
| 107 | + script: | |
| 108 | + const changed = '${{ steps.check_changes.outputs.changed }}'; |
| 109 | + const message = changed === 'true' |
| 110 | + ? '⚠️ **uv.lock needs to be regenerated**\n\nThe lockfile is out of sync with pyproject.toml. Please run the "Generate UV Lockfile" workflow manually or regenerate locally on Linux.' |
| 111 | + : '✅ **uv.lock is up to date**\n\nThe lockfile is in sync with pyproject.toml.'; |
| 112 | +
|
| 113 | + github.rest.issues.createComment({ |
| 114 | + issue_number: context.issue.number, |
| 115 | + owner: context.repo.owner, |
| 116 | + repo: context.repo.repo, |
| 117 | + body: message |
| 118 | + }); |
| 119 | +
|
0 commit comments