Branch Deployment #19
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: Branch Deployment | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
# all branches created from issue | |
- "[0-9]+-**" | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
jobs: | |
build: | |
name: Build Site | |
runs-on: ubuntu-latest | |
outputs: | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
steps: | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up config | |
working-directory: docs | |
env: | |
BASE_URL: ${{ steps.extract_branch.outputs.branch }} | |
run: | | |
echo "" >> _config.yml | |
echo "baseurl: /$BASE_URL" >> _config.yml | |
sed -i "s,tree/main,tree/$BASE_URL,g" _config.yml | |
cat _config.yml | |
- name: Build page | |
uses: actions/jekyll-build-pages@master | |
with: | |
source: ./docs | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: site | |
path: _site | |
retention-days: 1 | |
deploy: | |
name: Deploy to AWS | |
runs-on: ubuntu-latest | |
environment: | |
name: aws-development | |
url: ${{ steps.results.outputs.url }} | |
needs: build | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
BRANCH: ${{ needs.build.outputs.branch }} | |
steps: | |
- name: Dowload artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: site | |
path: _site | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.AWS_CLI_ROLE_ARN }} | |
role-session-name: docs-site-template-branch-deploy | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Deploy | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
run: | | |
aws s3 sync ./_site s3://${{ vars.AWS_BUCKET_NAME }}/${{ env.BRANCH }} --no-progress --follow-symlinks --delete | |
- name: Invalidate CloudFront | |
uses: chetan/invalidate-cloudfront-action@v2 | |
env: | |
DISTRIBUTION: ${{ vars.AWS_DISTRIBUTION_ID }} | |
PATHS: "/${{ env.BRANCH }}/*" | |
- name: Results | |
id: results | |
run: | | |
URL="${{ vars.AWS_WEBSITE_URL }}/${{ env.BRANCH }}" | |
echo "✔ Branch is successfully deploy to: $URL" >> $GITHUB_STEP_SUMMARY | |
echo "url=$URL" >> $GITHUB_OUTPUT |