Skip to content

Commit ac48737

Browse files
committed
feat: add GitHub Actions workflow for deploying Jekyll site to S3
1 parent 8578bc4 commit ac48737

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

.github/workflows/deploy-site.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Deploy Jekyll Site
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "_config.yml"
9+
- "_data/**"
10+
- "_includes/**"
11+
- "_layouts/**"
12+
- "_pages/**"
13+
- "_posts/**"
14+
- "assets/**"
15+
- "presentations/**"
16+
- "Gemfile"
17+
- "Gemfile.lock"
18+
- ".github/workflows/deploy-site.yml"
19+
workflow_dispatch:
20+
21+
permissions:
22+
id-token: write
23+
contents: read
24+
25+
env:
26+
AWS_REGION: us-east-1
27+
S3_BUCKET: gcharest-ca-website
28+
RUBY_VERSION: "3.2"
29+
30+
concurrency:
31+
group: deploy-site
32+
cancel-in-progress: false
33+
34+
jobs:
35+
deploy:
36+
name: Build and Deploy Site
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Setup Ruby
43+
uses: ruby/setup-ruby@v1
44+
with:
45+
ruby-version: ${{ env.RUBY_VERSION }}
46+
bundler-cache: true
47+
48+
- name: Install dependencies
49+
run: |
50+
bundle install
51+
52+
- name: Build Jekyll site
53+
run: |
54+
JEKYLL_ENV=production bundle exec jekyll build
55+
56+
- name: Configure AWS credentials
57+
uses: aws-actions/configure-aws-credentials@v4
58+
with:
59+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-terragrunt-role
60+
aws-region: ${{ env.AWS_REGION }}
61+
role-session-name: github-deploy-site
62+
63+
- name: Upload to S3
64+
run: |
65+
aws s3 sync _site/ s3://${{ env.S3_BUCKET }}/ \
66+
--delete \
67+
--cache-control "public, max-age=3600" \
68+
--exclude "*.html" \
69+
--exclude "manifest.json"
70+
71+
# Upload HTML files with shorter cache
72+
aws s3 sync _site/ s3://${{ env.S3_BUCKET }}/ \
73+
--exclude "*" \
74+
--include "*.html" \
75+
--cache-control "public, max-age=300"
76+
77+
# Upload manifest with no cache
78+
aws s3 sync _site/ s3://${{ env.S3_BUCKET }}/ \
79+
--exclude "*" \
80+
--include "manifest.json" \
81+
--cache-control "no-cache, no-store, must-revalidate"
82+
83+
- name: Get CloudFront Distribution ID
84+
id: cloudfront
85+
run: |
86+
DISTRIBUTION_ID=$(aws cloudfront list-distributions \
87+
--query "DistributionList.Items[?Comment=='Blog distribution for gcharest'].Id | [0]" \
88+
--output text)
89+
echo "distribution_id=$DISTRIBUTION_ID" >> $GITHUB_OUTPUT
90+
91+
- name: Invalidate CloudFront cache
92+
if: steps.cloudfront.outputs.distribution_id != 'None' && steps.cloudfront.outputs.distribution_id != ''
93+
run: |
94+
aws cloudfront create-invalidation \
95+
--distribution-id ${{ steps.cloudfront.outputs.distribution_id }} \
96+
--paths "/*"
97+
98+
- name: Deployment summary
99+
if: success()
100+
run: |
101+
echo "## ✅ Site Deployed Successfully" >> $GITHUB_STEP_SUMMARY
102+
echo "" >> $GITHUB_STEP_SUMMARY
103+
echo "**Website URL:** https://www.gcharest.ca/" >> $GITHUB_STEP_SUMMARY
104+
echo "" >> $GITHUB_STEP_SUMMARY
105+
echo "**S3 Bucket:** ${{ env.S3_BUCKET }}" >> $GITHUB_STEP_SUMMARY
106+
if [ -n "${{ steps.cloudfront.outputs.distribution_id }}" ]; then
107+
echo "**CloudFront Distribution:** ${{ steps.cloudfront.outputs.distribution_id }}" >> $GITHUB_STEP_SUMMARY
108+
fi

0 commit comments

Comments
 (0)