|
| 1 | +# Version Matrix Actions Script |
| 2 | + |
| 3 | +This folder contains scripts that are used to create Actions matrices for building specific Docker images with the right version combinations of Apify SDK, Playwright/Puppeteer, and Crawlee. |
| 4 | + |
| 5 | +These scripts are ran using the [bun](https://bun.sh) runtime (for no reason other than ease of use). |
| 6 | + |
| 7 | +## Adding a new Node version to the matrix |
| 8 | + |
| 9 | +When a new version of Node is released, just update the `supportedNodeVersions` array in the `src/shares/constants.ts` file. |
| 10 | + |
| 11 | +Then, run `SKIP_CACHE_SET=true bun node:normal` locally to preview the new matrix. (you can append `| jq -r '.include[] | "node-version=\(.["node-version"]) apify-version=\(.["apify-version"]) is-latest=\(.["is-latest"])"'` to get a nicer output from the big JSON blob) |
| 12 | + |
| 13 | +## Adding a new Python version to the matrix |
| 14 | + |
| 15 | +When a new version of Python is released, just update the `supportedPythonVersions` array in the `src/shares/constants.ts` file. |
| 16 | + |
| 17 | +Then, run `SKIP_CACHE_SET=true bun python:normal` locally to preview the new matrix. (you can append `| jq -r '.include[] | "python-version=\(.["python-version"]) playwright-version=\(.["playwright-version"]) apify-version=\(.["apify-version"]) is-latest=\(.["is-latest"])"'` to get a nicer output from the big JSON blob) |
| 18 | + |
| 19 | +## Adding a new Python version range for specific Playwright version ranges |
| 20 | + |
| 21 | +Sometimes, newer Python is not compatible with Playwright versions that were released before a specific one (at the time of writing, this is the case for Playwright 1.48.0 and Python 3.13 -> Python 3.13.x can only run Playwright 1.48.0 and newer). |
| 22 | + |
| 23 | +To add a new Python version range for a specific Playwright version, add a new entry to the `playwrightPythonVersionConstraints` array in the `python.ts` file. |
| 24 | + |
| 25 | +The key represents the Python version range where this starts taking effect. The value is the Playwright version range that is required for the Python version. |
| 26 | + |
| 27 | +## Updating the runtime version that will be used for images that are referenced with just the build tag |
| 28 | + |
| 29 | +When we build images, we also include a specific runtime version in the tag (as an example, we have `apify/actor-node:20`). We also provide images tagged with `latest` or `beta`. These images will default to the "latest" runtime version that is specified in the `src/shares/constants.ts` file under `latestPythonVersion` or `latestNodeVersion`. |
| 30 | + |
| 31 | +When the time comes to bump these, just make a PR, edit those values, and merge it. Next time images get built, the `latest` or `beta` tags will use those new versions for the tag. |
| 32 | + |
| 33 | +## Creating new matrices |
| 34 | + |
| 35 | +The structure for a GitHub Actions matrix is as follows: |
| 36 | + |
| 37 | +```ts |
| 38 | +interface Matrix { |
| 39 | + include: MatrixEntry[]; |
| 40 | +} |
| 41 | + |
| 42 | +type MatrixEntry = Record<string, string>; |
| 43 | +``` |
| 44 | + |
| 45 | +When trying to integrate a new matrix into a flow, you need to follow the following steps: |
| 46 | + |
| 47 | +- have a step that outputs the matrix as a JSON blob |
| 48 | + |
| 49 | + ```yaml |
| 50 | + matrix: |
| 51 | + outputs: |
| 52 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Generate matrix |
| 56 | + id: set-matrix |
| 57 | + run: echo "matrix=$(bun python:normal)" >> $GITHUB_OUTPUT |
| 58 | + working-directory: ./.github/actions/version-matrix |
| 59 | + ``` |
| 60 | +
|
| 61 | +(optionally you can also add in a print step to ensure the matrix is correct. Feel free to copy it from any that uses previous matrices) |
| 62 | +
|
| 63 | +- ensure the actual build step needs the matrix and uses it like this (the if check if optional if the matrix will always have at least one entry): |
| 64 | +
|
| 65 | + ```yaml |
| 66 | + needs: [matrix] |
| 67 | + if: ${{ toJson(fromJson(needs.matrix.outputs.matrix).include) != '[]' }} |
| 68 | + strategy: |
| 69 | + matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} |
| 70 | + ``` |
| 71 | +
|
| 72 | +- reference matrix values based on the keys in the objects in the `include` array. For example, to get the Python version, you can use `${{ matrix.python-version }}`. |
0 commit comments