-
Notifications
You must be signed in to change notification settings - Fork 3
54 lines (45 loc) · 1.5 KB
/
branch_deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Branch deploy preview
on:
workflow_dispatch:
inputs:
preview_branch:
description: 'Enter the branch name you wish to preview'
required: true
jobs:
branch_deploy_preview:
runs-on: ubuntu-latest
env:
PREVIEW_URL: https://deploy-preview--peaceful-wiles-97aae8.netlify.app
steps:
- name: Git clone repository
uses: actions/checkout@v4
- name: Fetch all commits
run: git fetch --all
- name: Remove deploy preview branch if it exists
run: |
result=$((git branch --all) 2>&1)
if [[ `echo $result` == *"deploy/preview"* ]];
then
git push origin --delete deploy/preview;
else
echo "deploy/preview branch does not exist";
fi
- name: Checkout preview branch
run: |
git checkout ${{ github.event.inputs.preview_branch }}
git fetch
git checkout -b deploy/preview
git fetch
- name: Merge into deploy/preview branch
run: |
git merge ${{ github.event.inputs.preview_branch }}
- name: Push deploy_preview branch
run: |
git push origin deploy/preview
- name: Deploy preview branch
run: |
curl -X POST -d {} ${{ secrets.BRANCH_DEPLOY_TOKEN }}
- name: Check deployment
run: |
timeout 900 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${PREVIEW_URL})" != "200" ]]; do sleep 30; done' || false
echo "The branch is deployed & ready to preview - ${PREVIEW_URL}"