-
Notifications
You must be signed in to change notification settings - Fork 4
153 lines (122 loc) · 4.94 KB
/
update_pip.yaml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# This workflow will automatically update the bundled pip and
# will create and update PRs in a similar way to dependabot.
#
# Notes:
# * If someone force pushes the main branch at around the same time as the scheduled run,
# it the run will probably fail with obscure errors.
# * I suspects this is true for non-forced push commits too.
name: update_pip
on:
schedule:
- cron: '0 0 * * 0' # Run at midnight UTC only on sunday
workflow_dispatch:
permissions:
pull-requests: write
contents: write
jobs:
update:
name: update
runs-on: ubuntu-latest
# Don't run on forks
if: github.repository == 'JeanChristopheMorinPerso/rez-pip'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Check if pip is up-to-date and download if not
run: |
set -e
error_code=0
git fetch origin __update_pip__ > /dev/null 2>&1 || error_code=$?
if [[ $error_code -eq 0 ]]; then
echo 'Switching to __update_pip__ branch'
set -x
git switch __update_pip__
git pull origin __update_pip__
else
echo 'Branch __update_pip__ does not exists'
fi
set -x
pipx run nox -s download_pip
if [[ $error_code -eq 0 ]]; then
git switch -
fi
id: download_pip
- name: Confirm step outputs
run: |
set -e
if [[ '${{ steps.download_pip.outputs.downloaded-pip-path }}' == '' ]]; then
echo 'steps.download_pip.outputs.downloaded-pip-path is empty!'
exit 1
fi
if [[ '${{ steps.download_pip.outputs.previous-pip-version }}' == '' ]]; then
echo 'steps.download_pip.outputs.previous-pip-version is empty!'
exit 1
fi
- name: Get __update_pip__ PR number
if: steps.download_pip.outputs.downloaded-pip-path != 'none'
id: get-pull-request-number
env:
GH_TOKEN: ${{ github.token }}
run: |
set -ex
number=$(gh pr list --app rez-pip-update-bot --limit 1 --head __update_pip__ --json number --jq '.[].number')
echo "number=${number}" >> $GITHUB_OUTPUT
- name: Get token
id: app-token
if: steps.download_pip.outputs.downloaded-pip-path != 'none'
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_BOT_APP_ID }}
private-key: ${{ secrets.GH_BOT_PRIVATE_KEY }}
- name: Create commit
if: steps.download_pip.outputs.downloaded-pip-path != 'none'
run: |
set -ex
if [ -z ${{ steps.get-pull-request-number.outputs.number }} ]; then
echo 'Creating branch named __update_pip__'
git switch -c __update_pip__
else
echo '__update_pip__ already exists. Re-using it'
git fetch origin __update_pip__
git switch __update_pip__
fi
cp -v ${{ steps.download_pip.outputs.downloaded-pip-path }} src/rez_pip/data/pip.pyz
git add src/rez_pip/data/pip.pyz
# https://stackoverflow.com/a/74071223
git config user.name 'rez-pip-update-bot[bot]'
# 133434221 comes from https://api.github.com/users/rez-pip-update-bot[bot]
git config user.email '133434221+rez-pip-update-bot[bot]@users.noreply.github.com'
git commit --signoff -m 'Update pip from ${{ steps.download_pip.outputs.previous-pip-version }} to ${{ steps.download_pip.outputs.new-pip-version }}'
git push origin __update_pip__
- name: PR
if: steps.download_pip.outputs.downloaded-pip-path != 'none'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -e
version=$(echo '${{ steps.download_pip.outputs.new-pip-version }}' | sed 's/\./-/g')
title='Update pip to ${{ steps.download_pip.outputs.new-pip-version }}'
cat << EOF > $RUNNER_TEMP/pr_body
Update pip from ${{ steps.download_pip.outputs.previous-pip-version }} to ${{ steps.download_pip.outputs.new-pip-version }}.
Changelog: https://pip.pypa.io/en/stable/news/#v${version}.
---
_This PR was created by the [rez-pip-update-bot](https://github.com/apps/rez-pip-update-bot) bot and the workflow located at [.github/workflows/update_pip.yaml](../blob/main/.github/workflows/update_pip.yaml)_
EOF
if [[ '${{ steps.get-pull-request-number.outputs.number }}' != '' ]]; then
echo 'Updating PR #${{ steps.get-pull-request-number.outputs.number }}'
set -x
gh pr edit ${{ steps.get-pull-request-number.outputs.number }} \
--title "${title}" \
--body-file $RUNNER_TEMP/pr_body
else
echo 'Creating new PR'
set -x
gh pr create \
--base main \
--head __update_pip__ \
--title "${title}" \
--body-file $RUNNER_TEMP/pr_body \
--label 'pip-update'
fi