|
| 1 | +name: Deploy to Staging (AWS S3 + CloudFront) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ staging ] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + id-token: write # Required for AWS OIDC authentication |
| 10 | + |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + commit_lint: |
| 15 | + name: Validate Commit Messages |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Validate PR Title |
| 23 | + uses: wagoid/commitlint-github-action@v5 |
| 24 | + env: |
| 25 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + with: |
| 27 | + configFile: .commitlintrc.json |
| 28 | + build-and-deploy-staging: |
| 29 | + name: Build and Deploy to Staging |
| 30 | + needs: commit_lint |
| 31 | + runs-on: ubuntu-latest |
| 32 | + environment: |
| 33 | + name: aws-stag |
| 34 | + steps: |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + - name: Set up Python |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: '3.11' |
| 44 | + cache: 'pip' |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: | |
| 48 | + python -m pip install --upgrade pip |
| 49 | + pip install -r requirements.txt |
| 50 | +
|
| 51 | + - name: Build MkDocs site |
| 52 | + run: mkdocs build --strict --use-directory-urls |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Add staging banner to site |
| 57 | + run: | |
| 58 | + # Add a staging environment banner to all HTML files |
| 59 | + find site -name "*.html" -type f -exec sed -i.bak '/<body/a \ |
| 60 | + <div style="background:#ff9800;color:#000;text-align:center;padding:10px;font-weight:bold;">\ |
| 61 | + 🚧 STAGING ENVIRONMENT - NOT FOR PRODUCTION USE 🚧\ |
| 62 | + </div>' {} \; |
| 63 | + # Clean up backup files |
| 64 | + find site -name "*.bak" -type f -delete |
| 65 | +
|
| 66 | + - name: Configure AWS credentials |
| 67 | + uses: aws-actions/configure-aws-credentials@v4 |
| 68 | + with: |
| 69 | + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} |
| 70 | + aws-region: ${{ secrets.AWS_REGION }} |
| 71 | + |
| 72 | + - name: Sync to S3 (Staging) |
| 73 | + run: | |
| 74 | + aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \ |
| 75 | + --delete \ |
| 76 | + --cache-control "public, max-age=300" \ |
| 77 | + --exclude "*.html" \ |
| 78 | + --exclude "sitemap.xml" |
| 79 | +
|
| 80 | + # Upload HTML files with shorter cache for staging |
| 81 | + aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \ |
| 82 | + --cache-control "public, max-age=60, must-revalidate" \ |
| 83 | + --content-type "text/html; charset=utf-8" \ |
| 84 | + --exclude "*" \ |
| 85 | + --include "*.html" |
| 86 | +
|
| 87 | + # Upload sitemap with no cache |
| 88 | + aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \ |
| 89 | + --cache-control "public, max-age=0, must-revalidate" \ |
| 90 | + --exclude "*" \ |
| 91 | + --include "sitemap.xml" |
0 commit comments