File size: 3,461 Bytes
314b695
 
 
 
 
 
 
 
 
 
 
28d8f0a
 
 
314b695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f88fe3
 
 
314b695
 
 
 
 
 
 
 
 
 
 
 
e952113
314b695
a634267
 
14359f9
 
 
 
 
 
 
 
a634267
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: PySR backend update
on:
  schedule:
    - cron: '00 00 * * *'
  workflow_dispatch:
jobs:
  update_compat:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.9
          cache: pip

      - name: "Install PySR"
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          python setup.py install
          # Not needed:
          # python -c 'import pysr; pysr.install()'

      - name: "Get SymbolicRegression.jl latest version"
        id: get-latest
        run: |
          cd $(mktemp -d)
          git clone https://github.com/MilesCranmer/SymbolicRegression.jl
          cd SymbolicRegression.jl
          echo "version=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT

      - name: "Get SymbolicRegression.jl version used in PySR"
        id: get-current
        run: |
          echo "version=$(python -c 'import pysr; print(pysr.version.__symbolic_regression_jl_version__)' 2>/dev/null)" >> $GITHUB_OUTPUT

      # If versions are different, we want to take our checked-out version,
      # create a new branch called "update_compat_{...}", where the "..."
      # is a timestamp. We then want to
      # go to pysr/version.py, bump the patch version of PySR (__version__),
      # set the version of __symbolic_regression_jl_version__ to the latest
      # version of SymbolicRegression.jl, and then commit and push.
      # Finally, we will open a PR from this branch to master.
      - name: "Update versions"
        if: ${{ steps.get-latest.outputs.version != steps.get-current.outputs.version }}
        run: |
          git config --global user.name "${GITHUB_ACTOR}"
          git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

          # Bump PySR patch number:
          CURRENT_PYSR_PATCH_VERSION=$(python -c 'import pysr; print(pysr.version.__version__.split(".")[-1])' 2>/dev/null)
          NEW_PYSR_PATCH_VERSION=$((CURRENT_PYSR_PATCH_VERSION + 1))
          sed -i "s/^__version__ = .*/__version__ = \"$(python -c 'import pysr; print(".".join(pysr.version.__version__.split(".")[:-1]))' 2>/dev/null).${NEW_PYSR_PATCH_VERSION}\"/" pysr/version.py
          
          # Set SymbolicRegression.jl version:
          sed -i "s/^__symbolic_regression_jl_version__ = .*/__symbolic_regression_jl_version__ = \"${{ steps.get-latest.outputs.version }}\"/" pysr/version.py

          git add pysr/version.py
          git commit -m "Update backend version to v${{ steps.get-latest.outputs.version }}"

      - name: "Create PR"
        if: ${{ steps.get-latest.outputs.version != steps.get-current.outputs.version }}
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.REPO_SCOPED_TOKEN }}
          title: "Automated update to backend: v${{ steps.get-latest.outputs.version }}"
          body: |
            This PR was automatically generated by the GitHub Action
            [PySR backend update](.github/workflows/update-backend.yml).

            It updates the backend version to v${{ steps.get-latest.outputs.version }}.
            For a full description of the changes, see the backend
            changelog: [v${{ steps.get-latest.outputs.version }}](https://github.com/MilesCranmer/SymbolicRegression.jl/releases/tag/v${{ steps.get-latest.outputs.version }}).
          delete-branch: true