|
| 1 | +name: Nightly Build |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 2 * * *' # Daily at 2 AM UTC |
| 6 | + workflow_dispatch: # Manual trigger for testing |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-for-changes: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + should-build: ${{ steps.check.outputs.should-build }} |
| 13 | + commit-hash: ${{ steps.check.outputs.commit-hash }} |
| 14 | + nightly-version: ${{ steps.check.outputs.nightly-version }} |
| 15 | + steps: |
| 16 | + - name: Checkout develop branch |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: develop |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Check if nightly build needed |
| 23 | + id: check |
| 24 | + run: | |
| 25 | + # Get the latest commit hash on develop |
| 26 | + COMMIT_HASH=$(git rev-parse --short HEAD) |
| 27 | + echo "commit-hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + # Check if we already built this commit as nightly |
| 30 | + LAST_NIGHTLY_TAG=$(git tag -l "*dev*" --sort=-version:refname | head -1) |
| 31 | + if [ -n "$LAST_NIGHTLY_TAG" ]; then |
| 32 | + # Get the commit that the last nightly tag points to |
| 33 | + LAST_NIGHTLY_COMMIT=$(git rev-list -n 1 $LAST_NIGHTLY_TAG) |
| 34 | + CURRENT_COMMIT=$(git rev-parse HEAD) |
| 35 | + if [ "$CURRENT_COMMIT" = "$LAST_NIGHTLY_COMMIT" ]; then |
| 36 | + echo "should-build=false" >> "$GITHUB_OUTPUT" |
| 37 | + echo "No new commits since last nightly build" |
| 38 | + exit 0 |
| 39 | + fi |
| 40 | + fi |
| 41 | +
|
| 42 | + # Generate nightly version |
| 43 | + BASE_VERSION=$(python -c " |
| 44 | + try: |
| 45 | + import tomllib |
| 46 | + except ImportError: |
| 47 | + import tomli as tomllib |
| 48 | + with open('packages/ragbits/pyproject.toml', 'rb') as f: |
| 49 | + data = tomllib.load(f) |
| 50 | + print(data['project']['version']) |
| 51 | + ") |
| 52 | + # Use timestamp for unique nightly version (PEP 440 compliant) |
| 53 | + TIMESTAMP=$(date +%Y%m%d%H%M) |
| 54 | + NIGHTLY_VERSION="${BASE_VERSION}.dev${TIMESTAMP}" |
| 55 | +
|
| 56 | + echo "should-build=true" >> "$GITHUB_OUTPUT" |
| 57 | + echo "nightly-version=$NIGHTLY_VERSION" >> "$GITHUB_OUTPUT" |
| 58 | + echo "Will build nightly version: $NIGHTLY_VERSION" |
| 59 | +
|
| 60 | + build-and-publish: |
| 61 | + needs: check-for-changes |
| 62 | + if: needs.check-for-changes.outputs.should-build == 'true' |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - name: Checkout develop branch |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + ref: develop |
| 69 | + |
| 70 | + - name: Install uv |
| 71 | + uses: astral-sh/setup-uv@v2 |
| 72 | + with: |
| 73 | + version: ${{ vars.UV_VERSION || '0.6.9' }} |
| 74 | + |
| 75 | + - name: Set up Python |
| 76 | + uses: actions/setup-python@v4 |
| 77 | + with: |
| 78 | + python-version: "3.10" |
| 79 | + |
| 80 | + - name: Update package versions for nightly |
| 81 | + run: | |
| 82 | + uv run scripts/update_nightly_versions.py "${{ needs.check-for-changes.outputs.nightly-version }}" |
| 83 | +
|
| 84 | + - name: Install dependencies |
| 85 | + run: | |
| 86 | + uv sync --all-extras |
| 87 | +
|
| 88 | + - name: Build packages |
| 89 | + run: | |
| 90 | + for dir in packages/*/; do |
| 91 | + echo "Building $dir" |
| 92 | + uv build "$dir" --out-dir dist |
| 93 | + done |
| 94 | +
|
| 95 | + - name: Publish to PyPI |
| 96 | + run: | |
| 97 | + uv tool run twine upload dist/* --verbose |
| 98 | + env: |
| 99 | + TWINE_USERNAME: __token__ |
| 100 | + TWINE_REPOSITORY_URL: ${{ vars.PYPI_REPOSITORY_URL || 'https://test.pypi.org/legacy/' }} |
| 101 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 102 | + |
| 103 | + - name: Deploy nightly documentation |
| 104 | + shell: bash |
| 105 | + run: uv run mike deploy --push nightly |
| 106 | + |
| 107 | + - name: Create git tag for nightly |
| 108 | + run: | |
| 109 | + git tag "${{ needs.check-for-changes.outputs.nightly-version }}" |
| 110 | + git push origin "${{ needs.check-for-changes.outputs.nightly-version }}" |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 113 | + |
| 114 | + - name: Notify on failure |
| 115 | + if: failure() |
| 116 | + run: | |
| 117 | + echo "Nightly build failed for commit ${{ needs.check-for-changes.outputs.commit-hash }}" |
| 118 | + echo "Version attempted: ${{ needs.check-for-changes.outputs.nightly-version }}" |
0 commit comments