|
| 1 | +name: UnitTests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ master ] |
| 7 | + pull_request: |
| 8 | + branches: [ master ] |
| 9 | + |
| 10 | +env: |
| 11 | + PATH_CACHE: /tmp/docker-img-arch |
| 12 | + |
| 13 | +jobs: |
| 14 | + php: |
| 15 | + name: Run tests via container |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Skip Duplicate Actions |
| 19 | + uses: fkirc/skip-duplicate-actions@v5 |
| 20 | + |
| 21 | + - name: Checkout repo |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Create image tag from file hash |
| 25 | + uses: KEINOS/gh-action-hash-for-cache@main |
| 26 | + id: imagetag |
| 27 | + # Udate the hash if any of the below file is changed or the month has changed. |
| 28 | + with: |
| 29 | + path: | |
| 30 | + ./Extension.php |
| 31 | + ./composer.json |
| 32 | + ./Dockerfile |
| 33 | + ./docker-compose.yml |
| 34 | + variant: $(TZ=UTC-9 date '+%Y%m') |
| 35 | + |
| 36 | + - name: Enable Cache |
| 37 | + id: cache |
| 38 | + uses: actions/cache@v4 |
| 39 | + with: |
| 40 | + path: ${{ env.PATH_CACHE }} |
| 41 | + key: ${{ steps.imagetag.outputs.hash }} |
| 42 | + |
| 43 | + - name: Load cached Docker images if any |
| 44 | + if: steps.cache.outputs.cache-hit == 'true' |
| 45 | + run: | |
| 46 | + docker load --input ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_min_1.tar |
| 47 | + docker load --input ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_max_1.tar |
| 48 | + docker load --input ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_latest_1.tar |
| 49 | +
|
| 50 | + - name: Pull base images if no-cache |
| 51 | + if: steps.cache.outputs.cache-hit != 'true' |
| 52 | + run: | |
| 53 | + : # Pull images for stability. |
| 54 | + docker compose pull |
| 55 | +
|
| 56 | + - name: Build Docker images if no-cache |
| 57 | + if: steps.cache.outputs.cache-hit != 'true' |
| 58 | + run: | |
| 59 | + docker compose build |
| 60 | +
|
| 61 | + - name: Run tests on minimum supported PHP version |
| 62 | + run: docker compose run --rm min |
| 63 | + |
| 64 | + - name: Run tests on maximum supported PHP version |
| 65 | + run: docker compose run --rm max |
| 66 | + |
| 67 | + - name: Run tests on latest PHP version (currently experimental. Expected to fail) |
| 68 | + run: docker compose run --rm latest || exit 0 |
| 69 | + |
| 70 | + - name: Save/export built images to cache dir if no-cache |
| 71 | + if: steps.cache.outputs.cache-hit != 'true' |
| 72 | + run: | |
| 73 | + mkdir -p ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }} |
| 74 | + docker save --output ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_min_1.tar parsedown-extension_table-of-contents-min:latest |
| 75 | + docker save --output ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_max_1.tar parsedown-extension_table-of-contents-max:latest |
| 76 | + docker save --output ${{ env.PATH_CACHE }}/${{ steps.imagetag.outputs.hash }}/github_latest_1.tar parsedown-extension_table-of-contents-latest:latest |
0 commit comments