From e08ce3e74256e6818d2ec8ad553dfef894ed5289 Mon Sep 17 00:00:00 2001 From: Tim Nolte Date: Tue, 7 Nov 2023 22:09:24 -0500 Subject: [PATCH] WIP - Unit Testing w/ Dev Container --- .devcontainer/devcontainer.json | 13 ++++--- .devcontainer/install.sh | 1 + .github/workflows/pr-unit-testing.yml | 54 ++++++--------------------- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9131cab6..6bbaabd5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "dockerComposeFile": "../docker-compose.yml", "service": "app", "mounts": ["source=dind-var-lib-docker,target=/var/lib/docker,type=volume"], - "workspaceMount": "source=${localWorkspaceFolder}/openid-connect-generic,target=/workspaces,type=bind,consistency=delegated", + //"workspaceMount": "source=${localWorkspaceFolder}/openid-connect-generic,target=/workspaces,type=bind,consistency=delegated", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", "customizations": { @@ -52,14 +52,17 @@ }, // Use `onCreateCommand` to run commands as part of the container creation. - "onCreateCommand": "sudo chmod +x .devcontainer/install.sh && .devcontainer/install.sh", + //"onCreateCommand": "chmod +x .devcontainer/install.sh && .devcontainer/install.sh", // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "sudo chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh", + "postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh", // Use 'postStartCommand' to run commands after the container has started. - "postStartCommand": "cd /app && wp plugin activate daggerhart-openid-connect-generic", + //"postStartCommand": "cd /app && wp plugin activate daggerhart-openid-connect-generic", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "wp_php" + "remoteUser": "wp_php", + + // A set of name-value pairs that sets or overrides environment variables for the devcontainer.json supporting service / tool (or sub-processes like terminals) but not the container as a whole. + "remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" } } diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh index 1bed8541..0158c3b8 100755 --- a/.devcontainer/install.sh +++ b/.devcontainer/install.sh @@ -18,5 +18,6 @@ fi # Copy the welcome message if [ ! -f /usr/local/etc/vscode-dev-containers/first-run-notice.txt ]; then + echo "Installing First Run Notice..." sudo cp .devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt fi diff --git a/.github/workflows/pr-unit-testing.yml b/.github/workflows/pr-unit-testing.yml index 9554edcb..746d7c07 100644 --- a/.github/workflows/pr-unit-testing.yml +++ b/.github/workflows/pr-unit-testing.yml @@ -24,50 +24,20 @@ jobs: # https://github.com/marketplace/actions/checkout uses: actions/checkout@v2 - - name: Get Composer Cache Directory - id: composer-cache - if: ${{ !env.ACT }} - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Set up Docker BuildKit + # https://github.com/marketplace/actions/docker-setup-buildx + uses: docker/setup-buildx-action@v1 - - name: Cache Composer dependencies - if: ${{ !env.ACT }} - uses: actions/cache@v2 - env: - composer-cache-name: cache-composer + - name: Build Dev Container + # https://github.com/marketplace/actions/dev-container-build-and-run-action + uses: devcontainers/ci@v0.3 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ env.WP_VERSION }}-v${{ env.ACTION_VERSION }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ env.WP_VERSION }}-v${{ env.ACTION_VERSION }}- - - - name: Setup Node Environment - # https://github.com/marketplace/actions/setup-node-js-environment - uses: actions/setup-node@v2 - with: - node-version-file: '.nvmrc' - cache: ${{ !env.ACT && 'npm' || '' }} - - - name: Setup PHP & Composer Environment - # https://github.com/marketplace/actions/setup-php-action - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ env.PHP_VERSION }}" - tools: "composer:${{ env.COMPOSER_VERSION }}" - - - name: Environment Check - run: php -v && composer --version - - - name: Require Specified WordPress Version - run: composer require johnpbloch/wordpress-core:${{ env.WP_VERSION }} php-stubs/wordpress-stubs:${{ env.WP_VERSION }} wp-phpunit/wp-phpunit:${{ env.WP_VERSION }} --dev --prefer-source --update-with-all-dependencies - - - name: Install Composer Dependencies - run: composer install --prefer-dist - - - name: NPM Setup - run: npm ci - - - name: Unit Tests - run: npm run test + # Change this to point to your image name + imageName: openid-connect-generic-devcontainer + # Change this to be your CI task/script + runCmd: npm run test + # Control when images are pushed. + push: never - name: Generate Coverage Report # https://github.com/marketplace/actions/coverage-report-as-comment-clover