-
Notifications
You must be signed in to change notification settings - Fork 1
117 lines (102 loc) · 4.09 KB
/
Copy pathci_update_requirements.yml
File metadata and controls
117 lines (102 loc) · 4.09 KB
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
name: CI - Check for updates to `requirements.txt`
on:
schedule:
# At 7:30 every Monday (6:30 UTC)
- cron: "30 6 * * 1"
workflow_dispatch:
env:
GIT_USER_NAME: "TEAM 4.0[bot]"
GIT_USER_EMAIL: "Team4.0@SINTEF.no"
jobs:
update-requirements:
name: Update `requirements.txt`
if: github.repository_owner == 'EMMC-ASBL'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: 'master'
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Set up git config
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Install immediate requirements
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install --no-cache-dir --upgrade-strategy=eager -U -r .github/utils/direct_requirements.txt
- name: Run `pip freeze` and update current `requirements.txt`
id: update_requirements
run: |
pip freeze > requirements_new.txt
if [ "$(diff requirements.txt requirements_new.txt)" ]; then
# There are updates !
mv -f requirements_new.txt requirements.txt
echo -e "requirements.txt has been updated. Diff:\n$(git diff requirements.txt)"
echo "update_deps=true" >> $GITHUB_OUTPUT
# Possibly also update the 'direct_requirements.txt' file for minimum versions.
while IFS= read -r line_direct; do
echo "line direct: ${line_direct}"
if [[ "${line_direct}" =~ ^([a-zA-Z_-]+)\>=.*$ ]]; then
package="${BASH_REMATCH[1]}"
echo "package: ${package}"
while IFS= read -r line_full; do
echo "line full: ${line_full}"
if [[ "${line_full}" =~ ^"${package}"==(.*)$ ]]; then
version="${BASH_REMATCH[1]}"
echo "version: ${version}"
sed -i "s|${package}>=.*|${package}>=${version}|" ".github/utils/direct_requirements.txt"
break
fi
done < requirements.txt
fi
done < .github/utils/direct_requirements.txt
git add requirements.txt
if [ -n "$(git status --porcelain .github/utils/direct_requirements.txt)" ]; then
git add .github/utils/direct_requirements.txt
fi
git commit -m "Update \`requirements.txt\`"
else
# No changes
echo "No changes found for requirements.txt."
echo "update_deps=false" >> $GITHUB_OUTPUT
fi
- name: Fetch PR body
if: steps.update_requirements.outputs.update_deps == 'true'
id: pr_body
run: |
TEMPLATE_FILE=".github/utils/requirements_update_pr_body.txt"
if [ -f "${TEMPLATE_FILE}" ]; then
echo "Template file found: ${TEMPLATE_FILE}"
CONTENT="$(cat "${TEMPLATE_FILE}")"
else
echo "Template file not found: ${TEMPLATE_FILE}"
# Bail out
exit 1
fi
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "${CONTENT}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create PR
if: steps.update_requirements.outputs.update_deps == 'true'
id: cpr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.RELEASE_PAT }}
commit-message: "Update `requirements.txt`"
committer: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>"
author: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>"
branch: ci/update-requirements
delete-branch: true
title: "[Auto-generated] Update `requirements.txt`"
body: ${{ steps.pr_body.outputs.content }}
labels: CI/CD,skip-changelog
- name: Information
if: steps.update_requirements.outputs.update_deps == 'true'
run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"'