Skip to content

Commit

Permalink
Merge pull request #128 from mittwald/task/functionaltests
Browse files Browse the repository at this point in the history
Add CI pipelines for testing the actual deployment functionality
  • Loading branch information
martin-helmich authored Apr 26, 2024
2 parents a4b78ab + 17d49a5 commit d39d5af
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Functional testing

on:
push:
branches: [ master ]
pull_request: {}

jobs:
build:
strategy:
max-parallel: 1
fail-fast: false
matrix:
php-versions: ['8.2', '8.3']
deployer-version: ['7.3']
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
path: 'git/mittwald-recipe'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, json
coverage: pcov

- name: Setup test project with composer
run: |
composer init --name mittwald/deployer-recipes-test --type project --repository '{"type":"path","url":"git/mittwald-recipe"}'
composer require --dev 'deployer/deployer:${{ matrix.deployer-version }}.*'
composer require --dev mittwald/deployer-recipes:dev-${GITHUB_SHA}
cp git/mittwald-recipe/functionaltest/deploy.php deploy.php
- name: Deploy testing SSH key
run: |
mkdir ~/.ssh
echo -n "${MITTWALD_SSH_PRIVATE_KEY}" | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub
env:
MITTWALD_SSH_PRIVATE_KEY: ${{ secrets.MITTWALD_SSH_PRIVATE_KEY }}

- name: Generate unique test file
run: |
openssl rand -hex 32 > testing.txt
- name: Run test deployment
run: |
./vendor/bin/dep deploy -vvv
env:
MITTWALD_APP_ID: ${{ secrets.MITTWALD_APP_ID }}
MITTWALD_APP_DOMAIN: ${{ secrets.MITTWALD_APP_DOMAIN }}
MITTWALD_API_TOKEN: ${{ secrets.MITTWALD_API_TOKEN }}

- name: Assert deployment was successful
run: |
deployed=$(curl -f -s https://${MITTWALD_APP_DOMAIN}/testing.txt)
expected=$(< testing.txt)
echo "::debug::got output: ${deployed}"
echo "::debug::expected: ${expected}"
test "${deployed}" = "${expected}"
env:
MITTWALD_APP_DOMAIN: ${{ secrets.MITTWALD_APP_DOMAIN }}
33 changes: 33 additions & 0 deletions functionaltest/deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Deployer;

require 'recipe/common.php';
require 'contrib/rsync.php';
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/mittwald/deployer-recipes/recipes/deploy.php';

// Config

set('rsync_src', __DIR__);
set('php_version', '8.2');
set('domain', getenv("MITTWALD_APP_DOMAIN"));

// Hosts

mittwald_app(getenv("MITTWALD_APP_ID"))
->set('public_path', '/');

// Hooks

task('deploy:prepare', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'rsync',
'deploy:shared',
'deploy:writable',
]);

after('deploy:failed', 'deploy:unlock');

0 comments on commit d39d5af

Please sign in to comment.