Skip to content

Commit bb55f91

Browse files
authored
Merge pull request #36 from PythonMexico/staging
Staging
2 parents a62b5d5 + e3891c8 commit bb55f91

37 files changed

+2202
-549
lines changed

.commitlintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"]
3+
}

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ jobs:
5555
echo "✅ All links working!"
5656
pkill -f "mkdocs serve" || true
5757
58-
# Solo para main: guardar el sitio construido
58+
# Upload build artifact for validation/review
5959
- name: Upload build artifact
60-
if: github.ref == 'refs/heads/main'
6160
uses: actions/upload-artifact@v4
6261
with:
6362
name: site
6463
path: site/
65-
retention-days: 1
64+
retention-days: 3

.github/workflows/ci-cd.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/deploy-aws.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Deploy to AWS S3 + CloudFront
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: read
9+
id-token: write # Required for AWS OIDC authentication
10+
11+
12+
jobs:
13+
commit_lint:
14+
name: Validate Commit Messages
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Validate PR Title
22+
uses: wagoid/commitlint-github-action@v5
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
with:
26+
configFile: .commitlintrc.json
27+
28+
build-and-deploy:
29+
needs: commit_lint
30+
name: Build and Deploy to AWS
31+
runs-on: ubuntu-latest
32+
environment:
33+
name: aws-prod
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: Configure AWS credentials
57+
uses: aws-actions/configure-aws-credentials@v4
58+
with:
59+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
60+
aws-region: ${{ secrets.AWS_REGION }}
61+
62+
- name: Sync to S3
63+
run: |
64+
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
65+
--delete \
66+
--cache-control "public, max-age=3600" \
67+
--exclude "*.html" \
68+
--exclude "sitemap.xml"
69+
70+
# Upload HTML files with shorter cache
71+
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
72+
--cache-control "public, max-age=600, must-revalidate" \
73+
--content-type "text/html; charset=utf-8" \
74+
--exclude "*" \
75+
--include "*.html"
76+
77+
# Upload sitemap with no cache
78+
aws s3 sync site/ s3://${{ secrets.AWS_S3_BUCKET }}/ \
79+
--cache-control "public, max-age=0, must-revalidate" \
80+
--exclude "*" \
81+
--include "sitemap.xml"
82+
83+
cleanup-staging:
84+
name: Stop Staging Site
85+
needs: build-and-deploy
86+
runs-on: ubuntu-latest
87+
environment:
88+
name: aws-stag
89+
steps:
90+
- name: Configure AWS credentials
91+
uses: aws-actions/configure-aws-credentials@v4
92+
with:
93+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
94+
aws-region: ${{ secrets.AWS_REGION }}
95+
96+
- name: Stop Staging Site
97+
run: |
98+
aws s3 rm s3://${{ secrets.AWS_S3_BUCKET }}/staging/ --recursive
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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"

.github/workflows/deploy.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,6 @@ Thumbs.db
271271
# Temporary files
272272
*.tmp
273273
*.temp
274+
275+
# Generated files
276+
broken_links.json

0 commit comments

Comments
 (0)