| name: Nix build and commit | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-commit: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| skip: ${{ steps.check.outputs.skip }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - id: check | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| msg=$(git log -1 --pretty=%B "${{ github.event.pull_request.head.sha }}") | |
| else | |
| msg="manual dispatch" | |
| fi | |
| echo "Commit message: $msg" | |
| if echo "$msg" | grep -q '\[skip-build\]'; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| build_and_commit: | |
| needs: check-commit | |
| if: needs.check-commit.outputs.skip == 'false' | |
| runs-on: docker-builder-01 | |
| steps: | |
| - name: Show disk usage | |
| run: df -h | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| ref: ${{ github.head_ref || github.ref }} | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v31 | |
| - name: Setup huggingface cachix | |
| uses: cachix/cachix-action@v15 | |
| with: | |
| name: huggingface | |
| - name: Clean build directory | |
| run: | | |
| rm -rf build | |
| - name: Build with Nix | |
| run: | | |
| nix run .#build-and-copy \ | |
| --override-input kernel-builder github:huggingface/kernel-builder \ | |
| --max-jobs 8 \ | |
| -j 8 \ | |
| -L | |
| - name: List built binaries | |
| run: | | |
| ls build | |
| - name: Commit build artifact | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add build/* | |
| git commit -m "Add built binary [skip-build]" | |
| - name: Push changes | |
| run: | | |
| git push origin HEAD:"$HEAD_REF" | |
| env: | |
| HEAD_REF: ${{ github.head_ref || github.ref }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |