Approve a release from GitHub Actions
Add a step to a GitHub Actions workflow that asks a person to approve the release, and deploy only when they do, with the TaskToHuman action from the GitHub Marketplace.
What you build#
A GitHub Actions workflow that stops before its deploy step and asks a person to approve the release. The approver gets an email with the commit, opens the task page, which links to the run, approves or rejects it, and the workflow deploys only on a person's approval.
At the end, you run the workflow, approve it from your inbox and see the deploy step run; reject it and the run fails before deploying.
Before you start#
- A GitHub repository where you can add workflows and secrets.
- A TaskToHuman account. Creating tasks from the API, and so from the action, works on every plan.
- The TaskToHuman action is a JavaScript action without dependencies. It runs on GitHub-hosted runners and on self-hosted runners (version 2.328.0 or later, Linux, macOS or Windows) with nothing else to install.
1. Create a task type#
In the app, open Task types and choose New task type:
- Name
Release approval, Keyapprove_release. - What should the human do? Approval.
- Instructions for the human: "Check the run, then approve to deploy this commit."
- Fields:
commit(text, required, not editable, so nobody can change what is deployed) andrun_url(link). - Escalation chain: add yourself as the human asked first.
- If nobody answers: Expire, so that silence never deploys anything.
More in Task types and fields.
2. Store a test key in GitHub#
In TaskToHuman, open API & webhooks, then API keys, and create a key in test mode. It starts with tth_test_ and is shown once.
In your GitHub repository, add it as a repository secret named TTH_API_KEY. Test tasks notify only you, whoever the task type names, so you can try this without bothering anyone. See Test mode.
3. Add the workflow#
Create .github/workflows/release.yml. It asks for approval and waits for the answer in one run, then deploys:
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- id: ask
uses: MobiusApps/tasktohuman-action@v1
with:
api-key: ${{ secrets.TTH_API_KEY }}
task-type: approve_release
title: Deploy ${{ github.sha }}?
fields: |
commit=${{ github.sha }}
run_url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
idempotency-key: release-${{ github.sha }}
wait: "true"
wait-timeout-minutes: 30
cancel-on-timeout: "true"
- name: Deploy
env:
COMMIT: ${{ github.sha }}
APPROVER: ${{ steps.ask.outputs.decided-by }}
run: echo "Deploying $COMMIT, approved by $APPROVER"What each input does:
fieldsfills the task type's fields askey=valuelines.idempotency-keynames this release: a retry of the step returns the same task instead of asking twice (replayedis thentrue).waitkeeps the step running until the task is final, checking every 15 seconds by default.fail-unless-approvedistrueby default: when waiting, the step fails unless a person approved, approved with edits or completed the task. So the deploy step runs only after a person's approval.cancel-on-timeoutcancels the task when the wait times out, so nobody approves a run that has already given up.
Replace the echo with your real deploy command. Pass values to scripts through env:, as here, never with ${{ }} inside run:.
4. Run it and approve#
In GitHub, open Actions, choose the workflow and run it. The ask step creates the task and waits.
You get an email with the commit (emails never carry links from fields: the link to the run is on the task page). Open the task and approve it. At its next check (every 15 seconds by default) the step ends with a notice such as Task resolved: approved, by Ana., its outputs hold the decision (action is approved, automatic is false, decided-by is the approver's name and decided-at the time) and the deploy step runs.
Test tasks end after your plan's maximum test life, so answer within a few minutes. A test task that ends unanswered fails the step, as an expiry should.
Check it works#
Push a new commit first: the idempotency key names the commit, and a new run of the same commit has a new run_url, so the API refuses it with 409 idempotency_conflict. Then run the workflow once more and reject the task. The ask step fails and the deploy step never runs. The task in the app shows who decided and when.
Push another commit, run it a third time and don't answer: when the test task ends, the step fails, and nothing is deployed.
Going live#
- Replace the secret with a live key (
tth_live_…). Tasks then go to the humans the task type's chain names; add a backup step so a release doesn't wait on one person (Escalation chains). - Pin the action to the full commit SHA of a release, as GitHub advises for actions of other parties:
MobiusApps/tasktohuman-action@<full commit SHA> # v1.0.0. Each version is tagged and named with its commit in the releases of the action's repository. - Waiting holds a runner the whole time. That is fine for short decisions on GitHub-hosted runners. For decisions that take hours, or a self-hosted runner that must not sit idle, let the run create the task and end, and have the decision start your deploy workflow: see Wait or dispatch. The starter template Release approval (GitHub Actions) sets this up. Test tasks never start a workflow, so that path only runs with a live key.
- When a newer build replaces an older one waiting for approval, add
cancel-previous: "true"to cancel the older request.
Where next#
- GitHub Actions: every input and output of the action, and starting a workflow when a person decides.
- Tasks: what the decision contains.
- Let an AI agent ask a person before it acts: the same approval for an AI agent.