Skip to content

Commit 67848fc

Browse files
committed
Create refresh-lockfiles.yml
1 parent 5c52b87 commit 67848fc

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# This workflow periodically creates new environment lock files based on the newest
2+
# available packages and dependencies.
3+
#
4+
# Environment specifications are given as conda environment.yml files found in
5+
# `requirements/py**.yml`. These state the packages required, the conda channels
6+
# that the packages will be pulled from, and any versions of packages that need to be
7+
# pinned at specific versions.
8+
#
9+
# For environments that have changed, a pull request will be made and submitted
10+
# to the main branch
11+
12+
name: Refresh Lockfiles
13+
14+
15+
on:
16+
workflow_call:
17+
18+
jobs:
19+
get_python_matrix:
20+
# Determines which Python versions should be included in the matrix used in
21+
# the gen_lockfiles job.
22+
if: "github.repository_owner == 'pydata' || github.event_name == 'workflow_dispatch'"
23+
runs-on: ubuntu-latest
24+
outputs:
25+
matrix: ${{ steps.get_py.outputs.matrix }}
26+
steps:
27+
- uses: actions/checkout@v5
28+
- id: get_py
29+
run: echo "MATRIX=$(ls -1 requirements/py*.yml | xargs -n1 basename | sed 's/....$//' | jq -cnR '[inputs]')" >> ${GITHUB_OUTPUT}
30+
31+
gen_lockfiles:
32+
# This is a matrix job: it splits to create new lockfiles for each
33+
# of the CI test python versions.
34+
if: "github.repository_owner == 'pydata' || github.event_name == 'workflow_dispatch'"
35+
runs-on: ubuntu-latest
36+
needs: get_python_matrix
37+
38+
strategy:
39+
matrix:
40+
python: ${{ fromJSON(needs.get_python_matrix.outputs.MATRIX) }}
41+
42+
steps:
43+
- uses: actions/checkout@v5
44+
- name: install requirements
45+
run: |
46+
source $CONDA/bin/activate base
47+
conda update -n base --all
48+
- name: generate lockfile
49+
run: |
50+
pipx run conda-lock -k explicit -p linux-64 -f requirements/${{matrix.python}}.yml
51+
mv conda-linux-64.lock ${{matrix.python}}-linux-64.lock
52+
- name: output lockfile
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: lock-artifacts-${{matrix.python}}
56+
path: ${{matrix.python}}-linux-64.lock
57+
58+
create_pr:
59+
# Once the matrix job has completed all the lock files will have been
60+
# uploaded as artifacts.
61+
# Download the artifacts, add them to the repo, and create a PR.
62+
if: "github.repository_owner == 'pydata' || github.event_name == 'workflow_dispatch'"
63+
runs-on: ubuntu-latest
64+
needs: gen_lockfiles
65+
66+
steps:
67+
- uses: actions/checkout@v5
68+
- name: get artifacts
69+
uses: actions/download-artifact@v5
70+
with:
71+
path: ${{ github.workspace }}/requirements/locks
72+
merge-multiple: true
73+
74+
- name: "Generate token"
75+
uses: actions/create-github-app-token@v2
76+
id: generate-token
77+
with:
78+
app-id: ${{ secrets.AUTH_APP_ID }}
79+
private-key: ${{ secrets.AUTH_APP_PRIVATE_KEY }}
80+
81+
- name: Create Pull Request
82+
id: cpr
83+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
84+
with:
85+
token: ${{ steps.generate-token.outputs.token }}
86+
commit-message: Updated environment lockfiles
87+
committer: "Lockfile bot <[email protected]>"
88+
author: "Lockfile bot <[email protected]>"
89+
delete-branch: true
90+
branch: auto-update-lockfiles
91+
title: "[CI Bot] environment lockfiles auto-update"
92+
body: |
93+
Lockfiles updated to the latest resolvable environment.
94+
### If the CI tasks fail, create a new branch based on this PR and add the required fixes to that branch.
95+
labels: |
96+
New: Pull Request
97+
Bot
98+
99+
- name: Check Pull Request
100+
if: steps.cpr.outputs.pull-request-number != ''
101+
run: |
102+
echo "### :rocket: Pull-Request Summary" >> ${GITHUB_STEP_SUMMARY}
103+
echo "" >> ${GITHUB_STEP_SUMMARY}
104+
echo "The following lock-files pull-request has been auto-generated:"
105+
echo "- **PR** #${{ steps.cpr.outputs.pull-request-number }}" >> ${GITHUB_STEP_SUMMARY}
106+
echo "- **URL** ${{ steps.cpr.outputs.pull-request-url }}" >> ${GITHUB_STEP_SUMMARY}
107+
echo "- **Operation** [${{ steps.cpr.outputs.pull-request-operation }}]" >> ${GITHUB_STEP_SUMMARY}
108+
echo "- **SHA** ${{ steps.cpr.outputs.pull-request-head-sha }}" >> ${GITHUB_STEP_SUMMARY}

0 commit comments

Comments
 (0)