From 0d1f3f40a2211899dd254fd3fdd473617a5c76a0 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Wed, 24 Apr 2024 13:37:20 +0200 Subject: [PATCH 1/9] Add CI pipelines for testing the actual deployment functionality --- .github/workflows/functional.yml | 42 ++++++++++++++++++++++++++++++++ functionaltest/deploy.php | 34 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/functional.yml create mode 100644 functionaltest/deploy.php diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml new file mode 100644 index 0000000..52bce99 --- /dev/null +++ b/.github/workflows/functional.yml @@ -0,0 +1,42 @@ +name: Functional testing + +on: + push: + branches: [ master ] + pull_request: {} + +jobs: + build: + strategy: + matrix: + php-versions: ['8.2', '8.3'] + deployer-version: ['7.3', '7.4'] + runs-on: ubuntu-latest + concurrency: foo + + 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: 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 }} diff --git a/functionaltest/deploy.php b/functionaltest/deploy.php new file mode 100644 index 0000000..8344f9f --- /dev/null +++ b/functionaltest/deploy.php @@ -0,0 +1,34 @@ +set('public_path', '{{typo3_webroot}}'); + +// Hooks + +task('deploy:prepare', [ + 'deploy:info', + 'deploy:setup', + 'deploy:lock', + 'deploy:release', + 'rsync', + 'deploy:shared', + 'deploy:writable', +]); + +after('deploy:failed', 'deploy:unlock'); \ No newline at end of file From d39b8775b10c97407181bb21e633fc6b4dc9901c Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Wed, 24 Apr 2024 16:40:55 +0200 Subject: [PATCH 2/9] Deploy SSH key for testing --- .github/workflows/functional.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 52bce99..03da00c 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -33,6 +33,15 @@ jobs: 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: Run test deployment run: | ./vendor/bin/dep deploy -vvv From 9f5d77cfcf7d816dae1f35d1a79e7a6ed56f3346 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Wed, 24 Apr 2024 16:42:42 +0200 Subject: [PATCH 3/9] Control concurrency correctly --- .github/workflows/functional.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 03da00c..86b9482 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -8,11 +8,11 @@ on: jobs: build: strategy: + max-parallel: 1 matrix: php-versions: ['8.2', '8.3'] deployer-version: ['7.3', '7.4'] runs-on: ubuntu-latest - concurrency: foo steps: - uses: actions/checkout@v4 From b9e176b04e5444a8cd19df449bf8b1d425e82d61 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 09:35:35 +0200 Subject: [PATCH 4/9] Set correct public path --- functionaltest/deploy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functionaltest/deploy.php b/functionaltest/deploy.php index 8344f9f..aadae64 100644 --- a/functionaltest/deploy.php +++ b/functionaltest/deploy.php @@ -17,7 +17,7 @@ // Hosts mittwald_app(getenv("MITTWALD_APP_ID")) - ->set('public_path', '{{typo3_webroot}}'); + ->set('public_path', '/'); // Hooks From 34e9252ca9269fca9626fde9c3d9adc2a55bc579 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 16:17:12 +0200 Subject: [PATCH 5/9] Streamline test deploy file --- functionaltest/deploy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/functionaltest/deploy.php b/functionaltest/deploy.php index aadae64..7c14386 100644 --- a/functionaltest/deploy.php +++ b/functionaltest/deploy.php @@ -9,7 +9,6 @@ // Config -set('repository', 'https://github.com/martin-helmich/t3crr23-deployer-demo.git'); set('rsync_src', __DIR__); set('php_version', '8.2'); set('domain', getenv("MITTWALD_APP_DOMAIN")); From 129dd17e589a0fde15d87c9d09a3a1f7e0ea32f2 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 16:24:53 +0200 Subject: [PATCH 6/9] Select correct deployer version for tests --- .github/workflows/functional.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 86b9482..301e709 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -29,7 +29,7 @@ jobs: - 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 'deployer/deployer:${{ matrix.deployer-version }}.*' composer require --dev mittwald/deployer-recipes:dev-${GITHUB_SHA} cp git/mittwald-recipe/functionaltest/deploy.php deploy.php From 7a9224a87fb111f01c1616408a95d70418856a9f Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 16:34:05 +0200 Subject: [PATCH 7/9] Disable fail-fast strategy --- .github/workflows/functional.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 301e709..c263f07 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -9,6 +9,7 @@ jobs: build: strategy: max-parallel: 1 + fail-fast: false matrix: php-versions: ['8.2', '8.3'] deployer-version: ['7.3', '7.4'] From 7136e51eab89209fc7358e2b71f0d4aa06c0630b Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 16:37:54 +0200 Subject: [PATCH 8/9] Constrain tests to deployer 7.3 (for now) --- .github/workflows/functional.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index c263f07..e42e1e6 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: php-versions: ['8.2', '8.3'] - deployer-version: ['7.3', '7.4'] + deployer-version: ['7.3'] runs-on: ubuntu-latest steps: From 17d49a5644c5fdf755d4231dc0a928238ceccbdf Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 25 Apr 2024 16:52:56 +0200 Subject: [PATCH 9/9] Assert that deployment actually succeeds --- .github/workflows/functional.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index e42e1e6..23c2a46 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -43,6 +43,10 @@ jobs: 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 @@ -50,3 +54,15 @@ jobs: 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 }} \ No newline at end of file