Skip to content

Commit ba79d84

Browse files
committed
ci(droplet): load deploy secrets from ENV_FILE and validate required keys
1 parent fd41587 commit ba79d84

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

.github/workflows/deploy-lnbits-droplet.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,53 @@ on:
77
jobs:
88
deploy-lnbits:
99
runs-on: ubuntu-latest
10+
env:
11+
# Supports either secret or variable named ENV_FILE (dotenv format)
12+
ENV_FILE: ${{ secrets.ENV_FILE || vars.ENV_FILE }}
1013
steps:
1114
- name: Checkout
1215
uses: actions/checkout@v4
1316

17+
- name: Load ENV_FILE
18+
shell: bash
19+
run: |
20+
set -euo pipefail
21+
if [ -z "${ENV_FILE:-}" ]; then
22+
echo "ENV_FILE is empty. Add secret/variable ENV_FILE with dotenv contents."
23+
exit 1
24+
fi
25+
26+
# Export KEY=VALUE lines into job env (ignore comments/blank lines)
27+
while IFS= read -r line; do
28+
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
29+
key="${line%%=*}"
30+
value="${line#*=}"
31+
key="$(echo "$key" | xargs)"
32+
[[ -z "$key" ]] && continue
33+
{
34+
echo "$key<<__EOF__"
35+
echo "$value"
36+
echo "__EOF__"
37+
} >> "$GITHUB_ENV"
38+
done <<< "$ENV_FILE"
39+
40+
- name: Validate required vars
41+
shell: bash
42+
run: |
43+
set -euo pipefail
44+
for k in LNBITS_DROPLET_HOST LNBITS_DROPLET_USER LNBITS_DROPLET_SSH_KEY LNBITS_ADMIN_KEY; do
45+
if [ -z "${!k:-}" ]; then
46+
echo "Missing required ENV_FILE key: $k"
47+
exit 1
48+
fi
49+
done
50+
1451
- name: Run setup-droplet.sh on LNbits host
1552
uses: appleboy/ssh-action@v1.0.3
1653
with:
17-
host: ${{ secrets.LNBITS_DROPLET_HOST }}
18-
username: ${{ secrets.LNBITS_DROPLET_USER }}
19-
key: ${{ secrets.LNBITS_DROPLET_SSH_KEY }}
54+
host: ${{ env.LNBITS_DROPLET_HOST }}
55+
username: ${{ env.LNBITS_DROPLET_USER }}
56+
key: ${{ env.LNBITS_DROPLET_SSH_KEY }}
2057
script_stop: true
2158
script: |
2259
set -euo pipefail
@@ -29,15 +66,10 @@ jobs:
2966
sudo bash scripts/setup-droplet.sh
3067
3168
- name: Verify LNURLp endpoint
32-
uses: appleboy/ssh-action@v1.0.3
33-
with:
34-
host: ${{ secrets.LNBITS_DROPLET_HOST }}
35-
username: ${{ secrets.LNBITS_DROPLET_USER }}
36-
key: ${{ secrets.LNBITS_DROPLET_SSH_KEY }}
37-
script_stop: true
38-
script: |
39-
set -euo pipefail
40-
code=$(curl -s -o /tmp/lnurlp.json -w "%{http_code}" https://ln.coinpayportal.com/lnurlp/api/v1/links \
41-
-H "X-Api-Key: $LNBITS_ADMIN_KEY")
42-
test "$code" = "200"
43-
cat /tmp/lnurlp.json | head -c 500
69+
shell: bash
70+
run: |
71+
set -euo pipefail
72+
code=$(curl -s -o /tmp/lnurlp.json -w "%{http_code}" "https://ln.coinpayportal.com/lnurlp/api/v1/links" \
73+
-H "X-Api-Key: ${LNBITS_ADMIN_KEY}")
74+
test "$code" = "200"
75+
head -c 500 /tmp/lnurlp.json

0 commit comments

Comments
 (0)