|
| 1 | +# Workflow to update lock files in a PR, triggered by specific PR comments |
| 2 | +name: Update lock files in PR |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + update-lock-files: |
| 12 | + if: >- |
| 13 | + github.event.issue.pull_request |
| 14 | + && startsWith(github.event.comment.body, '@scikit-learn-bot update lock-files') |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + # There is no direct way to get the HEAD information directly from issue_comment |
| 19 | + # event, so we use the GitHub CLI to get the PR head ref and repository |
| 20 | + - name: Get pull request HEAD information |
| 21 | + id: pr-head-info |
| 22 | + env: |
| 23 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run: | |
| 25 | + pr_info=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName,headRepository,headRepositoryOwner) |
| 26 | + pr_head_ref=$(echo "$pr_info" | jq -r '.headRefName') |
| 27 | + pr_head_repository=$(echo "$pr_info" | jq -r '.headRepositoryOwner.login + "/" + .headRepository.name') |
| 28 | + echo "pr_head_ref=$pr_head_ref" >> $GITHUB_OUTPUT |
| 29 | + echo "pr_head_repository=$pr_head_repository" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + - name: Check out the PR branch |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + ref: ${{ steps.pr-head-info.outputs.pr_head_ref }} |
| 35 | + repository: ${{ steps.pr-head-info.outputs.pr_head_repository }} |
| 36 | + |
| 37 | + # We overwrite all the scripts we are going to use in this workflow with their |
| 38 | + # versions on main; since this workflow has the write permissions this is to avoid |
| 39 | + # malicious changes to these scripts in PRs to be executed |
| 40 | + - name: Download scripts from main |
| 41 | + run: | |
| 42 | + curl https://raw.githubusercontent.com/${{ github.repository }}/comment-update-lock/build_tools/shared.sh --retry 5 -o ./build_tools/shared.sh |
| 43 | + curl https://raw.githubusercontent.com/${{ github.repository }}/comment-update-lock/build_tools/update_environments_and_lock_files.py --retry 5 -o ./build_tools/update_environments_and_lock_files.py |
| 44 | + curl https://raw.githubusercontent.com/${{ github.repository }}/comment-update-lock/build_tools/on_pr_comment_update_environments_and_lock_files.py --retry 5 -o ./build_tools/on_pr_comment_update_environments_and_lock_files.py |
| 45 | +
|
| 46 | + - name: Update lock files |
| 47 | + env: |
| 48 | + COMMENT: ${{ github.event.comment.body }} |
| 49 | + # We download the lock files update scripts from main, since this workflow is |
| 50 | + # run from main itself |
| 51 | + run: | |
| 52 | + source build_tools/shared.sh |
| 53 | + source $CONDA/bin/activate |
| 54 | + conda install -n base conda conda-libmamba-solver -y |
| 55 | + conda config --set solver libmamba |
| 56 | + conda install -c conda-forge "$(get_dep conda-lock min)" -y |
| 57 | +
|
| 58 | + python build_tools/on_pr_comment_update_environments_and_lock_files.py |
0 commit comments