Repository navigation
80 lines (76 loc) · 3.66 KB
/
Copy pathdeploy_promotion.yml
File metadata and controls
80 lines (76 loc) · 3.66 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
name: Deploy promotion banner
on:
workflow_dispatch:
permissions:
contents: read
id-token: write
concurrency:
group: deploy-promotion-banner
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- uses: actions/checkout@v4
- name: Validate campaign
run: |
node --check theme/discount.js
node --test scripts/test_discount.js
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Update promotion on every deployed language
shell: bash
env:
BUCKET: hacktricks-wiki
SITE_URL: https://hacktricks.wiki
DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
run: |
set -euo pipefail
# Discover only existing language roots; leave book content untouched.
aws s3api list-objects-v2 --bucket "$BUCKET" --delimiter / \
--query 'CommonPrefixes[].Prefix' --output json > /tmp/prefixes.json
python3 - <<'PYCODE'
import json, re
prefixes = [p for p in json.load(open('/tmp/prefixes.json')) if re.fullmatch(r'[a-z]{2}/', p)]
if 'en/' not in prefixes:
raise SystemExit('Expected the deployed English book')
with open('/tmp/languages.txt', 'w') as output:
output.write('\n'.join(prefixes) + '\n')
PYCODE
invalidation_paths=()
while IFS= read -r prefix; do
aws s3 cp src/images/hacktricks-black-friday-2026-v1.webp \
"s3://${BUCKET}/${prefix}images/hacktricks-black-friday-2026-v1.webp" \
--content-type image/webp --cache-control 'public,max-age=31536000,immutable' --only-show-errors
# mdBook versions have emitted both paths. Cover both existing page layouts.
for script in theme/discount.js discount.js; do
aws s3 cp theme/discount.js "s3://${BUCKET}/${prefix}${script}" \
--content-type application/javascript --cache-control 'public,max-age=300' --only-show-errors
done
for stylesheet in theme/discount.css discount.css; do
aws s3 cp theme/discount.css "s3://${BUCKET}/${prefix}${stylesheet}" \
--content-type text/css --cache-control 'public,max-age=300' --only-show-errors
done
# Exact paths avoid CloudFront's limit of 15 concurrent wildcard paths.
invalidation_paths+=(
"/${prefix}theme/discount.js" "/${prefix}discount.js"
"/${prefix}theme/discount.css" "/${prefix}discount.css"
)
done < /tmp/languages.txt
invalidation_id=$(aws cloudfront create-invalidation \
--distribution-id "$DISTRIBUTION_ID" \
--paths "${invalidation_paths[@]}" \
--query Invalidation.Id --output text)
aws cloudfront wait invalidation-completed \
--distribution-id "$DISTRIBUTION_ID" --id "$invalidation_id"
while IFS= read -r prefix; do
curl --fail --silent --show-error --retry 3 "${SITE_URL}/${prefix}theme/discount.js" | cmp - theme/discount.js
curl --fail --silent --show-error --retry 3 "${SITE_URL}/${prefix}theme/discount.css" | cmp - theme/discount.css
curl --fail --silent --show-error --retry 3 "${SITE_URL}/${prefix}images/hacktricks-black-friday-2026-v1.webp" \
| cmp - src/images/hacktricks-black-friday-2026-v1.webp
echo "Verified live promotion assets: ${SITE_URL}/${prefix}"
done < /tmp/languages.txt