|
1 | | -# SPEC-0 Versions Action |
| 1 | +# SPEC 0 Versions Action |
2 | 2 |
|
3 | | -This repository contains a GitHub Action to generate the files required for the SPEC-0 documentation. |
| 3 | +This repository contains a Github Action to update Python dependencies in your `pyproject.toml` such that they conform to the SPEC 0 support schedule. You can find this schedule [here](https://scientific-python.org/specs/spec-0000/) |
4 | 4 |
|
5 | 5 | ## Using the action |
6 | 6 |
|
| 7 | + |
| 8 | +### Example workflow |
| 9 | + |
| 10 | +To use the action you can copy the yaml below, and paste it into `.github/workflows/update-spec0.yaml`. Whenever the action is triggered it will open a PR in your repository that will update the dependencies of SPEC 0 to the new lower bound. For this you will have to provide it with a PAT that has write permissions in the `contents` and `pull request` scopes. Please refer to the GitHub documentation for instructions on how to do this [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). |
| 11 | + |
| 12 | + |
7 | 13 | ```yaml |
8 | | -name: Generate spec-zero data |
| 14 | +name: Update SPEC 0 dependencies |
9 | 15 |
|
10 | 16 | on: |
11 | | - push: |
12 | | - branches: |
13 | | - - main |
| 17 | + schedule: |
| 18 | + # At 00:00 on day-of-month 3 in every 3rd month. (i.e. every quarter) |
| 19 | + # Releases should happen on the second day of the quarter in savente93/SPEC0-schedule to |
| 20 | + # avoid fence post errors, so allow one day as a buffer to avoid timing issues here as well. |
| 21 | + - cron: "0 0 3 */3 *" |
| 22 | + # On demand: |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + pull-requests: write |
14 | 28 |
|
15 | 29 | jobs: |
16 | | - devstats-query: |
| 30 | + update: |
17 | 31 | runs-on: ubuntu-latest |
18 | 32 | steps: |
19 | | - - uses: scientific-python/spec0-action@main |
| 33 | + - uses: savente93/update-spec0-dependencies@v1.0.0 |
| 34 | + with: |
| 35 | + token: ${{ secrets.GH_PAT }} # <- GH_PAT you will have to configure in the repo as a secret |
20 | 36 | ``` |
21 | 37 |
|
22 | | -The above would produce an artifact named `spec-zero-versions`, the following files: `schedule.yaml`,`schedule.md` and `chart.md`. |
| 38 | +It should update any of the packages listed in the `dependency`, or `tool.pixi.*` tables. For examples of before and after you can see [./tests/test_data/pyproject.toml](./tests/test_data/pyproject.toml) and [./tests/test_data/pyproject_updated.toml](./tests/test_data/pyproject_updated.toml) respectively. Other tools are not yet supported, but I am open to feature requests. |
23 | 39 |
|
24 | | -To help projects stay compliant with SPEC-0, we provide a `schedule.json` file that can be used by CI systems to determine new version boundaries. |
25 | | -The structure of the file is as follows: |
| 40 | +The newest lower bounds will be downloaded from [https://github.com/savente93/SPEC0-schedule](https://github.com/savente93/SPEC0-schedule) but you should not have to worry about this. |
26 | 41 |
|
27 | | -```json |
28 | | -[ |
29 | | - { |
30 | | - "start_date": "iso8601_timestamp", |
31 | | - "packages": { |
32 | | - "package_name": "version" |
33 | | - } |
34 | | - } |
35 | | -] |
36 | | -``` |
37 | 42 |
|
38 | | -All information in the json file is in a string format that should be easy to use. |
39 | | -The date is the first timestamp of the relevant quarter. |
40 | | -Thus a workflow for using this file could be: |
| 43 | +### Parameters |
41 | 44 |
|
42 | | -1. Fetch `schedule.json` |
43 | | -2. Determine maximum date that is smaller than current date |
44 | | -3. Update packages listed with new minimum versions |
| 45 | +| Input | Required | Default | Description | |
| 46 | +| ------------------- | -------- | ------------------ | -------------------------------------------------------------------------------| |
| 47 | +| token | yes | — | Personal access token with `contents` & `pull-request` scopes | |
| 48 | +| project\_file\_name | no | `"pyproject.toml"` | File to update dependencies in | |
| 49 | +| schedule\_path | no | `"schedule.json"` | path to schedule json data. only relevant if you have it committed in your repo | |
| 50 | +| target\_branch | no | `"main"` | Branch to open PR against | |
| 51 | +| create_pr | no | `true` | Open a PR with new versions | |
| 52 | +| pr_title | no | `chore: Drop support for unsupported packages conform SPEC 0` | The title of the PR that will be opened | |
| 53 | +| commit_msg | no | `chore: Drop support for unsupported packages conform SPEC 0` | Commit message of the commit to update the versions. | |
45 | 54 |
|
46 | | -You can obtain the new versions you should set by using this `jq` expression: |
47 | 55 |
|
48 | | -```sh |
49 | | -jq 'map(select(.start_date |fromdateiso8601 |tonumber < now))| sort_by("start_date") | reverse | .[0].packages ' schedule.json |
50 | | -``` |
| 56 | +## Limitations |
| 57 | + |
| 58 | +1. Since this action simply parses the toml to do the upgrade and leaves any other bounds intact, it is possible that the environment of the PR becomes unsolvable. |
| 59 | + For example if you have a numpy dependency like so: `numpy = ">=1.25.0,<2"` this will get updated in the PR to `numpy = ">=2.0.0,<2"` which is infeasible. |
| 60 | + Keeping the resulting environment solvable is outside the scope of this action, so you might have to adjust them manually. |
| 61 | +2. Currently only `pyproject.toml` is supported by this action, though other manifest files could be considered upon request. |
51 | 62 |
|
52 | | -If you use a package manager like pixi you could update the dependencies with a bash script like this (untested): |
53 | | - |
54 | | -```sh |
55 | | -curl -Ls -o schedule.json https://raw.githubusercontent.com/scientific-python/specs/main/spec-0000/schedule.json |
56 | | -for line in $(jq 'map(select(.start_date |fromdateiso8601 |tonumber < now))| sort_by("start_date") | reverse | .[0].packages | to_entries | map(.key + ":" + .value)[]' --raw-output schedule.json); do |
57 | | - package=$(echo "$line" | cut -d ':' -f 1) |
58 | | - version=$(echo "$line" | cut -d ':' -f 2) |
59 | | - if pixi list -x "^$package" &>/dev/null| grep "No packages" -q; then |
60 | | - pixi add "$package>=$version"; |
61 | | - fi |
62 | | -done |
63 | | -``` |
0 commit comments