diff --git a/.forgejo/workflows/deployer-release-create.yaml b/.forgejo/workflows/deployer-release-create.yaml new file mode 100644 index 0000000..d93255c --- /dev/null +++ b/.forgejo/workflows/deployer-release-create.yaml @@ -0,0 +1,76 @@ +# Generic Deployer Release Create Workflow +# +# Downloads build artifact and runs `release:create ` to upload a release +# without switching to it. Use deployer-release-switch.yaml to activate the release. +# +# Usage: +# jobs: +# create-stage: +# uses: infrastructure/ci-templates/.forgejo/workflows/deployer-release-create.yaml@main +# with: +# server: stage +# secrets: +# ssh_key: ${{ secrets.STAGE_KEY }} + +name: Deployer Release Create + +on: + workflow_call: + inputs: + server: + description: 'Target server (e.g., stage, production)' + required: true + type: string + php_version: + description: 'PHP version' + required: false + type: string + default: '8.3' + deployer_file: + description: 'Path to deploy.php' + required: false + type: string + default: './build/deploy.php' + artifact_name: + description: 'Name of the build artifact to download' + required: false + type: string + default: 'build' + secrets: + ssh_key: + description: 'SSH private key for deployment' + required: true + +env: + COMPOSER_ALLOW_SUPERUSER: 1 + +jobs: + release-create: + name: Create Release (${{ inputs.server }}) + runs-on: ubuntu-latest + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact_name }} + + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz + + - name: Install system dependencies + run: | + apt-get update -qq && apt-get install -y -qq openssh-client rsync + composer require deployer/deployer --dev -q + + - name: Create release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: -q --file=${{ inputs.deployer_file }} release:create ${{ inputs.server }} + private-key: ${{ secrets.ssh_key }} diff --git a/.forgejo/workflows/deployer-release-switch.yaml b/.forgejo/workflows/deployer-release-switch.yaml new file mode 100644 index 0000000..100dc7f --- /dev/null +++ b/.forgejo/workflows/deployer-release-switch.yaml @@ -0,0 +1,77 @@ +# Generic Deployer Release Switch Workflow +# +# Downloads build artifact and runs `release:switch ` to activate +# a previously uploaded release. Use after deployer-release-create.yaml. +# +# Usage: +# jobs: +# switch-stage: +# needs: create-stage +# uses: infrastructure/ci-templates/.forgejo/workflows/deployer-release-switch.yaml@main +# with: +# server: stage +# secrets: +# ssh_key: ${{ secrets.STAGE_KEY }} + +name: Deployer Release Switch + +on: + workflow_call: + inputs: + server: + description: 'Target server (e.g., stage, production)' + required: true + type: string + php_version: + description: 'PHP version' + required: false + type: string + default: '8.3' + deployer_file: + description: 'Path to deploy.php' + required: false + type: string + default: './build/deploy.php' + artifact_name: + description: 'Name of the build artifact to download' + required: false + type: string + default: 'build' + secrets: + ssh_key: + description: 'SSH private key for deployment' + required: true + +env: + COMPOSER_ALLOW_SUPERUSER: 1 + +jobs: + release-switch: + name: Switch Release (${{ inputs.server }}) + runs-on: ubuntu-latest + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact_name }} + + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz + + - name: Install system dependencies + run: | + apt-get update -qq && apt-get install -y -qq openssh-client rsync + composer require deployer/deployer --dev -q + + - name: Switch release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: -q --file=${{ inputs.deployer_file }} release:switch ${{ inputs.server }} + private-key: ${{ secrets.ssh_key }} diff --git a/.forgejo/workflows/typo3-build-frontend.yaml b/.forgejo/workflows/typo3-build-frontend.yaml deleted file mode 100644 index 0ebb269..0000000 --- a/.forgejo/workflows/typo3-build-frontend.yaml +++ /dev/null @@ -1,258 +0,0 @@ -# Cloonar TYPO3 Staged Deployment Workflow -# -# Staged deployment: build → deploy to stage → run E2E tests → switch release -# -# Usage in project's .forgejo/workflows/deploy.yaml: -# name: Deploy -# on: -# push: -# branches: [main] -# jobs: -# deploy: -# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-staged-deploy.yaml@main -# with: -# stage_url: https://myproject.cloonar.dev -# php_version: '8.3' -# secrets: -# stage_key: ${{ secrets.STAGE_KEY }} -# prod_key: ${{ secrets.PROD_KEY }} - -name: TYPO3 Staged Deploy - -on: - workflow_call: - inputs: - stage_url: - description: 'Staging URL for E2E tests' - required: true - type: string - php_version: - description: 'PHP version' - required: false - type: string - default: '8.3' - node_version: - description: 'Node.js version' - required: false - type: string - default: '20' - build_frontend: - description: 'Run npm build' - required: false - type: boolean - default: false - run_e2e_tests: - description: 'Run Playwright E2E tests' - required: false - type: boolean - default: true - e2e_path: - description: 'Path to E2E tests' - required: false - type: string - default: 'tests/e2e' - deployer_file: - description: 'Path to deploy.php' - required: false - type: string - default: './build/deploy.php' - deploy_production: - description: 'Also deploy to production after stage succeeds' - required: false - type: boolean - default: true - secrets: - stage_key: - description: 'SSH key for staging' - required: true - prod_key: - description: 'SSH key for production' - required: false - -env: - COMPOSER_ALLOW_SUPERUSER: 1 - -jobs: - # =========================================================================== - # Build - # =========================================================================== - build: - name: Build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - tools: composer - - - name: Setup Node.js - if: ${{ inputs.build_frontend }} - uses: actions/setup-node@v4 - with: - node-version: ${{ inputs.node_version }} - - - name: Install PHP dependencies - run: composer install --prefer-dist --no-progress --no-dev --ignore-platform-reqs - - - name: Install Node dependencies & build - if: ${{ fromJSON(inputs.build_frontend) }} - run: | - npm ci - npm run build - - - name: Create artifact - run: | - tar -czf build.tar.gz \ - bin public packages config vendor build composer.json composer.lock \ - $([ -d "node_modules" ] && echo "node_modules") \ - $([ -d "dist" ] && echo "dist") \ - 2>/dev/null || true - - - uses: actions/upload-artifact@v4 - with: - name: build-${{ github.sha }} - path: build.tar.gz - retention-days: 1 - - - # =========================================================================== - # Deploy to Stage (release:create only) - # =========================================================================== - deploy-stage: - name: Upload to Stage - runs-on: ubuntu-latest - needs: [build] - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Upload release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # Switch Stage Release - # =========================================================================== - switch-stage: - name: Activate Stage Release - runs-on: ubuntu-latest - needs: [deploy-stage] - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Switch release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:switch stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # E2E Tests with Playwright - # =========================================================================== - test-stage: - name: E2E Tests - runs-on: ubuntu-latest - needs: [switch-stage] - if: ${{ inputs.run_e2e_tests }} - container: - image: mcr.microsoft.com/playwright:v1.50.0-noble - - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - working-directory: ${{ inputs.e2e_path }} - run: npm ci - - - name: Run smoke tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test smoke - - - name: Run visual regression tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test visual - continue-on-error: true - - - name: Upload test report - if: always() - uses: actions/upload-artifact@v4 - with: - name: playwright-report - path: ${{ inputs.e2e_path }}/playwright-report/ - retention-days: 7 - - - name: Upload diff screenshots - if: failure() - uses: actions/upload-artifact@v4 - with: - name: visual-diff - path: ${{ inputs.e2e_path }}/test-results/ - retention-days: 7 - - - # =========================================================================== - # Deploy to Production - # =========================================================================== - deploy-production: - name: Deploy Production - runs-on: ubuntu-latest - needs: [test-stage] - if: ${{ inputs.deploy_production && (needs.test-stage.result == 'success' || needs.test-stage.result == 'skipped') }} - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Deploy to production - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create production - private-key: ${{ secrets.prod_key }} diff --git a/.forgejo/workflows/typo3-build.yaml b/.forgejo/workflows/typo3-build.yaml index eadd3a0..0d60c24 100644 --- a/.forgejo/workflows/typo3-build.yaml +++ b/.forgejo/workflows/typo3-build.yaml @@ -1,23 +1,17 @@ -# Cloonar TYPO3 Staged Deployment Workflow -# -# Staged deployment: build → deploy to stage → run E2E tests → switch release -# -# Usage in project's .forgejo/workflows/deploy.yaml: -# name: Deploy -# on: -# push: -# branches: [main] +# TYPO3 Build Workflow +# +# Builds PHP/Node artifacts and uploads them for subsequent deployment jobs. +# Use this as the first step in your composable deployment pipeline. +# +# Usage: # jobs: -# deploy: -# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-staged-deploy.yaml@main +# build: +# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-build.yaml@main # with: -# stage_url: https://myproject.cloonar.dev # php_version: '8.3' -# secrets: -# stage_key: ${{ secrets.STAGE_KEY }} -# prod_key: ${{ secrets.PROD_KEY }} +# build_frontend: true -name: TYPO3 Staged Deploy +name: TYPO3 Build on: workflow_call: @@ -27,14 +21,26 @@ on: required: false type: string default: '8.3' + node_version: + description: 'Node.js version' + required: false + type: string + default: '20' + build_frontend: + description: 'Run npm build' + required: false + type: boolean + default: false + artifact_name: + description: 'Name of the build artifact to upload' + required: false + type: string + default: 'build' env: COMPOSER_ALLOW_SUPERUSER: 1 jobs: - # =========================================================================== - # Build - # =========================================================================== build: name: Build runs-on: ubuntu-latest @@ -48,21 +54,32 @@ jobs: php-version: ${{ inputs.php_version }} tools: composer + - name: Setup Node.js + if: ${{ inputs.build_frontend }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + - name: Install PHP dependencies + run: composer install --prefer-dist --no-progress --no-dev --ignore-platform-reqs + + - name: Install Node dependencies & build + if: ${{ inputs.build_frontend }} run: | - composer install --prefer-dist --no-progress --no-dev --ignore-platform-reqs - curl -o deploy-lib.php https://git.cloonar.com/infrastructure/ci-templates/raw/branch/main/deployer/typo3-recipe.php + npm ci + npm run build - name: Create artifact run: | tar -czf build.tar.gz \ - bin public packages config vendor build composer.json composer.lock deploy-lib.php \ + bin public packages config vendor build composer.json composer.lock \ $([ -d "node_modules" ] && echo "node_modules") \ $([ -d "dist" ] && echo "dist") \ 2>/dev/null || true - - uses: actions/upload-artifact@v3 + - name: Upload artifact + uses: actions/upload-artifact@v3 with: - name: build-${{ github.sha }} + name: ${{ inputs.artifact_name }} path: build.tar.gz retention-days: 1 diff --git a/.forgejo/workflows/typo3-deploy-stage.yaml b/.forgejo/workflows/typo3-deploy-stage.yaml deleted file mode 100644 index 685aa38..0000000 --- a/.forgejo/workflows/typo3-deploy-stage.yaml +++ /dev/null @@ -1,212 +0,0 @@ -# Cloonar TYPO3 Staged Deployment Workflow -# -# Staged deployment: build → deploy to stage → run E2E tests → switch release -# -# Usage in project's .forgejo/workflows/deploy.yaml: -# name: Deploy -# on: -# push: -# branches: [main] -# jobs: -# deploy: -# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-staged-deploy.yaml@main -# with: -# stage_url: https://myproject.cloonar.dev -# php_version: '8.3' -# secrets: -# stage_key: ${{ secrets.STAGE_KEY }} -# prod_key: ${{ secrets.PROD_KEY }} - -name: TYPO3 Staged Deploy - -on: - workflow_call: - inputs: - stage_url: - description: 'Staging URL for E2E tests' - required: true - type: string - php_version: - description: 'PHP version' - required: false - type: string - default: '8.3' - node_version: - description: 'Node.js version' - required: false - type: string - default: '20' - run_e2e_tests: - description: 'Run Playwright E2E tests' - required: false - type: boolean - default: true - e2e_path: - description: 'Path to E2E tests' - required: false - type: string - default: 'tests/e2e' - deployer_file: - description: 'Path to deploy.php' - required: false - type: string - default: './build/deploy.php' - deploy_production: - description: 'Also deploy to production after stage succeeds' - required: false - type: boolean - default: true - secrets: - stage_key: - description: 'SSH key for staging' - required: true - prod_key: - description: 'SSH key for production' - required: false - -env: - COMPOSER_ALLOW_SUPERUSER: 1 - -jobs: - # =========================================================================== - # Deploy to Stage (release:create only) - # =========================================================================== - deploy-stage: - name: Upload to Stage - runs-on: ubuntu-latest - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v3 - with: - name: build-${{ github.sha }} - - - run: | - tar xf build.tar.gz && rm build.tar.gz - composer require deployer/deployer --dev -q - - - run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - - - name: Upload release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: -q --file=${{ inputs.deployer_file }} release:create stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # Switch Stage Release - # =========================================================================== - switch-stage: - name: Activate Stage Release - runs-on: ubuntu-latest - needs: [deploy-stage] - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v3 - with: - name: build-${{ github.sha }} - - - run: | - tar xf build.tar.gz && rm build.tar.gz - composer require deployer/deployer --dev -q - - - run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - - - name: Switch release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: -q --file=${{ inputs.deployer_file }} release:switch stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # E2E Tests with Playwright - # =========================================================================== - test-stage: - name: E2E Tests - runs-on: ubuntu-latest - needs: [switch-stage] - if: ${{ inputs.run_e2e_tests }} - container: - image: mcr.microsoft.com/playwright:v1.50.0-noble - - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - working-directory: ${{ inputs.e2e_path }} - run: npm ci - - - name: Run smoke tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test smoke - - - name: Run visual regression tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test visual - continue-on-error: true - - - name: Upload test report - if: always() - uses: actions/upload-artifact@v3 - with: - name: playwright-report - path: ${{ inputs.e2e_path }}/playwright-report/ - retention-days: 7 - - - name: Upload diff screenshots - if: failure() - uses: actions/upload-artifact@v3 - with: - name: visual-diff - path: ${{ inputs.e2e_path }}/test-results/ - retention-days: 7 - - - # =========================================================================== - # Deploy to Production - # =========================================================================== - deploy-production: - name: Deploy Production - runs-on: ubuntu-latest - needs: [switch-stage, test-stage] - if: ${{ always() && inputs.deploy_production && needs.switch-stage.result == 'success' && needs.test-stage.result != 'failure' }} - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v3 - with: - name: build-${{ github.sha }} - - - run: | - tar xf build.tar.gz && rm build.tar.gz - composer require deployer/deployer --dev -q - - - run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - - - name: Deploy to production - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: -q --file=${{ inputs.deployer_file }} release:create production - private-key: ${{ secrets.prod_key }} diff --git a/.forgejo/workflows/typo3-e2e-test.yaml b/.forgejo/workflows/typo3-e2e-test.yaml new file mode 100644 index 0000000..6ccc6c3 --- /dev/null +++ b/.forgejo/workflows/typo3-e2e-test.yaml @@ -0,0 +1,81 @@ +# TYPO3 E2E Test Workflow +# +# Runs Playwright E2E tests against a deployed environment. +# Includes smoke tests and optional visual regression tests. +# +# Usage: +# jobs: +# test: +# needs: switch-stage +# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-e2e-test.yaml@main +# with: +# test_url: https://myproject.cloonar.dev + +name: TYPO3 E2E Tests + +on: + workflow_call: + inputs: + test_url: + description: 'URL to test against' + required: true + type: string + e2e_path: + description: 'Path to E2E test directory' + required: false + type: string + default: 'tests/e2e' + run_visual_tests: + description: 'Run visual regression tests' + required: false + type: boolean + default: true + visual_tests_continue_on_error: + description: 'Continue if visual tests fail' + required: false + type: boolean + default: true + +jobs: + e2e-test: + name: E2E Tests + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.50.0-noble + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + working-directory: ${{ inputs.e2e_path }} + run: npm ci + + - name: Run smoke tests + working-directory: ${{ inputs.e2e_path }} + env: + TEST_URL: ${{ inputs.test_url }} + run: npx playwright test smoke + + - name: Run visual regression tests + if: ${{ inputs.run_visual_tests }} + working-directory: ${{ inputs.e2e_path }} + env: + TEST_URL: ${{ inputs.test_url }} + run: npx playwright test visual + continue-on-error: ${{ inputs.visual_tests_continue_on_error }} + + - name: Upload test report + if: always() + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: ${{ inputs.e2e_path }}/playwright-report/ + retention-days: 7 + + - name: Upload diff screenshots + if: failure() + uses: actions/upload-artifact@v4 + with: + name: visual-diff + path: ${{ inputs.e2e_path }}/test-results/ + retention-days: 7 diff --git a/.forgejo/workflows/typo3-release-prod.yaml b/.forgejo/workflows/typo3-release-prod.yaml deleted file mode 100644 index 0ebb269..0000000 --- a/.forgejo/workflows/typo3-release-prod.yaml +++ /dev/null @@ -1,258 +0,0 @@ -# Cloonar TYPO3 Staged Deployment Workflow -# -# Staged deployment: build → deploy to stage → run E2E tests → switch release -# -# Usage in project's .forgejo/workflows/deploy.yaml: -# name: Deploy -# on: -# push: -# branches: [main] -# jobs: -# deploy: -# uses: infrastructure/ci-templates/.forgejo/workflows/typo3-staged-deploy.yaml@main -# with: -# stage_url: https://myproject.cloonar.dev -# php_version: '8.3' -# secrets: -# stage_key: ${{ secrets.STAGE_KEY }} -# prod_key: ${{ secrets.PROD_KEY }} - -name: TYPO3 Staged Deploy - -on: - workflow_call: - inputs: - stage_url: - description: 'Staging URL for E2E tests' - required: true - type: string - php_version: - description: 'PHP version' - required: false - type: string - default: '8.3' - node_version: - description: 'Node.js version' - required: false - type: string - default: '20' - build_frontend: - description: 'Run npm build' - required: false - type: boolean - default: false - run_e2e_tests: - description: 'Run Playwright E2E tests' - required: false - type: boolean - default: true - e2e_path: - description: 'Path to E2E tests' - required: false - type: string - default: 'tests/e2e' - deployer_file: - description: 'Path to deploy.php' - required: false - type: string - default: './build/deploy.php' - deploy_production: - description: 'Also deploy to production after stage succeeds' - required: false - type: boolean - default: true - secrets: - stage_key: - description: 'SSH key for staging' - required: true - prod_key: - description: 'SSH key for production' - required: false - -env: - COMPOSER_ALLOW_SUPERUSER: 1 - -jobs: - # =========================================================================== - # Build - # =========================================================================== - build: - name: Build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - tools: composer - - - name: Setup Node.js - if: ${{ inputs.build_frontend }} - uses: actions/setup-node@v4 - with: - node-version: ${{ inputs.node_version }} - - - name: Install PHP dependencies - run: composer install --prefer-dist --no-progress --no-dev --ignore-platform-reqs - - - name: Install Node dependencies & build - if: ${{ fromJSON(inputs.build_frontend) }} - run: | - npm ci - npm run build - - - name: Create artifact - run: | - tar -czf build.tar.gz \ - bin public packages config vendor build composer.json composer.lock \ - $([ -d "node_modules" ] && echo "node_modules") \ - $([ -d "dist" ] && echo "dist") \ - 2>/dev/null || true - - - uses: actions/upload-artifact@v4 - with: - name: build-${{ github.sha }} - path: build.tar.gz - retention-days: 1 - - - # =========================================================================== - # Deploy to Stage (release:create only) - # =========================================================================== - deploy-stage: - name: Upload to Stage - runs-on: ubuntu-latest - needs: [build] - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Upload release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # Switch Stage Release - # =========================================================================== - switch-stage: - name: Activate Stage Release - runs-on: ubuntu-latest - needs: [deploy-stage] - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Switch release - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:switch stage - private-key: ${{ secrets.stage_key }} - - - # =========================================================================== - # E2E Tests with Playwright - # =========================================================================== - test-stage: - name: E2E Tests - runs-on: ubuntu-latest - needs: [switch-stage] - if: ${{ inputs.run_e2e_tests }} - container: - image: mcr.microsoft.com/playwright:v1.50.0-noble - - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - working-directory: ${{ inputs.e2e_path }} - run: npm ci - - - name: Run smoke tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test smoke - - - name: Run visual regression tests - working-directory: ${{ inputs.e2e_path }} - env: - TEST_URL: ${{ inputs.stage_url }} - run: npx playwright test visual - continue-on-error: true - - - name: Upload test report - if: always() - uses: actions/upload-artifact@v4 - with: - name: playwright-report - path: ${{ inputs.e2e_path }}/playwright-report/ - retention-days: 7 - - - name: Upload diff screenshots - if: failure() - uses: actions/upload-artifact@v4 - with: - name: visual-diff - path: ${{ inputs.e2e_path }}/test-results/ - retention-days: 7 - - - # =========================================================================== - # Deploy to Production - # =========================================================================== - deploy-production: - name: Deploy Production - runs-on: ubuntu-latest - needs: [test-stage] - if: ${{ inputs.deploy_production && (needs.test-stage.result == 'success' || needs.test-stage.result == 'skipped') }} - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ inputs.php_version }} - - - uses: actions/download-artifact@v4 - with: - name: build-${{ github.sha }} - - - run: tar xf build.tar.gz && rm build.tar.gz - - - run: apt-get update && apt-get install -y openssh-client rsync - - - name: Deploy to production - uses: deployphp/action@v1 - with: - deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create production - private-key: ${{ secrets.prod_key }} diff --git a/.forgejo/workflows/typo3-staged-deploy.yaml b/.forgejo/workflows/typo3-staged-deploy.yaml index e92fee3..b7dce0f 100644 --- a/.forgejo/workflows/typo3-staged-deploy.yaml +++ b/.forgejo/workflows/typo3-staged-deploy.yaml @@ -1,18 +1,18 @@ -# Cloonar TYPO3 Staged Deployment Workflow -# -# Staged deployment: build → deploy to stage → run E2E tests → switch release -# -# Usage in project's .forgejo/workflows/deploy.yaml: -# name: Deploy -# on: -# push: -# branches: [main] +# TYPO3 Staged Deployment Workflow (Convenience Wrapper) +# +# All-in-one workflow: build → deploy to stage → test → optionally deploy to production +# For more control and visibility, use the composable workflows directly: +# - typo3-build.yaml +# - deployer-release-create.yaml +# - deployer-release-switch.yaml +# - typo3-e2e-test.yaml +# +# Usage: # jobs: # deploy: # uses: infrastructure/ci-templates/.forgejo/workflows/typo3-staged-deploy.yaml@main # with: # stage_url: https://myproject.cloonar.dev -# php_version: '8.3' # secrets: # stage_key: ${{ secrets.STAGE_KEY }} # prod_key: ${{ secrets.PROD_KEY }} @@ -57,7 +57,7 @@ on: type: string default: './build/deploy.php' deploy_production: - description: 'Also deploy to production after stage succeeds' + description: 'Deploy to production after tests pass' required: false type: boolean default: true @@ -90,7 +90,7 @@ jobs: tools: composer - name: Setup Node.js - if: ${{ fromJSON(inputs.build_frontend) }} + if: ${{ inputs.build_frontend }} uses: actions/setup-node@v4 with: node-version: ${{ inputs.node_version }} @@ -99,7 +99,7 @@ jobs: run: composer install --prefer-dist --no-progress --no-dev --ignore-platform-reqs - name: Install Node dependencies & build - if: ${{ fromJSON(inputs.build_frontend) }} + if: ${{ inputs.build_frontend }} run: | npm ci npm run build @@ -112,7 +112,8 @@ jobs: $([ -d "dist" ] && echo "dist") \ 2>/dev/null || true - - uses: actions/upload-artifact@v4 + - name: Upload artifact + uses: actions/upload-artifact@v4 with: name: build-${{ github.sha }} path: build.tar.gz @@ -120,10 +121,10 @@ jobs: # =========================================================================== - # Deploy to Stage (release:create only) + # Create Stage Release # =========================================================================== - deploy-stage: - name: Upload to Stage + create-stage: + name: Create Release (stage) runs-on: ubuntu-latest needs: [build] @@ -133,19 +134,22 @@ jobs: with: php-version: ${{ inputs.php_version }} - - uses: actions/download-artifact@v4 + - name: Download artifact + uses: actions/download-artifact@v4 with: name: build-${{ github.sha }} - - run: tar xf build.tar.gz && rm build.tar.gz + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz - - run: apt-get update && apt-get install -y openssh-client rsync + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - - name: Upload release + - name: Create release uses: deployphp/action@v1 with: deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create stage + dep: -q --file=${{ inputs.deployer_file }} release:create stage private-key: ${{ secrets.stage_key }} @@ -153,9 +157,9 @@ jobs: # Switch Stage Release # =========================================================================== switch-stage: - name: Activate Stage Release + name: Switch Release (stage) runs-on: ubuntu-latest - needs: [deploy-stage] + needs: [create-stage] steps: - name: Setup PHP @@ -163,24 +167,27 @@ jobs: with: php-version: ${{ inputs.php_version }} - - uses: actions/download-artifact@v4 + - name: Download artifact + uses: actions/download-artifact@v4 with: name: build-${{ github.sha }} - - run: tar xf build.tar.gz && rm build.tar.gz + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz - - run: apt-get update && apt-get install -y openssh-client rsync + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - name: Switch release uses: deployphp/action@v1 with: deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:switch stage + dep: -q --file=${{ inputs.deployer_file }} release:switch stage private-key: ${{ secrets.stage_key }} - + # =========================================================================== - # E2E Tests with Playwright + # E2E Tests # =========================================================================== test-stage: name: E2E Tests @@ -228,13 +235,13 @@ jobs: # =========================================================================== - # Deploy to Production + # Create Production Release # =========================================================================== - deploy-production: - name: Deploy Production + create-production: + name: Create Release (production) runs-on: ubuntu-latest - needs: [test-stage] - if: ${{ inputs.deploy_production && (needs.test-stage.result == 'success' || needs.test-stage.result == 'skipped') }} + needs: [switch-stage, test-stage] + if: ${{ always() && inputs.deploy_production && needs.switch-stage.result == 'success' && needs.test-stage.result != 'failure' }} steps: - name: Setup PHP @@ -242,17 +249,54 @@ jobs: with: php-version: ${{ inputs.php_version }} - - uses: actions/download-artifact@v4 + - name: Download artifact + uses: actions/download-artifact@v4 with: name: build-${{ github.sha }} - - run: tar xf build.tar.gz && rm build.tar.gz + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz - - run: apt-get update && apt-get install -y openssh-client rsync + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq openssh-client rsync - - name: Deploy to production + - name: Create release uses: deployphp/action@v1 with: deployer-binary: "./bin/dep" - dep: --file=${{ inputs.deployer_file }} release:create production + dep: -q --file=${{ inputs.deployer_file }} release:create production + private-key: ${{ secrets.prod_key }} + + + # =========================================================================== + # Switch Production Release + # =========================================================================== + switch-production: + name: Switch Release (production) + runs-on: ubuntu-latest + needs: [create-production] + if: ${{ always() && needs.create-production.result == 'success' }} + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: build-${{ github.sha }} + + - name: Extract artifact + run: tar xf build.tar.gz && rm build.tar.gz + + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq openssh-client rsync + + - name: Switch release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: -q --file=${{ inputs.deployer_file }} release:switch production private-key: ${{ secrets.prod_key }}