diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9131cab6..18f479b9 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", // 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..d5e52de4 100755 --- a/.devcontainer/install.sh +++ b/.devcontainer/install.sh @@ -10,13 +10,14 @@ if [ ! -f /usr/local/bin/wp ]; then fi # Install specific Composer version. -COMPOSER_VERSION=2.3.10 -if [ ! -f /usr/local/bin/composer ]; then - echo "Installing Composer ${COMPOSER_VERSION}..." - sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer --2 --version=${COMPOSER_VERSION} -fi +#COMPOSER_VERSION=2.3.10 +#if [ ! -f /usr/local/bin/composer ]; then +# echo "Installing Composer ${COMPOSER_VERSION}..." +# sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer --2 --version=${COMPOSER_VERSION} +#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/.devcontainer/setup.sh b/.devcontainer/setup.sh index 63608d3c..38800743 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -14,7 +14,7 @@ PLUGIN_DIR=/workspaces/openid-connect-generic # Install Composer dependencies. cd "${PLUGIN_DIR}" -composer install +composer install --no-progress # Install NPM dependencies. cd "${PLUGIN_DIR}" diff --git a/.github/workflows/pr-unit-testing.yml b/.github/workflows/pr-unit-testing.yml index 9554edcb..6486ab38 100644 --- a/.github/workflows/pr-unit-testing.yml +++ b/.github/workflows/pr-unit-testing.yml @@ -7,11 +7,8 @@ on: pull_request: env: - PHP_VERSION: '7.4' - WP_VERSION: '5.9.*' - WP_MULTISITE: 0 - COMPOSER_VERSION: '2.2' - ACTION_VERSION: 2 + REGISTRY: ghcr.io + ACTION_VERSION: 3 jobs: pr_unit_testing: @@ -24,50 +21,44 @@ 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: Cache Composer dependencies - if: ${{ !env.ACT }} - uses: actions/cache@v2 - env: - composer-cache-name: cache-composer - 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 + - name: Set Swap Space + uses: pierotofy/set-swap-space@master with: - node-version-file: '.nvmrc' - cache: ${{ !env.ACT && 'npm' || '' }} + swap-size-gb: 10 - - name: Setup PHP & Composer Environment - # https://github.com/marketplace/actions/setup-php-action - uses: shivammathur/setup-php@v2 + # https://github.com/marketplace/actions/docker-login + - name: Login to GitHub Packages + uses: docker/login-action@v3 with: - php-version: "${{ env.PHP_VERSION }}" - tools: "composer:${{ env.COMPOSER_VERSION }}" - - - name: Environment Check - run: php -v && composer --version + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + logout: false - - 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: Set up Docker BuildKit + # https://github.com/marketplace/actions/docker-setup-buildx + uses: docker/setup-buildx-action@v1 - - name: Install Composer Dependencies - run: composer install --prefer-dist - - - name: NPM Setup - run: npm ci + - name: Pre-build Dev Container Image + uses: devcontainers/ci@v0.3 + with: + imageName: ghcr.io/oidc-wp/openid-connect-generic-devcontainer + cacheFrom: ghcr.io/oidc-wp/openid-connect-generic-devcontainer + # Control when images are pushed. + push: always - - name: Unit Tests - run: npm run test + - name: Run Tests in Dev Container + uses: cloudposse/github-action-docker-compose-test-run@main + with: + file: docker-compose.ci.yml + service: app + registry: ${{ env.REGISTRY }} + login: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + command: | + composer install + npm ci + npm run tests - name: Generate Coverage Report # https://github.com/marketplace/actions/coverage-report-as-comment-clover diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 00000000..fe7bab8f --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,53 @@ +# This is the Compose file for command-line services. +# Anything that doesn't need to be run as part of the main `docker-compose up' +# command should reside in here and be invoked by a helper script. +version: "3.7" + +services: + app: + image: ghcr.io/oidc-wp/openid-connect-generic-devcontainer + restart: always + depends_on: + - db + working_dir: /workspaces/openid-connect-generic + environment: &env + WORDPRESS_DB_HOST: db + WORDPRESS_DB_NAME: wordpress + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_TEST_DB_NAME: wordpress_test + CODESPACES: "${CODESPACES}" + CODESPACE_NAME: "${CODESPACE_NAME}" + GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN: "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + volumes: + - .:/workspaces/openid-connect-generic:cached + - ./tools/local-env:/app:cached + - ./tools/php/php-cli.ini:/usr/local/etc/php/php-cli.ini:ro,cached + - .:/app/wp-content/plugins/daggerhart-openid-connect-generic:ro,cached + - ~/.composer:/root/.composer:cached + - ~/.npm:/root/.npm:cached + networks: + - oidcwp-net + + db: + image: mariadb + restart: unless-stopped + ports: + - 3306:3306 + environment: + MYSQL_DATABASE: wordpress + MYSQL_ROOT_PASSWORD: password + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + volumes: + - db:/var/lib/mysql + - ./tests/db-wordpress_test.sql:/docker-entrypoint-initdb.d/db-wordpress_test.sql + networks: + - oidcwp-net + +volumes: + db: + +networks: + oidcwp-net: +