From 6eac1f324216f18af8c36335292628eafb5ff788 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Wed, 24 Apr 2024 11:11:38 -0500 Subject: [PATCH] Use new composer lock diff workflow. --- .github/actions/drainpipe/ddev/action.yml | 92 +++++++++++++++++++ .github/actions/drainpipe/set-env/action.yml | 17 ++++ .../actions/drainpipe/set-env/bash_aliases | 7 ++ .../actions/drainpipe/setup-git/action.yml | 16 ++++ .../actions/drainpipe/setup-ssh/action.yml | 26 ++++++ .github/workflows/ComposerLockDiff.yml | 56 +++++++++++ .tugboat/config.yml | 14 ++- .tugboat/steps/1-init.sh | 5 + composer.json | 5 +- composer.lock | 23 ++--- 10 files changed, 246 insertions(+), 15 deletions(-) create mode 100644 .github/actions/drainpipe/ddev/action.yml create mode 100644 .github/actions/drainpipe/set-env/action.yml create mode 100644 .github/actions/drainpipe/set-env/bash_aliases create mode 100644 .github/actions/drainpipe/setup-git/action.yml create mode 100644 .github/actions/drainpipe/setup-ssh/action.yml create mode 100644 .github/workflows/ComposerLockDiff.yml diff --git a/.github/actions/drainpipe/ddev/action.yml b/.github/actions/drainpipe/ddev/action.yml new file mode 100644 index 0000000..a6469d6 --- /dev/null +++ b/.github/actions/drainpipe/ddev/action.yml @@ -0,0 +1,92 @@ +name: 'Install and Start DDEV' +description: 'Installs the latest or specified version of DDEV and starts the project' +inputs: + ssh-private-key: + description: "SSH Private Key" + required: false + ssh-known-hosts: + description: "SSH Known Hosts" + required: false + git-email: + description: "Git e-mail address" + required: false + git-name: + description: "Git name" + required: false + composer-cache-dir: + description: "Composer cache directory, relative to the project workspace. Set to false to disable." + required: false + version: + description: "Override the DDEV version .e.g. '1.19.0'" + required: false +runs: + using: "composite" + steps: + - name: Install and Start DDEV + run: | + curl https://apt.fury.io/drud/gpg.key | sudo apt-key add - + echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list + sudo apt update + sudo apt install libnss3-tools -y + + mkdir -p .ddev/homeadditions/.ssh + # Copy private key + if [ "${{ inputs.ssh-private-key }}" != "" ]; then + echo "${{ inputs.ssh-private-key }}" > .ddev/homeadditions/.ssh/id_rsa + chmod 600 .ddev/homeadditions/.ssh/id_rsa + fi + # Copy known hosts + if [ "${{ inputs.ssh-known-hosts }}" != "" ]; then + echo "${{ inputs.ssh-known-hosts}}" > .ddev/homeadditions/.ssh/known_hosts + chmod 644 .ddev/homeadditions/.ssh/known_hosts + fi + # SSH config file + touch .ddev/homeadditions/.ssh/config + + # Disable strict host key checking for Pantheon as ssh-keyscan will not + # return a stable response. + if [ -f "pantheon.yml" ]; then + echo -e "Host *.drush.in\\n\\tStrictHostKeyChecking no\\n\tLogLevel ERROR\\n" >> .ddev/homeadditions/.ssh/config + fi + + chmod 600 .ddev/homeadditions/.ssh/config + + chmod 700 .ddev/homeadditions/.ssh + + # Download and run the DDEV installer + if [ "${{ inputs.version }}" != "" ]; then + sudo apt install -y ddev=${{inputs.version}} + else + sudo apt install -y ddev + fi + + # Support local runner https://github.com/nektos/act + if [ "$ACT" != "" ]; then + sudo chown runner:docker /var/run/docker.sock + fi + + ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent + + if [ "${{ inputs.composer-cache-dir }}" != "false" ]; then + # @todo Replace /var/www/html with an environment variable. + CACHE_DIR=".ddev/.drainpipe-composer-cache" + if [ "${{ inputs.composer-cache-dir }}" != "" ]; then + CACHE_DIR="${{ inputs.composer-cache-dir }}" + fi + # Workaround for https://github.com/ddev/ddev/issues/6044 + if yq -re .type .ddev/config.yaml; then + ddev config --web-environment-add="COMPOSER_CACHE_DIR=/var/www/html/$CACHE_DIR" --project-type="$(yq -re .type .ddev/config.yaml)" + else + ddev config --web-environment-add="COMPOSER_CACHE_DIR=/var/www/html/$CACHE_DIR" + fi + fi + + ddev start + ddev describe + + # Copy git credentials + ddev exec "git config --global user.name \"${{ inputs.git-name }}\"" + ddev exec "git config --global user.email \"${{ inputs.git-email }}\"" + + echo "DRAINPIPE_DDEV=true" >> $GITHUB_ENV + shell: bash diff --git a/.github/actions/drainpipe/set-env/action.yml b/.github/actions/drainpipe/set-env/action.yml new file mode 100644 index 0000000..32862b6 --- /dev/null +++ b/.github/actions/drainpipe/set-env/action.yml @@ -0,0 +1,17 @@ +name: 'Set Env' +description: 'Creates some useful environment variables' +inputs: + github-api-token: + description: "GitHub API token" + required: true + github-api-token-username: + description: "GitHub API token username" + required: true +runs: + using: "composite" + steps: + - run: | + echo "Setting Drainpipe environment variables:" + echo "DRAINPIPE_PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" >> $GITHUB_ENV + echo "DRAINPIPE_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)" >> $GITHUB_ENV + shell: bash diff --git a/.github/actions/drainpipe/set-env/bash_aliases b/.github/actions/drainpipe/set-env/bash_aliases new file mode 100644 index 0000000..58fca27 --- /dev/null +++ b/.github/actions/drainpipe/set-env/bash_aliases @@ -0,0 +1,7 @@ +drainpipe_exec() { + if [ "$DRAINPIPE_DDEV" == "true" ]; then + ddev exec "$@" + else + eval "$@" + fi +} diff --git a/.github/actions/drainpipe/setup-git/action.yml b/.github/actions/drainpipe/setup-git/action.yml new file mode 100644 index 0000000..8a64c53 --- /dev/null +++ b/.github/actions/drainpipe/setup-git/action.yml @@ -0,0 +1,16 @@ +name: 'Configure git' +description: 'Configures git username and e-mail address' +inputs: + git-email: + description: "Git e-mail address" + required: true + git-name: + description: "Git name" + required: true +runs: + using: "composite" + steps: + - run: | + git config --global user.email ${{ inputs.git-email }} + git config --global user.name ${{ inputs.git-name }} + shell: bash diff --git a/.github/actions/drainpipe/setup-ssh/action.yml b/.github/actions/drainpipe/setup-ssh/action.yml new file mode 100644 index 0000000..9f0c642 --- /dev/null +++ b/.github/actions/drainpipe/setup-ssh/action.yml @@ -0,0 +1,26 @@ +name: 'Configure ssh' +description: 'Configures SSH' +inputs: + ssh-private-key: + description: "SSH Private Key" + required: true + ssh-known-hosts: + description: "SSH Known Hosts" + required: false +runs: + using: "composite" + steps: + - run: | + sudo apt-get update + sudo apt-get install -y openssh-client + eval $(ssh-agent -s) + echo "${{ inputs.ssh-private-key }}" | tr -d '\r' | ssh-add - + mkdir -p ~/.ssh + chmod 700 ~/.ssh + touch ~/.ssh/config + chmod 600 ~/.ssh/config + if [ "${{ inputs.ssh-known-hosts}}" != "" ]; then + echo "${{ inputs.ssh-known-hosts }}" >> ~/.ssh/known_hosts + chmod 644 ~/.ssh/known_hosts + fi + shell: bash diff --git a/.github/workflows/ComposerLockDiff.yml b/.github/workflows/ComposerLockDiff.yml new file mode 100644 index 0000000..51053c1 --- /dev/null +++ b/.github/workflows/ComposerLockDiff.yml @@ -0,0 +1,56 @@ +name: "Composer Lock Diff" + +on: + pull_request: + types: [opened, synchronize, reopened] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Composer-Lock-Diff: + runs-on: ubuntu-22.04 + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: Check if composer.lock was changed + id: composer-lock-changed + uses: tj-actions/changed-files@v44 + with: + files: 'composer.lock' + + - name: Delete sticky pull request comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: composer-lock-diff + delete: true + + - uses: actions/cache@v4 + if: ${{ steps.composer-lock-changed.outputs.any_changed == 'true' }} + with: + path: ${{ github.workspace }}/.ddev/.drainpipe-composer-cache + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Generate composer diff + if: ${{ steps.composer-lock-changed.outputs.any_changed == 'true' }} + id: composer-diff + uses: IonBazan/composer-diff-action@v1 + with: + base: ${{ github.base_ref || github.ref_name }} + with-platform: true + with-links: true + + - name: Post sticky pull request comment + if: ${{ steps.composer-lock-changed.outputs.any_changed == 'true' }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: composer-lock-diff + message: | + ### Composer package changes + ${{ (steps.composer-diff.outcome != 'success' && 'Review any changes to composer.lock manually.') || steps.composer-diff.outputs.composer_diff || 'No changes found' }} diff --git a/.tugboat/config.yml b/.tugboat/config.yml index c6b75cd..2165e09 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -1,6 +1,13 @@ # DO NOT EDIT THIS FILE # This file is controlled by Drainpipe, run composer install to apply pending -# updates. +# updates. You can add values to the php service using .tugboat/config.override.yml. +# +# Example config.drainpipe-override.yml +# php: +# aliases: +# urls: +# screenshot: +# visualdiff: services: php: http: false @@ -20,4 +27,7 @@ services: image: tugboatqa/mariadb:10.4 redis: - image: tugboatqa/redis:6-bullseye + image: tugboatqa/redis:7-bullseye + + elasticsearch: + image: tugboatqa/elasticsearch:7.17.19 diff --git a/.tugboat/steps/1-init.sh b/.tugboat/steps/1-init.sh index e3b4d23..76da224 100755 --- a/.tugboat/steps/1-init.sh +++ b/.tugboat/steps/1-init.sh @@ -42,6 +42,11 @@ docker-php-ext-install gd # of GD. Lullabot will likely be publishing an ADR recommending it too. apt-get install -y imagemagick +# Install the PHP redis extension. + +yes '' | pecl install -f redis +echo 'extension=redis.so' > /usr/local/etc/php/conf.d/redis.ini + # Install node apt-get install -y ca-certificates gnupg mkdir -p /etc/apt/keyrings diff --git a/composer.json b/composer.json index 8b6afa3..a842293 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "minimum-stability": "dev", "require": { - "lullabot/drainpipe": "^3", + "lullabot/drainpipe": "dev-composer-lock-diff-sticky-pr-comment", "lullabot/drainpipe-dev": "dev-main" }, "config": { @@ -27,7 +27,8 @@ }, "extra": { "drainpipe": { - "tugboat": {} + "tugboat": {}, + "github": ["ComposerLockDiff"] } } } diff --git a/composer.lock b/composer.lock index a08edc0..fc019b3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "440e3324554dd3348a41536d8cab78d8", + "content-hash": "e5e6d944d4d955bbd4b206cfbdac76c5", "packages": [ { "name": "behat/mink", @@ -1988,30 +1988,30 @@ }, { "name": "lullabot/drainpipe", - "version": "v3.6.0", + "version": "dev-composer-lock-diff-sticky-pr-comment", "source": { "type": "git", "url": "https://github.com/Lullabot/drainpipe.git", - "reference": "f0d5cb8e982211d6ff0d3c652c60bc5c63bf9a4e" + "reference": "57d94dda9059200f0a4dea17ace6fe2b8f96b093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Lullabot/drainpipe/zipball/f0d5cb8e982211d6ff0d3c652c60bc5c63bf9a4e", - "reference": "f0d5cb8e982211d6ff0d3c652c60bc5c63bf9a4e", + "url": "https://api.github.com/repos/Lullabot/drainpipe/zipball/57d94dda9059200f0a4dea17ace6fe2b8f96b093", + "reference": "57d94dda9059200f0a4dea17ace6fe2b8f96b093", "shasum": "" }, "require": { "composer-plugin-api": "^2.0", - "drush/drush": "^10|^11|^12", + "drush/drush": "^11|^12|^13", "ext-json": "*", "php": "^8.1", - "symfony/yaml": "^3|^4|^5|^6", - "twig/twig": "^2|^3", + "symfony/yaml": "^6|^7", + "twig/twig": "^3", "vlucas/phpdotenv": "^4|^5" }, "require-dev": { "composer/composer": "^2.7.2", - "phpunit/phpunit": "^7|^8|^9" + "phpunit/phpunit": "^9.6.19" }, "type": "composer-plugin", "extra": { @@ -2042,9 +2042,9 @@ "description": "An automated build tool to allow projects to have a set standardized operations scripts.", "support": { "issues": "https://github.com/Lullabot/drainpipe/issues", - "source": "https://github.com/Lullabot/drainpipe/tree/v3.6.0" + "source": "https://github.com/Lullabot/drainpipe/tree/composer-lock-diff-sticky-pr-comment" }, - "time": "2024-03-21T19:54:24+00:00" + "time": "2024-04-24T16:00:48+00:00" }, { "name": "lullabot/drainpipe-dev", @@ -7569,6 +7569,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { + "lullabot/drainpipe": 20, "lullabot/drainpipe-dev": 20 }, "prefer-stable": false,