-
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 2.63 KB
/
docs-deploy.yml
File metadata and controls
94 lines (80 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Deploy Documentation
on:
push:
branches: [main]
paths:
- 'docs/**'
- '.github/workflows/docs-deploy.yml'
- 'package.json'
- 'package-lock.json'
workflow_dispatch:
jobs:
build:
name: Build Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build documentation
run: npm run docs:build
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: docs-dist
path: docs/.vitepress/dist/
retention-days: 1
deploy:
name: Deploy to AWS S3
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
id-token: write
contents: read
steps:
- name: Download build artifact
uses: actions/download-artifact@v8
with:
name: docs-dist
path: dist/
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
aws-region: us-east-2
- name: Determine S3 bucket name
id: bucket
run: |
BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')
BUCKET_NAME="php-k8s-${BRANCH}-us-east-2-${{ secrets.AWS_ACCOUNT_ID }}"
echo "name=${BUCKET_NAME}" >> $GITHUB_OUTPUT
echo "Deploying to bucket: ${BUCKET_NAME}"
- name: Sync to S3
run: |
aws s3 sync dist/ s3://${{ steps.bucket.outputs.name }}/ \
--delete \
--cache-control "public, max-age=3600" \
--exclude "*.map"
- name: Invalidate CloudFront cache
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/*"
- name: Deployment summary
run: |
echo "### Deployment Complete :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Documentation has been deployed to:" >> $GITHUB_STEP_SUMMARY
echo "- **S3 Bucket**: \`${{ steps.bucket.outputs.name }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **URL**: https://php-k8s.cuppett.dev" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "CloudFront cache has been invalidated." >> $GITHUB_STEP_SUMMARY