Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: use branch name for PR deployments + prettify the comment #1288

Merged
merged 8 commits into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write

name: Deploy to dev/staging

steps:
- name: Cancel previous runs
uses: styfle/[email protected]
Expand All @@ -20,6 +24,18 @@ jobs:

- uses: actions/checkout@v3

# 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]'

- name: Install Node modules
run: yarn install --immutable

Expand Down Expand Up @@ -62,19 +78,33 @@ jobs:
BUCKET: s3://${{ secrets.AWS_DEVELOPMENT_BUCKET_NAME }}
run: bash ./scripts/github/s3_upload.sh

# PRs
### PRs ###

# Extract branch name
- name: Extract branch name
shell: bash
## Cut off "refs/heads/" and replace slashes with dashes, e.g. "refs/heads/features/hello" -> "features-hello"
run: echo "##[set-output name=branch;]$(echo $GITHUB_HEAD_REF | sed 's/refs\/heads\///' | sed 's/\//-/g')"
id: extract_branch

# Deploy to S3
- name: Deploy PR branch
if: github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/main'
if: github.event.number
env:
BUCKET: s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/webcore/pr${{ github.event.number }}
BUCKET: s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/webcore/${{ steps.extract_branch.outputs.branch }}
run: bash ./scripts/github/s3_upload.sh

- name: 'Post the deployment links in the PR'
if: success() && github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/main'
uses: mshick/add-pr-comment@v1
# Comnment
- name: Post a deployment link in the PR
if: always() && github.event.number
uses: mshick/add-pr-comment@v2
with:
message-id: praul
message: |
## Branch preview
https://pr${{ github.event.number }}--webcore.review-web-core.5afe.dev
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'
✅ Deploy successful!

https://${{ steps.extract_branch.outputs.branch }}--webcore.review-web-core.5afe.dev
message-failure: |
## Branch preview
❌ Deploy failed!