-
Notifications
You must be signed in to change notification settings - Fork 30
79 lines (70 loc) · 2.87 KB
/
cookiecutter.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
name: Autoupdate project structure
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # at the end of every day
jobs:
auto-update-project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: python -m pip install cruft poetry jello tabulate
- name: Update project structure
run: |
cruft update -y
- name: Check if there are changes
id: changes
run: echo "::set-output name=changed::$(git status --porcelain | wc -l)"
- name: apply additional changes and fixes
if: steps.changes.outputs.changed > 0
run: |
poetry lock --no-update # add new dependencies
poetry install
poetry run pre-commit run -a || true # we have to fix other issues manually
- name: Get template versions
id: get_versions
if: steps.changes.outputs.changed > 0
shell: bash
run: |
CURRENT_VERSION=$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
NEXT_VERSION=$(jello -r "_['commit'][:8]" < .cruft.json)
echo ::set-output name="current_version::$CURRENT_VERSION"
echo ::set-output name="next_version::$NEXT_VERSION"
- name: Get changelog
id: get_changelog
if: steps.changes.outputs.changed > 0
shell: bash
run: |
TEMPLATE=$(jello -r "_['template']" < .cruft.json)
git clone "$TEMPLATE" /tmp/template
cd /tmp/template
body=$( (echo "Date;Change;Hash"; git log --pretty=format:"%as;%s;%h" ${{ steps.get_versions.outputs.current_version }}..${{ steps.get_versions.outputs.next_version }}) | tabulate --header --format github -s ';' -)
body=$(cat <<EOF
Changes from $TEMPLATE
$body
EOF
)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name="changelog::$body"
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
env:
# a PAT is required to be able to update workflows
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}
if: ${{ steps.changes.outputs.changed > 0 && env.GITHUB_TOKEN != 0 }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ env.GITHUB_TOKEN }}
commit-message: >-
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
title: "[Actions] Auto-Update cookiecutter template"
body: ${{ steps.get_changelog.outputs.changelog }}
branch: chore/auto-update-project-from-template
delete-branch: true