-
Notifications
You must be signed in to change notification settings - Fork 50
114 lines (91 loc) · 3.86 KB
/
update-python-deps.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
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Update Python Dependencies
on:
schedule:
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
- cron: '0 10 * * *' # daily at 10 a.m.
workflow_dispatch:
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
defaults:
run:
shell: bash
env:
PYTHON_VERSION: "3.10"
jobs:
###########################################################
update-python-deps:
###########################################################
runs-on: ubuntu-latest
steps:
- name: "Show: GitHub context"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo $GITHUB_CONTEXT
- name: "Show: environment variables"
run: env | sort
- name: Generate GitHub Access Token
uses: tibdex/github-app-token@v2 #https://github.com/tibdex/github-app-token
id: generate_token
# see https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens
with:
# see https://github.com/organizations/Second-Hand-Friends/settings/apps/kleinanzeigen-bot-tu
app_id: ${{ secrets.DEPS_UPDATER_APP_ID }}
private_key: ${{ secrets.DEPS_UPDATER_PRIVATE_KEY }}
- name: Git Checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout
with:
token: ${{ steps.generate_token.outputs.token }}
- name: "Install: Python and PDM" # https://github.com/pdm-project/setup-pdm
uses: pdm-project/setup-pdm@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
cache: true
- name: "Install: Python dependencies"
run: |
set -eux
python --version
python -m pip install --upgrade pip
pip install --upgrade pdm
if [[ ! -e .venv ]]; then
pdm venv create || true
fi
pdm sync --clean -v
- name: Update Python dependencies
id: update_deps
run: |
set -euo pipefail
set -x
exec 5>&1
updates=$(pdm update --update-all 2>&1 | tee /dev/fd/5)
if git diff --exit-code pdm.lock; then
echo "updates=" >> "$GITHUB_OUTPUT"
else
updates="$(echo "$updates" | grep Update | grep -v kleinanzeigen-bot || true)"
if [[ $(wc -l <<< "$updates") -eq 1 ]]; then
echo "title=$(echo "$updates" | head -n 1 | sed 's/ successful//')" >> "${GITHUB_OUTPUT}"
else
echo "title=Update Python dependencies" >> "${GITHUB_OUTPUT}"
fi
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
delimiter="$(openssl rand -hex 8)"
echo "updates<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$updates" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
fi
- name: Create PR
uses: peter-evans/create-pull-request@v7 # https://github.com/peter-evans/create-pull-request
if: "${{ steps.update_deps.outputs.updates != '' }}"
with:
title: "chore: ${{ steps.update_deps.outputs.title }}"
author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
commit-message: "chore: ${{ steps.update_deps.outputs.title }}"
body: ${{ steps.update_deps.outputs.updates }}
add-paths: pdm.lock
branch: dependencies/pdm
delete-branch: true
token: ${{ steps.generate_token.outputs.token }}