Skip to content

Update S3 Cache-Control #18

Update S3 Cache-Control

Update S3 Cache-Control #18

name: Update S3 Cache-Control
on:
schedule:
- cron: "0 0 * * *" # This runs daily at midnight UTC.
workflow_dispatch:
jobs:
update-cache-control:
runs-on: ubuntu-latest
steps:
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-1"
- name: Update S3 Cache-Control
run: |
BUCKET_NAME="neofoodclub"
CACHE_CONTROL_VALUE="public, max-age=31536000"
DAYS_OLD=2
# Curl the URL and store the result in a variable
current_round=$(curl -s https://cdn.neofood.club/current_round.txt)
# Subtract DAYS_OLD from the current round
let previous_round=current_round-DAYS_OLD
# Update the Cache-Control header for that objects data
aws s3api copy-object --bucket $BUCKET_NAME --key "rounds/$previous_round.json" --copy-source "$BUCKET_NAME/rounds/$previous_round.json" --metadata-directive REPLACE --cache-control "$CACHE_CONTROL_VALUE"
echo "Cache-Control updated for: rounds/$previous_round.json"