Repository navigation
160 lines (141 loc) · 6.63 KB
/
Copy pathdeploy.yml
File metadata and controls
160 lines (141 loc) · 6.63 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Deploy MSK Scripts Docs
on:
push:
branches:
- main
permissions:
contents: read
# Needed to post a legacy commit status under context "CI" so that
# PR-management UIs that only read the older Statuses API (rather
# than the newer Check-Runs API) show the merge commits as green
# instead of stuck-on-pending.
statuses: write
# Only one deploy at a time. Parallel runs upload into the same DocumentRoot,
# and the post-deploy step of one run moves the csp-hashes.conf the other run
# still needs. A newer push waits for the running deploy instead of cancelling
# it, because an interrupted upload would leave a half-updated site. GitHub
# keeps just the newest waiting run, so the site always ends on the latest commit.
concurrency:
group: deploy-docs
cancel-in-progress: false
jobs:
build-and-deploy:
name: Build & Deploy
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout Repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 🟢 Setup Node.js
uses: actions/setup-node@v7
with:
node-version: 24
cache: yarn
- name: 📦 Install Dependencies
run: yarn install --frozen-lockfile
- name: 🏗️ Build Project
run: yarn build
# The appleboy actions get the server SSH key, so they are pinned to a
# commit SHA instead of a moving branch. Both point to the master commit
# the deploy already ran with: the last releases are older and lack
# fixes that landed on master afterwards. Bump the SHAs deliberately.
#
# The build goes to a staging folder first, not into the DocumentRoot.
# The next step syncs it over with rsync --delete, so pages that were
# removed from the docs also disappear from the server. Before this,
# every deploy only added files and old pages stayed reachable.
# rm: true empties the staging folder first, so leftovers of a failed
# run never reach the site.
- name: 🚀 Upload build to staging folder
uses: appleboy/scp-action@7e85c2e09aa21988492acd66466b5d68bda49e2b # master 2026-08-09, v1.0.0 plus 10 commits
with:
host: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.FTP_PORT }}
source: "build/*"
target: "/var/www/docs_msk-scripts.staging/"
strip_components: 1
rm: true
- name: 🛠️ Sync, Ownership, CSP-Snippet, Apache-Reload
uses: appleboy/ssh-action@c4f70287fc37c43b14b30b407224bbbc8e8c6327 # master 2026-08-16, v1.2.5 plus 10 commits (drone-ssh checksum check)
with:
host: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.FTP_PORT }}
# script_stop was removed from ssh-action in v1.2.1. The
# `set -euo pipefail` below stops the script on the first failing
# command and fails this step.
script: |
set -euo pipefail
DOCROOT=/var/www/html/docs_msk-scripts
STAGING=/var/www/docs_msk-scripts.staging
SNIPPETS_DIR=/etc/apache2/snippets
SNIPPET_DST="${SNIPPETS_DIR}/docu-csp-hashes.conf"
SNIPPET_SRC="${STAGING}/csp-hashes.conf"
# Refuse to sync an incomplete upload: rsync --delete would
# otherwise wipe the live site down to whatever arrived.
echo "::group::Upload prüfen"
if [ ! -f "${STAGING}/index.html" ] || [ ! -f "${STAGING}/de/index.html" ]; then
echo "❌ ${STAGING} ist unvollständig, index.html oder de/index.html fehlt"
exit 1
fi
if [ ! -f "${SNIPPET_SRC}" ]; then
echo "❌ ${SNIPPET_SRC} fehlt, build erzeugt es normalerweise via scripts/generate-csp.mjs"
exit 1
fi
echo "✓ $(find "${STAGING}" -type f | wc -l) Dateien hochgeladen"
echo "::endgroup::"
# --checksum compares contents, not size and mtime, so a changed
# file of the same size is never skipped. --delay-updates moves
# all new files into place at the end, which keeps the window of
# a half-updated site short. csp-hashes.conf is excluded because
# it must not be served publicly. Everything under img/ and
# de/img/ is protected from deletion: external pages such as
# forum posts and READMEs may still embed old images.
echo "::group::Build in den DocumentRoot abgleichen"
mkdir -p "${DOCROOT}"
rsync -a --checksum --delete --delay-updates --itemize-changes \
--exclude=/csp-hashes.conf \
--filter='P /img/**' --filter='P /de/img/**' \
"${STAGING}/" "${DOCROOT}/" > /tmp/docs-rsync.log
echo "✓ $(grep -c '^\*deleting' /tmp/docs-rsync.log || true) veraltete Einträge entfernt, $(grep -cE '^[<>]f' /tmp/docs-rsync.log || true) Dateien neu oder geändert"
echo "::endgroup::"
echo "::group::Datei-Besitzer auf www-data setzen"
chown -R www-data:www-data "${DOCROOT}"
echo "::endgroup::"
echo "::group::CSP-Snippet ablegen"
mkdir -p "${SNIPPETS_DIR}"
install -o root -g root -m 0644 "${SNIPPET_SRC}" "${SNIPPET_DST}"
echo "✓ ${SNIPPET_DST} aktualisiert"
echo "::endgroup::"
echo "::group::Apache-Config testen"
apachectl configtest
echo "::endgroup::"
echo "::group::Apache reloaden"
systemctl reload apache2
systemctl is-active --quiet apache2 && echo "✓ apache2 läuft"
echo "::endgroup::"
echo "::group::Staging-Ordner aufräumen"
rm -rf "${STAGING}"
echo "::endgroup::"
- name: ✅ Post CI commit status (legacy API)
if: always()
uses: actions/github-script@v9
with:
script: |
const state = '${{ job.status }}' === 'success' ? 'success' : 'failure';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state,
context: 'CI',
description:
state === 'success'
? 'Build + deploy green'
: 'Build or deploy failed, see workflow logs',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});