-
Notifications
You must be signed in to change notification settings - Fork 5
119 lines (99 loc) · 4.49 KB
/
conda-lock.yml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: "Update conda lock files"
on:
schedule:
- cron: "37 5 * * 1"
workflow_dispatch:
permissions:
pull-requests: write
contents: write
jobs:
update-conda-lock-files:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: "3.11"
- name: Install dependencies
run: python3 -m pip install conda-lock
- name: Update conda
run: conda update --channel conda-forge --quiet conda
- name: Hash existing lock files
run: |
shopt -s globstar
sha256sum **/locks/*.txt > ${{ runner.temp }}/lock_file_hashes
cat ${{ runner.temp }}/lock_file_hashes
- name: Switch branch
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git switch -c conda-lock-files
- name: Update CSET developer and workflow lock files
run: |
py_vers="3.10 3.11 3.12 3.13"
for py_ver in $py_vers
do
# Developer lock files.
cp "requirements/environment.yml" "${{ runner.temp }}/${py_ver}_dev_environment.yml"
echo -e "\n - python = $py_ver" >> "${{ runner.temp }}/${py_ver}_dev_environment.yml"
conda-lock --channel conda-forge --kind explicit --file "${{ runner.temp }}/${py_ver}_dev_environment.yml" --platform linux-64 --filename-template "requirements/locks/py$(echo $py_ver | sed 's/\.//')-lock-linux-64.txt"
# Workflow lock files.
cp "cset-workflow/requirements/environment.yml" "${{ runner.temp }}/${py_ver}_workflow_environment.yml"
echo -e "\n - python = $py_ver" >> "${{ runner.temp }}/${py_ver}_workflow_environment.yml"
conda-lock --channel conda-forge --kind explicit --file "${{ runner.temp }}/${py_ver}_workflow_environment.yml" --platform linux-64 --filename-template "cset-workflow/requirements/locks/py$(echo $py_ver | sed 's/\.//')-lock-linux-64.txt"
done
wait
- name: Sort lock files to make diffs easier to review
run: |
shopt -s globstar
for file in **/locks/*.txt
do
cat "$file" | (sed -u 4q; sort) > sorted.txt
mv sorted.txt "$file"
done
- name: Generate GitHub App Token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69
id: app-token
with:
app-id: ${{ secrets.AUTH_APP_ID }}
private-key: ${{ secrets.AUTH_APP_PRIVATE_KEY }}
- name: Create pull requests
env:
source_ref: ${{ github.ref }}
source_ref_type: ${{ github.ref_type }}
run: |
shopt -s globstar
# Display any changes in the log.
git diff --name-status
# Exit early if there are no changes.
if $(sha256sum --status -c ${{ runner.temp }}/lock_file_hashes)
then
echo "Lock files unchanged. Skipping pull request..."
exit 0
fi
# Commit changed lockfiles.
git add **/locks/*.txt
git commit -m "[CI] Update conda lock files"
# Update lock_file_hashes so pushed branch name is unique.
sha256sum **/locks/*.txt > ${{ runner.temp }}/lock_file_hashes
remote_branch_name="conda-lock-$(sha256sum ${{ runner.temp }}/lock_file_hashes | head -c 8)"
# If running from a branch target the created PR at that branch.
if [[ $source_ref_type = branch ]]
then
base_branch_name="$source_ref"
else
base_branch_name="main"
fi
# Push branch to GitHub.
git push --set-upstream origin "conda-lock-files:${remote_branch_name}"
# Create PR on GitHub using GitHub REST API.
request_body='{"title":"[CI] Update conda lock files","body":"Created automatically by GitHub Actions.","base":"'"${base_branch_name}"'","head":"'"${remote_branch_name}"'"}'
curl -LsS --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ steps.app-token.outputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d "$request_body"