Skip to content

Commit

Permalink
chore: branch named PR deployment (#266)
Browse files Browse the repository at this point in the history
* chore: add epic PR deployment step

* remove if

* if PR and starts with `epic-`

* chore: deploy epic PR branch

* chore: update job title

* chore: replace `dev` deployment for branch name deployment
  • Loading branch information
DiogoSoaress authored Feb 6, 2024
1 parent 73dc4c9 commit fb7e5ea
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to dev/staging
name: Deploy

on:
pull_request:
Expand All @@ -12,14 +12,26 @@ jobs:
runs-on: ubuntu-latest
permissions: write-all

name: Deploy to dev/staging
name: Deploy to S3

steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}

# Post a PR comment before deploying
- name: Post a comment while building
if: github.event.number
uses: mshick/add-pr-comment@v2
with:
message-id: praul
message: |
## Branch preview
⏳ Deploying a preview site...
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'

- uses: actions/checkout@v3

- uses: ./.github/workflows/yarn
Expand All @@ -30,11 +42,10 @@ jobs:
is-production: false

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

# Deploy the main branch to staging
- name: Deploy to the staging S3
Expand All @@ -43,24 +54,31 @@ jobs:
BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current
run: bash ./scripts/github/s3_upload.sh

# Deploy all other branches to dev
- name: Deploy to the dev S3
if: github.ref != 'refs/heads/main'
# Extract branch name
- name: Extract branch name
shell: bash
## Allow only alphanumeric characters and convert to lower case,
run: echo "branch=$(echo $GITHUB_HEAD_REF | sed 's/[^a-z0-9]/_/ig' | sed 's/[A-Z]/\L&/g')" >> $GITHUB_OUTPUT
id: extract_branch

# Deploy to S3
- name: Deploy PR branch
if: github.event.number
env:
BUCKET: s3://${{ secrets.AWS_DEVELOPMENT_BUCKET_NAME }}
BUCKET: s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/homepage/${{ steps.extract_branch.outputs.branch }}
run: bash ./scripts/github/s3_upload.sh

# Comment
- name: Post a deployment link in the PR
# Comment with the deployment link
- name: Post an epic deployment link in the PR
if: always() && github.event.number
uses: mshick/add-pr-comment@v2
with:
message-id: praul
message: |
## Branch preview
✅ Deployed to dev:
✅ Deployed successfully in branch deployment:
https://safe-web-landing.dev.5afe.dev
https://${{ steps.extract_branch.outputs.branch }}--homepage.review.5afe.dev
message-failure: |
## Branch preview
❌ Deploy failed!

0 comments on commit fb7e5ea

Please sign in to comment.