From f57c15ee0d89afe872fdbdb8691364a9b6dfe0b7 Mon Sep 17 00:00:00 2001 From: Leonel Enriquez Date: Mon, 29 Apr 2024 18:00:21 -0500 Subject: [PATCH] Issue #535: Use labels to run the Multidev deploy --- .../PantheonReviewAppsDDEVManual.yml | 52 ++++++++++++++ .../workflows/PantheonReviewAppsManual.yml | 72 +++++++++++++++++++ src/ScaffoldInstallerPlugin.php | 11 +++ 3 files changed, 135 insertions(+) create mode 100644 scaffold/github/workflows/PantheonReviewAppsDDEVManual.yml create mode 100644 scaffold/github/workflows/PantheonReviewAppsManual.yml diff --git a/scaffold/github/workflows/PantheonReviewAppsDDEVManual.yml b/scaffold/github/workflows/PantheonReviewAppsDDEVManual.yml new file mode 100644 index 00000000..86636e05 --- /dev/null +++ b/scaffold/github/workflows/PantheonReviewAppsDDEVManual.yml @@ -0,0 +1,52 @@ +name: "Pantheon Review Apps" + +on: + pull_request_target: + types: [ labeled ] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Drainpipe-Deploy-Pantheon-Multidev: + runs-on: ubuntu-22.04 + if: github.event.label.name == 'pantheon-multidev' + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.ddev/.drainpipe-composer-cache + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - uses: ./.github/actions/drainpipe/set-env + + - name: Install and Start DDEV + uses: ./.github/actions/drainpipe/ddev + with: + git-name: Drainpipe Bot + git-email: no-reply@example.com + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }} + + - name: Build Project + env: + directory: /tmp/release + run: | + ddev composer install + ddev task build + ddev task snapshot:directory directory=/tmp/release + + - name: Deploy Pantheon Review App + uses: ./.github/actions/drainpipe/pantheon/review + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + terminus-token: ${{ secrets.PANTHEON_TERMINUS_TOKEN }} + commit-message: ${{ github.sha }} + site-name: ${{ vars.PANTHEON_SITE_NAME || secrets.PANTHEON_SITE_NAME }} + lock-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + lock-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} + # set to "true" if you want to run the installer + run-installer: ${{ secrets.PANTHEON_REVIEW_RUN_INSTALLER }} diff --git a/scaffold/github/workflows/PantheonReviewAppsManual.yml b/scaffold/github/workflows/PantheonReviewAppsManual.yml new file mode 100644 index 00000000..b0bfc561 --- /dev/null +++ b/scaffold/github/workflows/PantheonReviewAppsManual.yml @@ -0,0 +1,72 @@ +name: "Pantheon Review Apps" + +on: + pull_request_target: + types: [ labeled ] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +# You will also need to add the secrets used below to Dependabot secrets +# if you want this to successfully run in auto-created PRs. +permissions: + deployments: write + contents: read + pull-requests: read + +jobs: + Drainpipe-Deploy-Pantheon-Multidev: + runs-on: ubuntu-22.04 + if: github.event.label.name == 'pantheon-multidev' + steps: + - uses: actions/checkout@v4 + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - uses: ./.github/actions/drainpipe/set-env + + - uses: ./.github/actions/drainpipe/setup-git + with: + git-name: Drainpipe Bot + git-email: no-reply@example.com + + - uses: ./.github/actions/drainpipe/setup-ssh + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }} + + - uses: ./.github/actions/drainpipe/pantheon/setup-terminus + with: + pantheon-token: ${{ secrets.PANTHEON_TERMINUS_TOKEN }} + terminus-plugins: ${{ vars.TERMINUS_PLUGINS || secrets.TERMINUS_PLUGINS }} + + - uses: php-actions/composer@v6 + + - name: Build Project + env: + directory: /tmp/release + run: | + composer install + task build + task snapshot:directory directory=/tmp/release + + - name: Deploy Pantheon Review App + uses: ./.github/actions/drainpipe/pantheon/review + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + terminus-token: ${{ secrets.PANTHEON_TERMINUS_TOKEN }} + commit-message: ${{ github.sha }} + site-name: ${{ vars.PANTHEON_SITE_NAME || secrets.PANTHEON_SITE_NAME }} + lock-username: ${{ secrets.PANTHEON_REVIEW_USERNAME }} + lock-password: ${{ secrets.PANTHEON_REVIEW_PASSWORD }} diff --git a/src/ScaffoldInstallerPlugin.php b/src/ScaffoldInstallerPlugin.php index b16bcaf8..02e602a3 100644 --- a/src/ScaffoldInstallerPlugin.php +++ b/src/ScaffoldInstallerPlugin.php @@ -293,6 +293,17 @@ private function installCICommands(): void $fs->copy("$scaffoldPath/github/workflows/PantheonReviewApps.yml", './.github/workflows/PantheonReviewApps.yml'); } } + elseif ($github === 'PantheonReviewAppsManual') { + $fs->ensureDirectoryExists('./.github/actions/drainpipe/pantheon'); + $fs->ensureDirectoryExists('./.github/workflows'); + $fs->copy("$scaffoldPath/github/actions/pantheon", './.github/actions/drainpipe/pantheon'); + if (file_exists('./.ddev/config.yaml')) { + $fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsDDEVManual.yml", './.github/workflows/PantheonReviewApps.yml'); + } + else { + $fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsManual.yml", './.github/workflows/PantheonReviewApps.yml'); + } + } else if ($github === 'ComposerLockDiff') { $fs->ensureDirectoryExists('./.github/workflows'); $fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml');