Skip to content

Commit 4c46323

Browse files
author
Hermes
committed
ci: skip unchanged root sitemap invalidations
1 parent 2aea30d commit 4c46323

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

.github/workflows/translate_all.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,29 @@ jobs:
275275
find . -type f -name 'index.html' -print | head -n 3 | xargs -r cat
276276
277277
- name: Refresh root sitemap index
278+
id: root_sitemap
278279
run: |
279-
LANGS=$(aws s3api list-objects-v2 --bucket hacktricks-cloud --delimiter / --query 'CommonPrefixes[].Prefix' --output text | tr '\t' '\n' | sed 's:/$::' | grep -E '^[a-z]{2}$' | sort | paste -sd, -)
280+
set -euo pipefail
281+
LANGS=$(aws s3api list-objects-v2 --bucket hacktricks-cloud --delimiter / --query 'CommonPrefixes[].Prefix' --output text | tr '\t' '\n' | sed 's:/$::' | grep -E '^[a-z]{2}$' | sort | paste -sd, - || true)
280282
if [ -z "$LANGS" ]; then
281283
LANGS="en"
282284
fi
283285
python3 /tmp/seo_postprocess.py index --site-url https://cloud.hacktricks.wiki --languages "$LANGS" --output ./sitemap.xml
284-
aws s3 cp ./sitemap.xml s3://hacktricks-cloud/sitemap.xml --content-type application/xml --cache-control max-age=300
286+
if aws s3 cp s3://hacktricks-cloud/sitemap.xml /tmp/current-root-sitemap.xml >/dev/null 2>&1 && cmp -s /tmp/current-root-sitemap.xml ./sitemap.xml; then
287+
echo "Root sitemap unchanged; skipping S3 upload and CloudFront invalidation for /sitemap.xml"
288+
echo "changed=false" >> "$GITHUB_OUTPUT"
289+
else
290+
aws s3 cp ./sitemap.xml s3://hacktricks-cloud/sitemap.xml --content-type application/xml --cache-control max-age=300
291+
echo "changed=true" >> "$GITHUB_OUTPUT"
292+
fi
285293
286294
- name: Invalidate CloudFront HTML and SEO assets
287295
run: |
296+
set -euo pipefail
297+
paths=("/$BRANCH/*" "/$BRANCH/sitemap.xml")
298+
if [ "${{ steps.root_sitemap.outputs.changed }}" = "true" ]; then
299+
paths+=("/sitemap.xml")
300+
fi
288301
aws cloudfront create-invalidation \
289302
--distribution-id "${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}" \
290-
--paths "/$BRANCH/*" "/sitemap.xml" "/$BRANCH/sitemap.xml"
303+
--paths "${paths[@]}"

0 commit comments

Comments
 (0)