203 lines
6.3 KiB
YAML
203 lines
6.3 KiB
YAML
name: E2E Tests
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
version:
|
|
required: true
|
|
type: string
|
|
description: 'Version to test (e.g. v1.6.0-beta.1)'
|
|
outputs:
|
|
page_url:
|
|
description: 'URL of the deployed report'
|
|
value: ${{ jobs.report-deployment.outputs.page_url }}
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
required: true
|
|
type: string
|
|
description: 'Version to test (e.g. v1.6.0-beta.1)'
|
|
|
|
jobs:
|
|
deploy:
|
|
timeout-minutes: 15
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
droplet_id: ${{ steps.create-droplet.outputs.droplet_id }}
|
|
droplet_ip: ${{ steps.get-droplet-ip.outputs.droplet_ip }}
|
|
postgres_password: ${{ steps.get-postgres-password.outputs.postgres_password }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install SSH key
|
|
uses: shimataro/ssh-key-action@v2
|
|
with:
|
|
key: ${{ secrets.SSH_KEY }}
|
|
known_hosts: unnecessary
|
|
name: id_rsa
|
|
|
|
- name: Get sha of last commit
|
|
id: get-sha
|
|
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Install doctl
|
|
uses: digitalocean/action-doctl@v2
|
|
with:
|
|
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
|
|
|
|
- name: Create new Droplet
|
|
id: create-droplet
|
|
run: |
|
|
droplet_id=$(doctl compute droplet create runtipi-${{ steps.get-sha.outputs.sha }} \
|
|
--image ubuntu-20-04-x64 \
|
|
--size s-1vcpu-1gb \
|
|
--format ID \
|
|
--no-header \
|
|
--ssh-keys ${{ secrets.SSH_KEY_FINGERPRINT }})
|
|
echo "droplet_id=$droplet_id" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for Droplet to become active
|
|
run: |
|
|
while ! doctl compute droplet get ${{ steps.create-droplet.outputs.droplet_id }} --format Status --no-header | grep -q "active"; do sleep 5; done
|
|
|
|
- name: Get Droplet IP address
|
|
id: get-droplet-ip
|
|
run: |
|
|
droplet_ip=$(doctl compute droplet get ${{ steps.create-droplet.outputs.droplet_id }} --format PublicIPv4 --no-header)
|
|
echo "droplet_ip=$droplet_ip" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for SSH to be ready on Droplet
|
|
run: |
|
|
while ! ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ steps.get-droplet-ip.outputs.droplet_ip }} "echo 'SSH is ready'"; do sleep 5; done
|
|
|
|
- name: Create docker group on Droplet
|
|
uses: fifsky/ssh-action@master
|
|
with:
|
|
command: |
|
|
groupadd docker
|
|
usermod -aG docker root
|
|
host: ${{ steps.get-droplet-ip.outputs.droplet_ip }}
|
|
user: root
|
|
key: ${{ secrets.SSH_KEY }}
|
|
|
|
- name: Wait 90 seconds for Docker to be ready on Droplet
|
|
run: sleep 90
|
|
|
|
- name: Deploy app to Droplet
|
|
uses: fifsky/ssh-action@master
|
|
with:
|
|
command: |
|
|
echo 'Downloading install script from GitHub'
|
|
curl -s https://raw.githubusercontent.com/runtipi/runtipi/${{ inputs.version }}/scripts/install.sh > install.sh
|
|
chmod +x install.sh
|
|
echo 'Running install script'
|
|
./install.sh --version ${{ inputs.version }}
|
|
echo 'App deployed'
|
|
host: ${{ steps.get-droplet-ip.outputs.droplet_ip }}
|
|
user: root # TODO: use non-root user
|
|
key: ${{ secrets.SSH_KEY }}
|
|
|
|
- name: Get POSTGRES_PASSWORD from .env file
|
|
id: get-postgres-password
|
|
run: |
|
|
postgres_password=$(ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ steps.get-droplet-ip.outputs.droplet_ip }} "cat ./runtipi/.env | grep POSTGRES_PASSWORD | cut -d '=' -f2")
|
|
echo "postgres_password=$postgres_password" >> $GITHUB_OUTPUT
|
|
|
|
e2e:
|
|
timeout-minutes: 30
|
|
runs-on: ubuntu-latest
|
|
needs: [deploy]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: pnpm/action-setup@v2.4.0
|
|
name: Install pnpm
|
|
id: pnpm-install
|
|
with:
|
|
version: 8
|
|
run_install: false
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-cache
|
|
run: |
|
|
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
|
|
|
|
- uses: actions/cache@v3
|
|
name: Setup pnpm cache
|
|
with:
|
|
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
|
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-store-
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Create .env.e2e file with Droplet IP
|
|
run: |
|
|
echo "SERVER_IP=${{ needs.deploy.outputs.droplet_ip }}" > .env.e2e
|
|
echo "POSTGRES_PASSWORD=${{ needs.deploy.outputs.postgres_password }}" >> .env.e2e
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install
|
|
|
|
- name: Install Playwright Browsers
|
|
run: npx playwright install --with-deps
|
|
|
|
- name: Run Playwright tests
|
|
id: run-e2e
|
|
run: npm run test:e2e
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
if: always()
|
|
with:
|
|
name: playwright-report
|
|
path: playwright-report/
|
|
retention-days: 7
|
|
|
|
report-deployment:
|
|
runs-on: ubuntu-latest
|
|
needs: [e2e]
|
|
outputs:
|
|
page_url: ${{ steps.deployment.outputs.page_url }}
|
|
permissions:
|
|
pages: write # to deploy to Pages
|
|
id-token: write # to verify the deployment originates from an appropriate source
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
if: always()
|
|
steps:
|
|
- name: Download report artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: playwright-report
|
|
path: playwright-report/
|
|
|
|
- name: Setup Pages
|
|
uses: actions/configure-pages@v3
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-pages-artifact@v2
|
|
with:
|
|
path: playwright-report/
|
|
|
|
- name: Deploy to GitHub Pages
|
|
id: deployment
|
|
uses: actions/deploy-pages@v2
|
|
|
|
teardown:
|
|
runs-on: ubuntu-latest
|
|
if: always()
|
|
needs: [e2e, deploy]
|
|
steps:
|
|
- name: Install doctl
|
|
uses: digitalocean/action-doctl@v2
|
|
with:
|
|
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
|
|
|
|
- name: Delete Droplet
|
|
run: doctl compute droplet delete ${{ needs.deploy.outputs.droplet_id }} --force
|