From 4d2a9815d72445dfa6158f2923275593599cda80 Mon Sep 17 00:00:00 2001 From: Michael Seele Date: Tue, 19 May 2026 15:07:29 +0000 Subject: [PATCH] fix: update versioning parameters in README and action.yml for clarity Co-authored-by: Copilot --- publish-static-contents/README.md | 21 ++++++++++++++----- publish-static-contents/action.yml | 33 +++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/publish-static-contents/README.md b/publish-static-contents/README.md index 9ebc930..5d5c6b4 100644 --- a/publish-static-contents/README.md +++ b/publish-static-contents/README.md @@ -9,7 +9,8 @@ Syncs frontend assets to S3 and invalidates a CloudFront distribution. Optionall | `dist_dir` | No | `frontend/dist` | Path to the frontend dist directory | | `s3_bucket_name` | Yes | — | Name of the S3 bucket to sync assets to | | `cloudfront_distribution_ids` | No | `''` | Space-separated list of CloudFront distribution IDs to invalidate | -| `versioned_static_prefix` | No | `''` | S3 prefix under which versioned builds are stored (e.g. `_static`). When set, old versions older than 7 days are deleted, keeping at least the 2 newest | +| `versioning` | No | `false` | When `true`, enables versioned builds. Old versions older than 7 days are deleted, keeping at least the 2 newest | +| `versioning_prefix` | No | `''` | S3 prefix under which versioned builds are stored (e.g. `_static` → `_static/1234567890/`). When omitted, versions are stored at the bucket root (e.g. `1234567890/`) | ## Usage @@ -20,20 +21,30 @@ Syncs frontend assets to S3 and invalidates a CloudFront distribution. Optionall cloudfront_distribution_ids: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }} ``` -With versioned static assets: +With versioned static assets at the bucket root: ```yaml - uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/publish-static-contents@publish-static-contents-v1 with: - dist_dir: frontend/dist s3_bucket_name: my-bucket cloudfront_distribution_ids: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }} - versioned_static_prefix: _static + versioning: true +``` + +With versioned static assets under a prefix: + +```yaml +- uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/publish-static-contents@publish-static-contents-v1 + with: + s3_bucket_name: my-bucket + cloudfront_distribution_ids: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }} + versioning: true + versioning_prefix: _static ``` ## Notes -- When `versioned_static_prefix` is set, all assets are synced with `Cache-Control: public, max-age=31536000, immutable`. +- When `versioning` is `true`, all assets are synced with `Cache-Control: public, max-age=31536000, immutable`. - `index.html` is always synced separately with `Cache-Control: no-cache, max-age=300` so browsers pick up new deployments quickly. - Old versioned builds are pruned: any version folder older than 7 days is deleted, with at least the 2 newest versions always retained. - CloudFront invalidation is skipped when `cloudfront_distribution_ids` is empty. diff --git a/publish-static-contents/action.yml b/publish-static-contents/action.yml index 6d7341d..4eadf6b 100644 --- a/publish-static-contents/action.yml +++ b/publish-static-contents/action.yml @@ -13,8 +13,12 @@ inputs: description: Space-separated list of CloudFront distribution IDs to invalidate required: false default: '' - versioned_static_prefix: - description: S3 prefix under which versioned builds are stored (e.g. _static). When set, old versions older than 7 days are deleted, keeping at least the 2 newest. + versioning: + description: 'When set to true, enables versioned builds. Old versions older than 7 days are deleted, keeping at least the 2 newest.' + required: false + default: false + versioning_prefix: + description: 'S3 prefix under which versioned builds are stored (e.g. "_static" → _static/1234567890/). When omitted, versions are stored at the bucket root (e.g. 1234567890/).' required: false default: '' @@ -36,21 +40,25 @@ runs: env: INPUT_DIST_DIR: ${{ inputs.dist_dir }} INPUT_S3_BUCKET_NAME: ${{ inputs.s3_bucket_name }} - INPUT_VERSIONED_STATIC_PREFIX: ${{ inputs.versioned_static_prefix }} + INPUT_VERSIONING: ${{ inputs.versioning }} + INPUT_VERSIONING_PREFIX: ${{ inputs.versioning_prefix }} run: | CACHE_CONTROL_ARG="" - if [[ -n "${INPUT_VERSIONED_STATIC_PREFIX}" ]]; then + if [[ "${INPUT_VERSIONING}" == "true" ]]; then CACHE_CONTROL_ARG="--cache-control 'public, max-age=31536000, immutable'" fi EXCLUDE_INDEX_ARG="" - if [[ -n "${INPUT_VERSIONED_STATIC_PREFIX}" && -f "${INPUT_DIST_DIR}/index.html" ]]; then + if [[ "${INPUT_VERSIONING}" == "true" && -f "${INPUT_DIST_DIR}/index.html" ]]; then EXCLUDE_INDEX_ARG="--exclude index.html" fi aws s3 sync "${INPUT_DIST_DIR}" "s3://${INPUT_S3_BUCKET_NAME}" $CACHE_CONTROL_ARG $EXCLUDE_INDEX_ARG - name: Publish index.html without immutable cache - if: ${{ inputs.versioned_static_prefix != '' }} + if: ${{ inputs.versioning == 'true' }} shell: bash + env: + INPUT_DIST_DIR: ${{ inputs.dist_dir }} + INPUT_S3_BUCKET_NAME: ${{ inputs.s3_bucket_name }} run: | if [[ -f "${INPUT_DIST_DIR}/index.html" ]]; then aws s3 cp "${INPUT_DIST_DIR}/index.html" "s3://${INPUT_S3_BUCKET_NAME}/index.html" \ @@ -59,13 +67,18 @@ runs: fi - name: Clean up old versioned static builds - if: ${{ inputs.versioned_static_prefix != '' }} + if: ${{ inputs.versioning == 'true' }} shell: bash env: INPUT_S3_BUCKET_NAME: ${{ inputs.s3_bucket_name }} - INPUT_VERSIONED_STATIC_PREFIX: ${{ inputs.versioned_static_prefix }} + INPUT_VERSIONING_PREFIX: ${{ inputs.versioning_prefix }} run: | - aws s3 ls "s3://$INPUT_S3_BUCKET_NAME/$INPUT_VERSIONED_STATIC_PREFIX/" \ + S3_PATH="s3://$INPUT_S3_BUCKET_NAME" + if [[ -n "${INPUT_VERSIONING_PREFIX}" ]]; then + S3_PATH="s3://$INPUT_S3_BUCKET_NAME/$INPUT_VERSIONING_PREFIX" + fi + + aws s3 ls "${S3_PATH}/" \ | grep -oP '(?<=PRE )[0-9]+' \ | sort --stable --reverse \ | tail -n +3 \ @@ -75,7 +88,7 @@ runs: # delete if older than 7 days if [ $diff -gt 604800000 ]; then echo "Deleting $version" - aws s3 rm --recursive "s3://$INPUT_S3_BUCKET_NAME/$INPUT_VERSIONED_STATIC_PREFIX/$version" + aws s3 rm --recursive "${S3_PATH}/$version" fi done