forked from different-ai/openwork
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (87 loc) · 3.43 KB
/
Copy pathden-api-env.yml
File metadata and controls
96 lines (87 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Den API Env
# Sets a single environment variable on the production den-api service
# (Render) and triggers a deploy so it takes effect.
#
# Do NOT use this for secret values: workflow_dispatch inputs are visible in
# the run metadata. Secrets should be set in the Render dashboard directly.
#
# Required GitHub Actions secrets:
# RENDER_API_KEY Render API key
# RENDER_DEN_CONTROL_PLANE_SERVICE_ID Render service id of den-api
on:
workflow_dispatch:
inputs:
key:
description: "Environment variable name (e.g. DEN_PLAN_GATING_ENABLED)"
type: string
required: true
value:
description: "Environment variable value (non-secret values only)"
type: string
required: true
permissions:
contents: read
concurrency:
group: den-api-env
cancel-in-progress: false
jobs:
set-env:
name: Set env var and deploy
if: github.repository == 'different-ai/openwork'
runs-on: blacksmith-4vcpu-ubuntu-2204
env:
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
RENDER_SERVICE_ID: ${{ secrets.RENDER_DEN_CONTROL_PLANE_SERVICE_ID }}
steps:
- name: Verify Render secrets are configured
run: |
set -euo pipefail
missing=""
[ -z "$RENDER_API_KEY" ] && missing="$missing RENDER_API_KEY"
[ -z "$RENDER_SERVICE_ID" ] && missing="$missing RENDER_DEN_CONTROL_PLANE_SERVICE_ID"
if [ -n "$missing" ]; then
echo "::error::Missing GitHub Actions secrets:$missing."
exit 1
fi
echo "Render secrets present."
- name: Update environment variable
run: |
set -euo pipefail
value="$(jq -n --arg v '${{ inputs.value }}' '{value: $v}')"
curl -sf -X PUT "https://api.render.com/v1/services/$RENDER_SERVICE_ID/env-vars/${{ inputs.key }}" \
-H "Authorization: Bearer $RENDER_API_KEY" \
-H "Content-Type: application/json" \
-d "$value" >/dev/null
echo "Updated ${{ inputs.key }} on the den-api service."
- name: Trigger deploy and wait
run: |
set -euo pipefail
response="$(curl -s -w '\n%{http_code}' -X POST "https://api.render.com/v1/services/$RENDER_SERVICE_ID/deploys" \
-H "Authorization: Bearer $RENDER_API_KEY" \
-H "Content-Type: application/json" -d '{}')"
http_code="$(printf '%s' "$response" | tail -1)"
body="$(printf '%s' "$response" | sed '$d')"
if [ "$http_code" -ge 400 ]; then
echo "::error::POST /deploys returned HTTP $http_code: $body"
exit 1
fi
deploy_id="$(printf '%s' "$body" | jq -r '.id')"
echo "Deploy triggered: $deploy_id"
for _ in $(seq 1 90); do
status="$(curl -sf "https://api.render.com/v1/services/$RENDER_SERVICE_ID/deploys/$deploy_id" \
-H "Authorization: Bearer $RENDER_API_KEY" | jq -r '.status')"
echo "deploy status: $status"
case "$status" in
live)
echo "Deploy is live."
exit 0
;;
build_failed|update_failed|pre_deploy_failed|canceled|deactivated)
echo "::error::Deploy failed with status: $status"
exit 1
;;
esac
sleep 10
done
echo "::error::Deploy did not go live within 15 minutes."
exit 1