Merge pull request #76 from gosh-sh/l2_fix_owerview #18
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
name: Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- dev | |
- ci | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }} | |
# default unless branch is 'main' | |
BUCKET_NAME: ${{ github.ref == 'refs/heads/main' && 'docs-gosh' || 'staging-docs-gosh' }} | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Setup policy | |
# pin python 3.11 | |
uses: ajeffowens/jinja2-action@90dab3da2215932ea86d2875224f06bbd6798617 | |
with: | |
template: .ci/s3/policy.json.j2 | |
output_file: site/policy.json | |
- name: Check if S3 Bucket Exists | |
working-directory: site | |
run: | | |
if aws s3api head-bucket --bucket "$BUCKET_NAME" ; then | |
echo 'Bucket already exists! Just syncing.' | |
else | |
aws s3api create-bucket --bucket "$BUCKET_NAME" --acl public-read --create-bucket-configuration LocationConstraint="$AWS_DEFAULT_REGION" | |
aws s3 website s3://"$BUCKET_NAME" --index-document index.html --error-document index.html | |
aws s3api put-bucket-policy --bucket "$BUCKET_NAME" --policy file://policy.json | |
fi | |
shell: bash | |
- name: Sync with S3 Bucket | |
working-directory: site | |
run: aws s3 sync . s3://"$BUCKET_NAME" | |
- name: Create invalidation | |
if: github.ref == 'refs/heads/main' | |
run: | | |
aws cloudfront create-invalidation --distribution-id E38B49XVCTNRVX --paths '/*' |