-
Notifications
You must be signed in to change notification settings - Fork 21
132 lines (125 loc) · 5.78 KB
/
pr-demo-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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
# When a push is made to a branch, deploy an instance of the app using
# that branch.
# The deployed url will be <branchname>.<domain>
name: Deploy pr preview
on:
pull_request:
# (pull_request_target get fired on external contributer pull requests)
#pull_request_target
paths-ignore:
- '**/README.md'
- '**/TESTING.md'
- 'docs/**'
jobs:
deploy-pr:
runs-on: ubuntu-22.04
timeout-minutes: 60
environment: testing
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- name: Dump context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo $GITHUB_CONTEXT
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: psf/black@stable # Fail early if fails Black code style
- name: Prepare runner with ssh keys
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
set -x
mkdir -p ~/.ssh
eval `ssh-agent -s`
ssh-add - <<< "$SSH_PRIVATE_KEY"
ssh-keyscan $DOKKU_HOST >> ~/.ssh/known_hosts
- name: Set subdomain (ensure is lowercase for dokku)
run: |
set -x
# Enforce max 60 chars, always end with alnum char
echo SUBDOMAIN=`echo "${{ github.head_ref }}" | tr '[:upper:]' '[:lower:]' | cut -c -60 | rev | sed 's/[^[:alnum:]]//1' | rev` >> $GITHUB_ENV
echo $GITHUB_ENV
- name: Create dokku app for pr branch if dosent already exist using dokku apps:create
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
set -x
echo The PR was raised by: ${{ github.event.pull_request.user.login }}
eval `ssh-agent -s`
ssh-add - <<< "$SSH_PRIVATE_KEY"
echo Creating dokku app ${{ env.SUBDOMAIN }}.pcpink.co.uk/
ssh dokku@$DOKKU_HOST -C "dokku apps:create ${{ env.SUBDOMAIN }}" | true
echo The url will be ${{ env.SUBDOMAIN }}.pcpink.co.uk
ssh dokku@$DOKKU_HOST -C "dokku git:initialize ${{ env.SUBDOMAIN }}"
ssh dokku@$DOKKU_HOST -C "dokku git:set ${{ env.SUBDOMAIN }} deploy-branch ${{ github.head_ref }}"
# set Stripe test keys as env vars dor dokku/docker
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_TEST_SECRET_KEY=${{ secrets.STRIPE_TEST_SECRET_KEY }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_TEST_PUBLISHABLE_KEY=${{ secrets.STRIPE_TEST_PUBLISHABLE_KEY }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST=${{ secrets.STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} FLASK_ENV=development"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} EMAIL_QUEUE_FOLDER=${{ secrets.DOKKU_EMAIL_QUEUE_FOLDER }}"
# mount email-queue folder
ssh dokku@$DOKKU_HOST -C "dokku storage:mount ${{ github.head_ref }} ${{ secrets.HOST_EMAIL_QUEUE_PATH }}:${{ secrets.DOKKU_EMAIL_QUEUE_FOLDER }} && dokku ps:restart ${{ github.head_ref }} || true"
- name: Deploy branch ${{ github.head_ref }} to dokku
uses: idoberko2/dokku-deploy-github-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
dokku-host: ${{ secrets.DOKKU_HOST }}
app-name: ${{ env.SUBDOMAIN }}
git-push-flags: '--force'
remote-branch: ${{ github.head_ref }}
- name: Click to see your PR web address
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
echo Visit your pr here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk
- name: 'Comment PR with web address of application live preview'
uses: actions/github-script@v3
if: github.event_name == 'pull_request'
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "🙌 Live preview is here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk"
})
- uses: actions/setup-node@v3
- uses: microsoft/playwright-github-action@v1
- name: Install node dependencies needed for Playwright browser tests
run: |
npm i -D @playwright/[email protected]
npx playwright install
sudo npx playwright install-deps
- name: Run & Record browser automated tests (Playwright)
env:
PLAYWRIGHT_HOST: http://${{ env.SUBDOMAIN }}.pcpink.co.uk/
PLAYWRIGHT_SLOWMO: 1000
PLAYWRIGHT_HEADLESS: true
SUBSCRIBER_EMAIL_HOST: ${{ secrets.SUBSCRIBER_EMAIL_HOST }}
SUBSCRIBER_EMAIL_USER: ${{ secrets.SUBSCRIBER_EMAIL_USER }}
SUBSCRIBER_EMAIL_PASSWORD: ${{ secrets.SUBSCRIBER_EMAIL_PASSWORD }}
EMAIL_SEARCH_API_HOST: ${{ secrets.EMAIL_SEARCH_API_HOST }}
RESET_PASSWORD_IMAP_SEARCH_SUBJECT: ${{ secrets.RESET_PASSWORD_IMAP_SEARCH_SUBJECT }}
IMAP_SEARCH_UNSEEN: "1"
IMAP_SEARCH_SINCE_DATE: "01-Sep-2022"
run: |
set -x
cp tests/browser-automated-tests-playwright/.env.example tests/browser-automated-tests-playwright/.env
cp .env.example .env
cd tests/browser-automated-tests-playwright
python3 run-playwright-tests.py
- uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: Screenshots-and-video-artifacts
path: |
./tests/browser-automated-tests-playwright/test-videos