Skip to content

GitHub Actions

Add one step to a workflow and a failed run, or a finished deploy, arrives on your devices with a button that opens the run on GitHub.

This uses an API Source, with curl and jq, which GitHub’s hosted runners have. shell: bash makes the step run the same on Windows runners.

  1. In the Pocketbell app, create a Source named GitHub, choose API, and copy its key.

  2. In the repository on GitHub, open Settings → Secrets and variables → Actions, click New repository secret, name it POCKETBELL_KEY, paste the key, and click Add secret.

  3. Add this as the last step of the job you want to hear about:

    - name: Tell Pocketbell
    if: failure()
    shell: bash
    env:
    POCKETBELL_KEY: ${{ secrets.POCKETBELL_KEY }}
    WORKFLOW: ${{ github.workflow }}
    REPO: ${{ github.repository }}
    BRANCH: ${{ github.ref_name }}
    RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
    run: |
    jq -n --arg title "$WORKFLOW failed" --arg message "$REPO on $BRANCH" --arg url "$RUN_URL" \
    '{title: $title, message: $message, priority: "important", tags: ["github"],
    url: $url, url_title: "Open run"}' |
    curl --fail-with-body -sS https://api.pocketbell.dev/v1/messages \
    -H "Authorization: Bearer $POCKETBELL_KEY" \
    -H "Content-Type: application/json" \
    --data @-
  4. Push, and the next failed run sends it.

  • Every run, pass or fail: change if: failure() to if: always(), add STATUS: ${{ job.status }} under env:, and use "$WORKFLOW: $STATUS" as the title.
  • A deploy finished: if: success() at the end of the deploy job, with priority: "normal".
  • A failure that must wake you: priority: "critical" repeats until you acknowledge it. See Critical notifications.

Values such as a branch name, a pull request title or a commit message are written by whoever pushed them. Passed through env:, they reach the script as plain data and can’t run as commands, which is GitHub’s own advice. jq --arg turns each one into a JSON string, so quotes and line breaks in them can’t break the request.

The step’s log shows Pocketbell’s answer, since --fail-with-body prints it and fails the step:

  • 401 invalid_api_key: the secret is missing or wrong. Secrets aren’t passed to workflows run from forks.
  • 400 invalid_request: details in the answer names the field.