Kernels
optimizer / .github /workflows /build-and-commit.yml
wyldecat's picture
feat(workflow): add Slack notifications for build start, success, and failure [skip-build] (#12)
0b8d958 unverified
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: Notify build start on Slack
id: slack_start
run: |
msg="*Build started* for \`${{ github.repository }}\`\nBranch: \`${{ github.ref_name }}\`\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Workflow>"
response=$(curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.SLACK_TOKEN }}" \
-H "Content-type: application/json; charset=utf-8" \
--data "{\"channel\":\"${{ secrets.SLACK_CHANNEL_ID }}\",\"text\":\"$msg\"}" \
https://slack.com/api/chat.postMessage)
ts=$(echo "$response" | jq -r '.ts')
echo "thread_ts=$ts" >> "$GITHUB_OUTPUT"
echo "$response"
- 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 }}
- name: Notify success on Slack (thread)
if: success()
run: |
ts="${{ steps.slack_start.outputs.thread_ts }}"
msg="*Build succeeded* for \`${{ github.repository }}\`\nBranch: \`${{ github.ref_name }}\`\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Workflow>"
curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.SLACK_TOKEN }}" \
-H "Content-type: application/json; charset=utf-8" \
--data "{\"channel\":\"${{ secrets.SLACK_CHANNEL_ID }}\",\"text\":\"$msg\",\"thread_ts\":\"$ts\"}" \
https://slack.com/api/chat.postMessage
- name: Notify failure on Slack (thread)
if: failure()
run: |
ts="${{ steps.slack_start.outputs.thread_ts }}"
msg="*Build failed* for \`${{ github.repository }}\`\nBranch: \`${{ github.ref_name }}\`\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Workflow>"
curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.SLACK_TOKEN }}" \
-H "Content-type: application/json; charset=utf-8" \
--data "{\"channel\":\"${{ secrets.SLACK_CHANNEL_ID }}\",\"text\":\"$msg\",\"thread_ts\":\"$ts\"}" \
https://slack.com/api/chat.postMessage