Fetch, Build, and Deploy to Cloudflare Pages #431
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Fetch, Build, and Deploy to S3 | |
| on: | |
| workflow_dispatch: # Allow manual triggering | |
| schedule: | |
| - cron: "0 0 * * *" # Runs daily at midnight UTC | |
| jobs: | |
| fetch-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| # Step 1: Checkout the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Step 2: Setup Node.js | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| # Step 3: Install dependencies | |
| - name: Install dependencies | |
| run: npm install | |
| # Step 4: Run the fetchRepoData script | |
| - name: Fetch repository data | |
| run: node utils/fetchData/fetchRepoData.cjs | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Step 5: Build the project | |
| - name: Build the project | |
| run: npm run build | |
| # Step 6: Configure AWS Credentials | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_NUMBER }}:role/gh-action-fetch-build-deploy | |
| role-session-name: GitHub_to_AWS_via_FederatedOIDC | |
| aws-region: us-east-1 | |
| # Step 7: Sync to S3 | |
| - name: Sync to S3 | |
| uses: nojanath/s3-sync-action@master | |
| with: | |
| args: --delete | |
| env: | |
| AWS_S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }} | |
| AWS_REGION: us-east-1 | |
| SOURCE_DIR: ./dist | |
| # Step 8: Invalidate CloudFront Cache | |
| - name: Invalidate CloudFront Cache | |
| run: | | |
| aws cloudfront create-invalidation \ | |
| --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \ | |
| --paths "/*" |