diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6247ef5..85a4f6f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: # Github doesn't seem to like a working-directory arg for a custom action # and I ideally want to test this works as expected in the root - name: Copy test files to root - run: cp test/cached-composer-install/composer.* . + run: cp test/cached-composer-install/composer.* . - name: Install without dev dependencies uses: ./cached-composer-install @@ -40,3 +40,36 @@ jobs: env: EXPECT_DEV_PACKAGES: installed run: php test/cached-composer-install/check-installed.php + + integration-test-check-docker-composer-platform: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 # note, using 8.3 to prove that the composer reqs are only met within the mounted image + tools: composer:v2 + + - name: Pass with correct php version + uses: ./check-docker-composer-platform + with: + image: "php:8.4-alpine" + composer_json_dir: '${{ github.workspace }}/test/check-docker-composer-platform' + + - name: Fail with incorrect php version + id: with-wrong-version + continue-on-error: true + uses: ./check-docker-composer-platform + with: + image: "php:8.3-alpine" + composer_json_dir: '${{ github.workspace }}/test/check-docker-composer-platform' + + - name: Assert failed steps should have failed + shell: bash + run: | + if [ "${{ steps.with-wrong-version.outcome }}" != "failure" ] ; then + echo "Should have failed with incorrect PHP version in image, got ${{ steps.with-wrong-version.outcome }}" + exit 1 + fi diff --git a/check-docker-composer-platform/action.yml b/check-docker-composer-platform/action.yml new file mode 100644 index 0000000..43da055 --- /dev/null +++ b/check-docker-composer-platform/action.yml @@ -0,0 +1,39 @@ +name: 'Check docker image meets composer platform requirements' +description: 'Verifies that the PHP and extension versions in a docker image meet the platform requirements of the project and any composer-managed dependencies' +inputs: + image: + description: 'The docker image name and tag to check' + required: true + composer_json_dir: + description: 'The directory holding the composer.json and composer.lock - defaults to the main workspace' + default: ${{ github.workspace }} +runs: + using: 'composite' + steps: + - id: find_composer + name: Identify path to composer binary + shell: bash + run: | + set +e errexit + composer_bin=$(which composer) + set -e errexit + if [ -z "$composer_bin" ] ; then + echo "Cannot find composer binary on the github actions runner: have you run the setup-php action?" + exit 1 + fi + + echo "composer_bin=$composer_bin" >> $GITHUB_OUTPUT + + - name: Run composer check-platform-reqs + shell: bash + run: | + docker run \ + --rm \ + --quiet \ + -v "${{ steps.find_composer.outputs.composer_bin }}":/usr/bin/composer \ + -v "${{ inputs.composer_json_dir }}":/workspace \ + -w /workspace \ + --entrypoint /usr/bin/composer \ + "${{ inputs.image }}" \ + check-platform-reqs \ + --lock diff --git a/test/check-docker-composer-platform/composer.json b/test/check-docker-composer-platform/composer.json new file mode 100644 index 0000000..85e467f --- /dev/null +++ b/test/check-docker-composer-platform/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "php": "8.4.*" + } +} diff --git a/test/check-docker-composer-platform/composer.lock b/test/check-docker-composer-platform/composer.lock new file mode 100644 index 0000000..71dae33 --- /dev/null +++ b/test/check-docker-composer-platform/composer.lock @@ -0,0 +1,20 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "6d8d5097e0798e7d3ba5726488aad078", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "8.4.*" + }, + "platform-dev": {}, + "plugin-api-version": "2.6.0" +}