|
| 1 | +name: Internal - Test Composer PHP version discovery |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | +permissions: {} |
| 5 | +jobs: |
| 6 | + unit: |
| 7 | + uses: $/.github/workflows/continuous-integration.yml |
| 8 | + permissions: |
| 9 | + contents: read |
| 10 | + id-token: write |
| 11 | + with: |
| 12 | + working-directory: actions/get-php-versions |
| 13 | + lint: "false" |
| 14 | + dependency-review: false |
| 15 | + integration: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + - name: Arrange - Composer is the only version declaration |
| 24 | + run: | |
| 25 | + rm .php-version |
| 26 | + php -r 'echo PHP_VERSION;' > "$RUNNER_TEMP/php-version-before" |
| 27 | + chmod 600 tests/php-project/composer.json |
| 28 | + - name: Act - Discover releases for a nested Composer project |
| 29 | + id: versions |
| 30 | + uses: $/actions/get-php-versions |
| 31 | + with: |
| 32 | + working-directory: tests/php-project |
| 33 | + - name: Assert - Discovery preserves the runner PHP installation |
| 34 | + run: test "$(php -r 'echo PHP_VERSION;')" = "$(cat "$RUNNER_TEMP/php-version-before")" |
| 35 | + - name: Act - Set up the highest compatible release |
| 36 | + id: setup |
| 37 | + uses: $/actions/setup-php |
| 38 | + with: |
| 39 | + working-directory: ${{ github.workspace }}/tests/php-project |
| 40 | + install-dependencies: "false" |
| 41 | + - name: Assert - Setup and discovery agree |
| 42 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 43 | + env: |
| 44 | + VERSIONS: ${{ steps.versions.outputs.php-versions }} |
| 45 | + HIGHEST: ${{ steps.versions.outputs.php-version }} |
| 46 | + INSTALLED: ${{ steps.setup.outputs.php-version }} |
| 47 | + with: |
| 48 | + script: | |
| 49 | + const assert = require('node:assert/strict'); |
| 50 | + const versions = JSON.parse(process.env.VERSIONS); |
| 51 | + assert.ok(versions.length > 1, 'Discover every compatible stable minor, not only one default'); |
| 52 | + assert.equal(versions.at(-1), process.env.HIGHEST); |
| 53 | + assert.equal(process.env.INSTALLED, process.env.HIGHEST.split('.').slice(0, 2).join('.')); |
| 54 | + const {stdout} = await exec.getExecOutput('php', ['-r', 'echo PHP_VERSION;'], {silent: true}); |
| 55 | + assert.equal(stdout.trim(), process.env.HIGHEST); |
| 56 | + - name: Arrange - Project version file overrides automatic selection |
| 57 | + run: echo '8.2' > tests/php-project/.php-version |
| 58 | + - name: Act - Honor the version file |
| 59 | + id: file |
| 60 | + uses: $/actions/setup-php |
| 61 | + with: |
| 62 | + working-directory: tests/php-project |
| 63 | + install-dependencies: "false" |
| 64 | + - name: Act - Explicit version overrides the version file |
| 65 | + id: explicit |
| 66 | + uses: $/actions/setup-php |
| 67 | + with: |
| 68 | + working-directory: tests/php-project |
| 69 | + php-version: "8.3" |
| 70 | + install-dependencies: "false" |
| 71 | + - name: Assert - Overrides are preserved |
| 72 | + env: |
| 73 | + FILE_VERSION: ${{ steps.file.outputs.php-version }} |
| 74 | + EXPLICIT_VERSION: ${{ steps.explicit.outputs.php-version }} |
| 75 | + run: | |
| 76 | + test "$FILE_VERSION" = '8.2' |
| 77 | + test "$EXPLICIT_VERSION" = '8.3' |
| 78 | + - name: Arrange - Composer platform override |
| 79 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + const fs = require('node:fs'); |
| 83 | + fs.rmSync('tests/php-project/.php-version'); |
| 84 | + fs.rmSync('tests/php-project/composer.lock'); |
| 85 | + const manifest = JSON.parse(fs.readFileSync('tests/php-project/composer.json', 'utf8')); |
| 86 | + manifest.config = {...manifest.config, platform: {php: '8.2.0'}}; |
| 87 | + fs.writeFileSync('tests/php-project/composer.json', JSON.stringify(manifest)); |
| 88 | + - name: Act - Honor Composer platform selection |
| 89 | + id: platform |
| 90 | + uses: $/actions/setup-php |
| 91 | + with: |
| 92 | + working-directory: tests/php-project |
| 93 | + install-dependencies: "false" |
| 94 | + - name: Assert - Composer platform override is preserved |
| 95 | + env: |
| 96 | + PLATFORM_VERSION: ${{ steps.platform.outputs.php-version }} |
| 97 | + run: test "$PLATFORM_VERSION" = '8.2' |
| 98 | + - name: Act - Resolve the local Docker build runtime |
| 99 | + id: docker |
| 100 | + run: | |
| 101 | + docker build --tag php-version-resolver actions/get-php-versions |
| 102 | + test "$(docker run --rm --entrypoint id php-version-resolver -u)" -ne 0 |
| 103 | + version=$(docker run --rm --user "$(id -u):$(id -g)" --volume "$GITHUB_WORKSPACE/tests/php-project:/project:ro" php-version-resolver) |
| 104 | + printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT" |
| 105 | + - name: Assert - Local builds use the same Composer constraint |
| 106 | + env: |
| 107 | + DOCKER_VERSION: ${{ steps.docker.outputs.version }} |
| 108 | + ACTION_VERSION: ${{ steps.versions.outputs.php-version }} |
| 109 | + run: test "$DOCKER_VERSION" = "$ACTION_VERSION" |
| 110 | + - name: Arrange - Project symlink escapes the checkout |
| 111 | + run: ln -s /tmp tests/php-project/outside |
| 112 | + - name: Act - Reject a directory outside the checkout |
| 113 | + id: outside |
| 114 | + continue-on-error: true |
| 115 | + uses: $/actions/get-php-versions |
| 116 | + with: |
| 117 | + working-directory: .. |
| 118 | + - name: Act - Reject a symlink outside the checkout |
| 119 | + id: symlink |
| 120 | + continue-on-error: true |
| 121 | + uses: $/actions/get-php-versions |
| 122 | + with: |
| 123 | + working-directory: tests/php-project/outside |
| 124 | + - name: Assert - Invalid paths fail without outputs |
| 125 | + env: |
| 126 | + OUTSIDE_OUTCOME: ${{ steps.outside.outcome }} |
| 127 | + SYMLINK_OUTCOME: ${{ steps.symlink.outcome }} |
| 128 | + OUTSIDE_OUTPUTS: ${{ toJSON(steps.outside.outputs) }} |
| 129 | + SYMLINK_OUTPUTS: ${{ toJSON(steps.symlink.outputs) }} |
| 130 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 131 | + with: |
| 132 | + script: | |
| 133 | + const assert = require('node:assert/strict'); |
| 134 | + for (const scenario of ['OUTSIDE', 'SYMLINK']) { |
| 135 | + assert.equal(process.env[`${scenario}_OUTCOME`], 'failure'); |
| 136 | + assert.ok(Object.values(JSON.parse(process.env[`${scenario}_OUTPUTS`])).every(value => value === '')); |
| 137 | + } |
0 commit comments