Every client takes an API token and wraps the same API. Keep the token in an environment variable such as HOOK_TOKEN.
Node
terminal
npm install @gethook/sdkdeploy.mjs
import { Hook } from "@gethook/sdk";
const hook = new Hook({ token: process.env.HOOK_TOKEN });
await hook.push({ title: "Deployed", message: "api v1.8.0", priority: 3 });
await hook.liveActivities.stream("deploy", {
type: "progress",
content_state: { title: "Deploying api", percentage: 40 },
});
await hook.liveActivities.endStream("deploy");
await hook.metrics.update("mrr", 1240, { unit: "$" });
const approval = await hook.approvals.request({ title: "Deploy api to production" });
const result = await hook.approvals.wait(approval.id);
if (result.status !== "approved") process.exit(1);Python
terminal
pip install gethookdeploy.py
import os
from gethook import Hook
hook = Hook(token=os.environ["HOOK_TOKEN"])
hook.push(title="Deployed", message="api v1.8.0", priority=3)
hook.live_activities.stream("deploy", type="progress",
content_state={"title": "Deploying api", "percentage": 40})
hook.live_activities.end_stream("deploy")
hook.metrics.update("mrr", 1240, unit="$")
approval = hook.approvals.request(title="Deploy api to production")
result = hook.approvals.wait(approval["id"])CLI
The Node package ships a hook command. It reads HOOK_TOKEN.
terminal
npx @gethook/sdk push "Backup finished" --title "db-1"
hook stream deploy --type progress --title Deploy --percentage 40
hook end deploy
hook metric mrr 1240 --unit $
hook approve "Deploy?" --wait 300hook approve waits up to the number of seconds you give and exits non-zero unless you approved, so it works as a gate in a script.
GitHub Action
Add your token as a repository secret named HOOK_TOKEN, then notify from a workflow.
.github/workflows/deploy.yml
- uses: gethook/sdk/github-action@main
with:
token: ${{ secrets.HOOK_TOKEN }}
title: Deployed
message: ${{ github.repository }} ${{ github.sha }}
# Deploy progress as a Live Activity, ended even when the job fails
- uses: gethook/sdk/github-action@main
with: { token: "${{ secrets.HOOK_TOKEN }}", stream-key: deploy, stream-type: progress, title: Deploy, percentage: 40 }
- uses: gethook/sdk/github-action@main
if: always()
with: { token: "${{ secrets.HOOK_TOKEN }}", stream-key: deploy, stream-end: "true" }Something wrong on this page? Email office@swiftapps.us.