-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mukhtar Mukhtar
committed
Aug 2, 2024
1 parent
1590e2d
commit 4346521
Showing
6 changed files
with
196 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Deploy PR Preview cannabis.ca.gov | ||
# site: https://[branch-name].pr.cannabis.ca.gov | ||
# s3 bucket http://pr.cannabis.ca.gov.s3-website-us-west-1.amazonaws.com/ | ||
# editor: https://api.cannabis.ca.gov | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- ready_for_review | ||
- reopened | ||
jobs: | ||
build_deploy: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: n1hility/cancel-previous-runs@v2 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@master | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18.16.0 | ||
- name: Get branch name (merge) | ||
if: github.event_name != 'pull_request' | ||
shell: bash | ||
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV | ||
- name: Get branch name (pull request) | ||
if: github.event_name == 'pull_request' | ||
shell: bash | ||
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV | ||
- name: Escape branch name for URL | ||
shell: bash | ||
run: echo "URLSAFE_BRANCH_NAME=$(echo ${BRANCH_NAME} | tr '[:upper:]' '[:lower:]' | sed 's|[^A-Za-z0-9-]|-|g' | sed -E 's|-*([A-Za-z0-9]*.*[A-Za-z0-9]+)-*|\1|')" >> $GITHUB_ENV | ||
- name: Report escaped branch name | ||
shell: bash | ||
run: echo ${URLSAFE_BRANCH_NAME} | ||
- name: Build 11ty | ||
run: | | ||
mkdir dist | ||
npm ci --legacy-peer-deps | ||
SITE_ENV=production DOMAIN=${URLSAFE_BRANCH_NAME}.pr.cannabis.ca.gov npm run build | ||
- name: Write robots.txt | ||
run: | | ||
echo 'User-agent: *' > docs/robots.txt | ||
echo 'Disallow: /' >> docs/robots.txt | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-west-1 | ||
# jbum added exclude | ||
- name: Deploy to S3 | ||
run: aws s3 sync --follow-symlinks --delete ./docs s3://pr.cannabis.ca.gov/pr/${URLSAFE_BRANCH_NAME} --exclude 'wp-content/uploads/*' | ||
- name: Invalidate CloudFront cache | ||
run: aws cloudfront create-invalidation --distribution-id ELR9BZ6ZDNOSW --paths "/*" | ||
- name: Post URL to PR | ||
uses: mshick/add-pr-comment@v1 | ||
with: | ||
message: | | ||
Preview site available at [${{ env.URLSAFE_BRANCH_NAME }}.pr.cannabis.ca.gov](https://${{ env.URLSAFE_BRANCH_NAME }}.pr.cannabis.ca.gov/). | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
repo-token-user-login: 'github-actions[bot]' | ||
allow-repeats: false |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: 11ty build Staging Site | ||
# site: https://staging.cannabis.ca.gov | ||
# s3 bucket http://staging.cannabis.ca.gov.s3-website-us-west-1.amazonaws.com/ | ||
# editor: https://api.cannabis.ca.gov | ||
on: | ||
workflow_run: | ||
workflows: ["Update static content [staging]"] | ||
types: ['completed'] | ||
branches: | ||
- staging | ||
push: | ||
branches: | ||
- staging | ||
|
||
concurrency: | ||
group: sync_staging_deployments | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build_deploy: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-node@master | ||
with: | ||
node-version: 18.16.0 | ||
cache: 'npm' | ||
- name: Install packages | ||
run: | | ||
mkdir dist | ||
npm ci --production | ||
- name: Build 11ty | ||
run: | | ||
SITE_ENV=staging DOMAIN=staging.cannabis.ca.gov npm run build | ||
- name: Write robots.txt | ||
run: | | ||
echo 'User-agent: *' > docs/robots.txt | ||
echo 'Disallow: /' >> docs/robots.txt | ||
# deploy built files to separate branch that contains only built files that github pages uses to serve site | ||
- name: Deploy to github pages branch | ||
uses: peaceiris/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./docs | ||
publish_branch: deploy_staging | ||
|
||
# Set up AWS CLI | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-west-1 | ||
|
||
- name: Deploy to S3 (staging.cannabis.ca.gov) | ||
run: aws s3 sync --follow-symlinks --delete ./docs s3://staging.cannabis.ca.gov --exclude 'wp-content/uploads/*' | ||
|
||
# Reset the cache-control headers on static assets on S3 bucket | ||
- name: Reset cache-control on static files | ||
uses: prewk/s3-cp-action@v2 | ||
with: | ||
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws_region: 'us-west-1' # optional: defaults to us-east-1 | ||
source: './docs/fonts' | ||
dest: 's3://staging.cannabis.ca.gov/fonts' | ||
flags: --recursive --cache-control max-age=15552000 | ||
- name: Reset cache-control on assets | ||
uses: prewk/s3-cp-action@v2 | ||
with: | ||
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws_region: 'us-west-1' # optional: defaults to us-east-1 | ||
source: './docs/assets' | ||
dest: 's3://staging.cannabis.ca.gov/assets' | ||
flags: --recursive --cache-control max-age=15552000 | ||
|
||
|
||
# - name: Deploy redirects | ||
# run: | | ||
# AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} npm run deploy:redirects | ||
|
||
# Invalidate Cloudfront production distribution | ||
- name: Invalidate Cloudfront (cannabis.ca.gov) | ||
run: aws cloudfront create-invalidation --distribution-id EQTK6QDHAMA8Z --paths "/*" |