wip Fix #1133 I can configure plan prorations as a shop owner #1746
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
--- | |
# 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: | |
workflow_dispatch: # Allow choosing from which branch to run action on | |
pull_request: | |
# (pull_request_target get fired on external contributor 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@v4 | |
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 doesn't 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 }}" | |
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} SERVER_NAME=${{ env.SUBDOMAIN }}.pcpink.co.uk" | |
# mount email-queue folder | |
ssh dokku@$DOKKU_HOST -C "dokku storage:mount ${{ env.SUBDOMAIN }} ${{ secrets.HOST_EMAIL_QUEUE_PATH }}:${{ secrets.DOKKU_EMAIL_QUEUE_FOLDER }} && dokku ps:restart ${{ env.SUBDOMAIN }} || true" | |
echo Disable dokku checks until healthchecks updated | |
ssh dokku@$DOKKU_HOST -C "dokku checks:disable ${{ env.SUBDOMAIN }}" | |
echo Clear and then set dokku ports map | |
ssh dokku@$DOKKU_HOST -C "dokku ports:clear ${{ env.SUBDOMAIN }}" | |
ssh dokku@$DOKKU_HOST -C "dokku ports:add ${{ env.SUBDOMAIN }} http:80:5000" | |
- 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 | |
- name: Install playwright dependencies | |
run: npm ci | |
- name: Install playwright browsers | |
run: npx playwright install --with-deps | |
- name: Install graphviz | |
run: | | |
sudo apt-get install graphviz | |
- name: Run & Record browser automated tests (Playwright) | |
env: | |
# TODO these envs arn't read- update yaml settings loading | |
# to read from environment and have those take precedence | |
# if set just like before when using .env | |
# see tests/browser-automated-tests-playwright/playwright.config.ts | |
# to update. | |
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 settings.yaml.example settings.yaml | |
# Update all settings which point to localhost (the default) to the pr-preview url | |
sed -i "s|127.0.0.1:5000|${{ env.SUBDOMAIN }}.pcpink.co.uk|g" settings.yaml | |
cd tests/browser-automated-tests-playwright | |
pip3 install -r requirements.txt | |
python3 run-playwright-tests.py | |
- uses: actions/upload-artifact@v4 | |
if: ${{ always() }} | |
with: | |
name: Screenshots-and-video-artifacts | |
path: | | |
./tests/browser-automated-tests-playwright/test-videos |