|
| 1 | +name: pre-commit |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: [exec] |
| 8 | + paths-ignore: |
| 9 | + - 'constraints-*.txt' |
| 10 | + |
| 11 | +jobs: |
| 12 | + pre-commit: |
| 13 | + runs-on: windows-2022 |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] |
| 17 | + name: Pre-commit WSL python ${{ matrix.python-version }} |
| 18 | + steps: |
| 19 | + - uses: Vampire/setup-wsl@v6 |
| 20 | + with: |
| 21 | + distribution: Ubuntu-24.04 |
| 22 | + use-cache: 'true' |
| 23 | + update: 'true' |
| 24 | + additional-packages: | |
| 25 | + python3 |
| 26 | + python3-pip |
| 27 | + build-essential |
| 28 | + libssl-dev |
| 29 | + zlib1g-dev |
| 30 | + libbz2-dev |
| 31 | + libreadline-dev |
| 32 | + libsqlite3-dev |
| 33 | + wget |
| 34 | + curl |
| 35 | + llvm |
| 36 | + libncurses5-dev |
| 37 | + libncursesw5-dev |
| 38 | + xz-utils |
| 39 | + tk-dev |
| 40 | + libffi-dev |
| 41 | + liblzma-dev |
| 42 | + python-openssl |
| 43 | + - name: Install pyenv in WSL |
| 44 | + shell: wsl-bash {0} |
| 45 | + run: | |
| 46 | + git clone -b v2.6.11 https://github.com/pyenv/pyenv.git ~/.pyenv |
| 47 | + cd ~/.pyenv && src/configure && make -C src |
| 48 | + |
| 49 | + echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc |
| 50 | + echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc |
| 51 | + echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc |
| 52 | + |
| 53 | + echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile |
| 54 | + echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile |
| 55 | + echo 'eval "$(pyenv init - bash)"' >> ~/.bash_profile |
| 56 | + - name: Install python ${{matrix.python-version}} using pyenv in WSL |
| 57 | + shell: wsl-bash {0} |
| 58 | + run: | |
| 59 | + pyenv install ${{matrix.python-version}} |
| 60 | + pyenv global ${{matrix.python-version}} |
| 61 | + - name: Clone repo |
| 62 | + shell: wsl-bash {0} |
| 63 | + run: | |
| 64 | + git clone --filter=blob:none --no-checkout "${{github.server_url}}/${{github.repository}}" the_repo |
| 65 | + cd the_repo |
| 66 | + git checkout "${{github.sha}}" |
| 67 | + - name: 'Install requirements (standard or constraints ${{ matrix.python-version }})' |
| 68 | + shell: wsl-bash {0} |
| 69 | + run: | |
| 70 | + cd the_repo |
| 71 | + python -mvenv .env |
| 72 | + source .env/bin/activate |
| 73 | + |
| 74 | + pip install --upgrade pip wheel |
| 75 | + constraints_file="constraints-${{ matrix.python-version }}-wsl.txt" |
| 76 | + regen_constraints= |
| 77 | + if [ -f "$constraints_file" ] ; then |
| 78 | + at="$(git --no-pager log -p -1 "--format=tformat:%at" --no-patch -- "$constraints_file")" |
| 79 | + dat="$(git --no-pager log -p -1 "--format=tformat:%at" --no-patch -- "requirements.txt")" |
| 80 | + if [ "$at" -lt "$dat" ] ; then |
| 81 | + regen_constraints=true |
| 82 | + fi |
| 83 | + else |
| 84 | + regen_constraints=true |
| 85 | + fi |
| 86 | + if [ -n "$regen_constraints" ] ; then |
| 87 | + pip install -r requirements.txt |
| 88 | + pip freeze > "$constraints_file" |
| 89 | + grep -vF git+ "$constraints_file" > "$constraints_file"-relaxed |
| 90 | + else |
| 91 | + grep -vF git+ "$constraints_file" > "$constraints_file"-relaxed |
| 92 | + pip install -r requirements.txt -c "$constraints_file"-relaxed |
| 93 | + fi |
| 94 | + - name: 'Install development requirements' |
| 95 | + shell: wsl-bash {0} |
| 96 | + run: | |
| 97 | + cd the_repo |
| 98 | + source .env/bin/activate |
| 99 | + |
| 100 | + pip install -r dev-requirements.txt -r mypy-requirements.txt -c constraints-${{ matrix.python-version }}-wsl.txt-relaxed |
| 101 | +# - name: MyPy cache |
| 102 | +# uses: actions/cache@v4 |
| 103 | +# with: |
| 104 | +# path: '.mypy_cache/[0-9]*' |
| 105 | +# key: mypy-${{ matrix.python-version }} |
| 106 | + - name: 'pre-commit' |
| 107 | + shell: wsl-bash {0} |
| 108 | + run: | |
| 109 | + cd the_repo |
| 110 | + source .env/bin/activate |
| 111 | + |
| 112 | + pre-commit run -a |
| 113 | + - name: 'pytest + coverage (${{ matrix.python-version }})' |
| 114 | + shell: wsl-bash {0} |
| 115 | + run: | |
| 116 | + cd the_repo |
| 117 | + source .env/bin/activate |
| 118 | + |
| 119 | + pytest --cov=execution_process_metrics_collector |
| 120 | + - name: Get transitive dependencies licences |
| 121 | + id: license_check_print_report |
| 122 | +# uses: pilosus/action-pip-license-checker@v1.0.0 |
| 123 | +# continue-on-error: true |
| 124 | + uses: pilosus/action-pip-license-checker@v3.1.0 |
| 125 | + with: |
| 126 | + requirements: the_repo/constraints-${{ matrix.python-version }}-wsl.txt |
| 127 | +# - name: Check transitive dependencies licences |
| 128 | +# id: license_check_report |
| 129 | +# uses: pilosus/action-pip-license-checker@v3.1.0 |
| 130 | +# with: |
| 131 | +# requirements: constraints-${{ matrix.python-version }}.txt |
| 132 | +# fail: 'StrongCopyleft' |
| 133 | +# exclude: '(?i)^(pylint|dulwich|docutils).*' |
| 134 | + - name: Print licences report |
| 135 | + if: ${{ always() }} |
| 136 | + run: echo "${{ steps.license_check_print_report.outputs.report }}" |
| 137 | + - uses: actions/upload-artifact@v4 |
| 138 | + with: |
| 139 | + name: wsl_pre-commit-${{ matrix.python-version }} |
| 140 | + retention-days: 2 |
| 141 | + path: the_repo/constraints-${{ matrix.python-version }}-wsl.txt |
| 142 | + |
| 143 | + pull_request_changes: |
| 144 | + # Do this only when it is not a pull request validation |
| 145 | + if: github.event_name != 'pull_request' |
| 146 | + runs-on: ubuntu-latest |
| 147 | + name: Pull request with the newly generated contents |
| 148 | + needs: |
| 149 | + - pre-commit |
| 150 | + steps: |
| 151 | + - name: Get analysis timestamp |
| 152 | + id: timestamp |
| 153 | + run: echo "timestamp=$(date -Is)" >> "$GITHUB_OUTPUT" |
| 154 | + - uses: actions/checkout@v5 |
| 155 | + - uses: actions/download-artifact@v5 |
| 156 | + id: download |
| 157 | + with: |
| 158 | + pattern: wsl-pre-commit-* |
| 159 | + merge-multiple: true |
| 160 | + path: changes-dir |
| 161 | + - name: Move artifacts to their right place |
| 162 | + id: move |
| 163 | + run: | |
| 164 | + skip=true |
| 165 | + if [ -d "${{steps.download.outputs.download-path}}" ] ; then |
| 166 | + for con in "${{steps.download.outputs.download-path}}"/constraints-*-wsl.txt ; do |
| 167 | + case "$con" in |
| 168 | + */constraints-\*-wsl.txt) |
| 169 | + break |
| 170 | + ;; |
| 171 | + *) |
| 172 | + cp -p "$con" . |
| 173 | + skip=false |
| 174 | + ;; |
| 175 | + esac |
| 176 | + done |
| 177 | + fi |
| 178 | + echo "skip=$skip" >> "$GITHUB_OUTPUT" |
| 179 | + - name: Create Pull Request |
| 180 | + id: cpr |
| 181 | + uses: peter-evans/create-pull-request@v7 |
| 182 | + if: steps.move.outputs.skip == 'false' |
| 183 | + with: |
| 184 | + title: Updated WSL constraints (triggered on ${{ steps.timestamp.outputs.timestamp }} by ${{ github.sha }}) |
| 185 | + branch: create-pull-request/patch-constraints |
| 186 | + add-paths: constraints-*-wsl.txt |
| 187 | + delete-branch: true |
| 188 | + commit-message: "[create-pull-request] Automatically commit updated contents (constraints WSL)" |
| 189 | + - name: Check outputs |
| 190 | + if: ${{ steps.cpr.outputs.pull-request-number }} |
| 191 | + run: | |
| 192 | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" >> "$GITHUB_STEP_SUMMARY" |
| 193 | + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments