|
| 1 | +name: Autoupdate project structure |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" # at the end of every day |
| 6 | + |
| 7 | +jobs: |
| 8 | + auto-update-project: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v2 |
| 12 | + - name: Set up Python |
| 13 | + uses: actions/setup-python@v2 |
| 14 | + with: |
| 15 | + python-version: 3.9 |
| 16 | + |
| 17 | + - name: Set credentials for private templates |
| 18 | + run: | |
| 19 | + git config --global url."https://api:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" |
| 20 | + git config --global url."https://ssh:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "ssh://git@github.com/" |
| 21 | + git config --global url."https://git:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "git@github.com:" |
| 22 | +
|
| 23 | + - name: Install dependencies |
| 24 | + run: python -m pip install cruft poetry jello tabulate |
| 25 | + |
| 26 | + - name: Update project structure |
| 27 | + run: | |
| 28 | + cruft update -y |
| 29 | +
|
| 30 | + - name: Check if there are changes |
| 31 | + id: changes |
| 32 | + uses: UnicornGlobal/has-changes-action@v1.0.11 |
| 33 | + |
| 34 | + - name: apply additional changes and fixes |
| 35 | + if: steps.changes.outputs.changed == 1 |
| 36 | + run: | |
| 37 | + poetry lock --no-update # add new dependencies |
| 38 | + poetry install |
| 39 | + poetry run pre-commit run -a || true # we have to fix other issues manually |
| 40 | +
|
| 41 | + - name: Get template versions |
| 42 | + id: get_versions |
| 43 | + if: steps.changes.outputs.changed == 1 |
| 44 | + run: | |
| 45 | + echo ::set-output name=current_version::$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]") |
| 46 | + echo ::set-output name=next_version::$(cat .cruft.json | jello -r "_['commit'][:8]") |
| 47 | +
|
| 48 | + - name: Get changelog |
| 49 | + id: get_changelog |
| 50 | + if: steps.changes.outputs.changed == 1 |
| 51 | + run: | |
| 52 | + export TEMPLATE=$(cat .cruft.json | jello -r "_['template']") |
| 53 | + git clone $TEMPLATE /tmp/template |
| 54 | + cd /tmp/template |
| 55 | + 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 ';' -) |
| 56 | + body=$(cat <<EOF |
| 57 | + Changes from $TEMPLATE |
| 58 | +
|
| 59 | + $body |
| 60 | + EOF |
| 61 | + ) |
| 62 | + body="${body//'%'/'%25'}" |
| 63 | + body="${body//$'\n'/'%0A'}" |
| 64 | + body="${body//$'\r'/'%0D'}" |
| 65 | + echo ::set-output name=changelog::$body |
| 66 | +
|
| 67 | + # behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour |
| 68 | + - name: Create Pull Request |
| 69 | + env: |
| 70 | + # a PAT is required to be able to update workflows |
| 71 | + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }} |
| 72 | + if: ${{ steps.changes.outputs.changed == 1 && env.GITHUB_TOKEN != 0 }} |
| 73 | + uses: peter-evans/create-pull-request@v3 |
| 74 | + with: |
| 75 | + token: ${{ env.GITHUB_TOKEN }} |
| 76 | + commit-message: >- |
| 77 | + chore: update project structure to ${{ steps.get_versions.outputs.next_version }} |
| 78 | + title: "[Actions] Auto-Update cookiecutter template" |
| 79 | + body: ${{ steps.get_changelog.outputs.changelog }} |
| 80 | + branch: chore/auto-update-project-from-template |
| 81 | + delete-branch: true |
0 commit comments