-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (76 loc) · 2.85 KB
/
ssl.yml
File metadata and controls
89 lines (76 loc) · 2.85 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
name: ssl
on:
schedule:
- cron: 0 8 1 * *
workflow_dispatch:
permissions:
contents: write
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
jobs:
ssl:
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
matrix:
domain:
# domain that has a 127.0.0.1 A record
- local.jmw.nz
steps:
- uses: actions/checkout@v3
- name: cloudflare
run: |
mkdir -p ssl
echo "dns_cloudflare_api_token = $CLOUDFLARE_API_TOKEN" > ssl/cloudflare.ini
- name: certbot
working-directory: ssl
run: |
docker run --rm \
-v $PWD/cloudflare.ini:/cloudflare.ini \
-v $PWD/letsencrypt:/etc/letsencrypt \
certbot/dns-cloudflare certonly \
--non-interactive \
--domains ${{ matrix.domain }} \
--dns-cloudflare \
--dns-cloudflare-credentials /cloudflare.ini \
--dns-cloudflare-propagation-seconds 60 \
--agree-tos \
--preferred-challenges dns \
-m contact@jmw.nz
- name: chown
working-directory: ssl
# whoami - uid=1001 gid=121, user: runner, group: docker
run: sudo chown -R 1001:121 letsencrypt
- name: package
working-directory: ssl
run: |
mkdir ${{ matrix.domain }}
cp letsencrypt/archive/${{ matrix.domain }}/fullchain1.pem ${{ matrix.domain }}/${{ matrix.domain }}.crt
cp letsencrypt/archive/${{ matrix.domain }}/privkey1.pem ${{ matrix.domain }}/${{ matrix.domain }}.key
# Create PFX for .NET (no password for easier loading)
openssl pkcs12 -export -out ${{ matrix.domain }}/${{ matrix.domain }}.pfx \
-inkey letsencrypt/archive/${{ matrix.domain }}/privkey1.pem \
-in letsencrypt/archive/${{ matrix.domain }}/fullchain1.pem \
-passout pass:
# Password-protected zip to prevent CA from scanning and revoking
zip -P password -r ${{ matrix.domain }}.zip ${{ matrix.domain }}
- name: commit to orphan branch
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create orphan branch or reset it
git checkout --orphan certs-temp
git rm -rf .
# Add only the zip file
cp ssl/${{ matrix.domain }}.zip .
git add ${{ matrix.domain }}.zip
git commit -m "Update SSL certificates $(date -u +%Y-%m-%d)"
# Force push to certs branch
git push origin certs-temp:certs --force
# Only upload the password-protected zip as artifact
- name: artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.domain }}
path: ssl/${{ matrix.domain }}.zip