Notify GChat on CI workflow failure #13
This file contains hidden or 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
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-test: | |
| name: build-and-test (${{ matrix.os }}, py${{ matrix.python-version }}) | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 30 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| python-version: ["3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| allow-prereleases: true | |
| cache: 'pip' | |
| - name: Install zstd (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libzstd-dev | |
| - name: Install zstd (macOS) | |
| if: runner.os == 'macOS' | |
| run: brew install zstd | |
| - name: Upgrade pip | |
| run: python -m pip install --upgrade pip | |
| - name: Install tintype | |
| run: pip install -v . | |
| - name: Install test dependencies | |
| run: pip install pytest | |
| - name: Run tests | |
| run: pytest tests/ -v | |
| notify: | |
| name: notify-on-failure | |
| needs: build-and-test | |
| # Single workflow-level notification: fires once if ANY leg of the | |
| # build-and-test matrix failed, instead of per-leg (avoids 6x noise | |
| # from the 2 OS x 3 Python matrix). `failure()` at job scope returns | |
| # true when any job in `needs:` has the `failure` result. | |
| if: ${{ failure() }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Notify GChat on failure | |
| env: | |
| GCHAT_WEBHOOK_URL: ${{ secrets.GCHAT_WEBHOOK_URL }} | |
| REPO: ${{ github.repository }} | |
| REF_NAME: ${{ github.ref_name }} | |
| WORKFLOW: ${{ github.workflow }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| text=$(printf '❌ *GitHub Action Failed*\n\n*Repo:* %s\n*Branch:* %s\n*Workflow:* %s\n*Run:* %s' \ | |
| "$REPO" "$REF_NAME" "$WORKFLOW" "$RUN_URL") | |
| curl -X POST "$GCHAT_WEBHOOK_URL" \ | |
| -H 'Content-Type: application/json' \ | |
| -d "$(jq -n --arg text "$text" '{text: $text}')" |