Repository navigation
141 lines (129 loc) · 5.31 KB
/
Copy pathgithub-relay.docs.plus.yml
File metadata and controls
141 lines (129 loc) · 5.31 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Server-only GitHub-to-Discord relay stack deploy, decoupled from the app pipeline.
name: CI/CD GitHub Relay
on:
workflow_dispatch:
inputs:
action:
description: 'Action to run on the GitHub relay stack'
required: true
default: setup
type: choice
options: [setup, update, restart, down]
defaults:
run:
shell: bash
permissions:
contents: read
env:
COMPOSE_FILE: docker-compose.github-relay.yml
ENV_SOURCE: /opt/projects/prod.docs.plus/.env.github-relay
ENV_FILE: .env.github-relay
OBS_ENV_SOURCE: /opt/projects/prod.docs.plus/.env.observability
jobs:
deploy:
name: 📣 Deploy GitHub Relay
runs-on: prod.docs.plus
timeout-minutes: 10
concurrency:
group: github-relay-deploy
cancel-in-progress: false
if: github.ref == 'refs/heads/main' && inputs.action != 'down'
permissions:
contents: read
steps:
- name: 📦 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: 🔐 Prepare environment
run: |
install -m 600 "${ENV_SOURCE}" "${ENV_FILE}"
for k in GITHUB_WEBHOOK_SECRET DISCORD_BOT_TOKEN DISCORD_GITHUB_CHANNEL_ID DISCORD_RELEASES_CHANNEL_ID; do
if ! grep -Eq "^${k}=[\"']?[^\"'[:space:]]" "${ENV_FILE}"; then
echo "::error::${k} missing or empty in ${ENV_SOURCE}"; exit 1
fi
done
echo "✅ Environment ready"
- name: 🔧 Ensure network
run: docker network create docsplus-network 2>/dev/null || true
- name: 🚀 Deploy stack
env:
ACTION_IN: ${{ inputs.action }}
run: |
ACTION="${ACTION_IN:-setup}"
case "${ACTION}" in
setup|update|restart) ;;
*) echo "::error::unknown relay action '${ACTION}'"; exit 1 ;;
esac
if [ "${ACTION}" = "restart" ]; then
docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" restart
else
docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" up -d --build --remove-orphans
fi
- name: 🩺 Verify health
run: |
docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" ps
ok=0
for _i in $(seq 1 15); do
if docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" exec -T github-relay \
bun -e "fetch('http://127.0.0.1:'+(process.env.PORT||'4050')+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" 2>/dev/null; then
ok=1
echo "✅ github-relay healthy"
break
fi
sleep 3
done
[ "${ok}" = 1 ] || { echo "::error::github-relay not healthy after 45s"; exit 1; }
- name: 🔑 Verify Discord channel permissions
if: inputs.action != 'restart'
run: |
docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" exec -T github-relay \
bun -e "
const url = 'http://127.0.0.1:' + (process.env.PORT || '4050') + '/health';
for (let i = 0; i < 15; i++) {
const body = await fetch(url).then((r) => r.json());
const ch = body.channels;
if (!ch) {
console.log('::warning::/health does not expose channels field; skipping check');
process.exit(0);
}
if (ch.checkedAt) {
for (const r of ch.results || []) {
const name = r.channelName ? r.channelKey + ' (' + r.channelName + ')' : r.channelKey;
const detail = r.ok ? 'OK' : (r.error || 'missing ' + (r.missing || []).join(', '));
console.log('[' + r.status + '] ' + name + ': ' + detail);
}
if (ch.hasDenied) {
console.log('::error::Discord channel permissions missing or unsupported; check output above');
process.exit(1);
}
if (ch.hasTransientError) {
console.log('::warning::Discord API returned a transient error during permission check; relay is healthy and will retry');
process.exit(0);
}
console.log('✅ Discord channel permissions verified');
process.exit(0);
}
await Bun.sleep(1000);
}
console.log('::warning::Discord permission check still pending after 15s; relay is healthy');
"
- name: 📣 Notify failure
if: failure()
run: bash scripts/ci/notify-telegram.sh "${OBS_ENV_SOURCE}" "📣 GitHub Relay deploy FAILED (${GITHUB_SHA}, run ${GITHUB_RUN_ID})"
teardown:
name: 🧹 Down GitHub Relay
runs-on: prod.docs.plus
timeout-minutes: 10
if: github.ref == 'refs/heads/main' && inputs.action == 'down'
permissions:
contents: read
steps:
- name: 📦 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: 🔐 Prepare environment
run: install -m 600 "${ENV_SOURCE}" "${ENV_FILE}"
- name: 🧹 Down (keep volume)
run: docker compose -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" down