File: upgrade-dependencies.yml

package info (click to toggle)
python-maggma 0.72.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,388 kB
  • sloc: python: 9,610; makefile: 12
file content (93 lines) | stat: -rw-r--r-- 4,902 bytes parent folder | download | duplicates (2)
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
# https://www.oddbird.net/2022/06/01/dependabot-single-pull-request/
# https://github.com/materialsproject/MPContribs/blob/master/.github/workflows/upgrade-dependencies.yml
name: upgrade dependencies

on:
  workflow_dispatch: # Allow running on-demand
  schedule:
    # Runs every Monday at 8:00 UTC (4:00 Eastern)
    - cron: '0 8 * * 1'

jobs:
  upgrade:
    name: ${{ matrix.package }} (${{ matrix.os }}/py${{ matrix.python-version }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ['ubuntu-latest', 'macos-latest']
        package: ["."]
        python-version: ["3.9", "3.10", "3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
      - name: Upgrade Python dependencies
        shell: bash
        run: |
          python${{ matrix.python-version }} -m pip install --upgrade pip pip-tools
          cd ${{ matrix.package }}
          python${{ matrix.python-version }} -m piptools compile -q --upgrade --resolver=backtracking -o requirements/${{ matrix.os }}_py${{ matrix.python-version }}.txt
          python${{ matrix.python-version }} -m piptools compile -q --upgrade --resolver=backtracking --all-extras -o requirements/${{ matrix.os }}_py${{ matrix.python-version }}_extras.txt
      - name: Detect changes
        id: changes
        shell: bash
        run: |
          #git diff-index HEAD ${{ matrix.package }}/requirements/${{ matrix.os }}_py${{ matrix.python-version }}*.txt | awk '{print $4}' | sort -u
          #sha1=$(git diff-index HEAD ${{ matrix.package }}/requirements/${{ matrix.os }}_py${{ matrix.python-version }}*.txt | awk '{print $4}' | sort -u | head -n1)
          #[[ $sha1 == "0000000000000000000000000000000000000000" ]] && git update-index --really-refresh ${{ matrix.package }}/requirements/${{ matrix.os }}_py${{ matrix.python-version }}*.txt
          echo "count=$(git diff-index HEAD ${{ matrix.package }}/requirements/${{ matrix.os }}_py${{ matrix.python-version }}*.txt | wc -l | xargs)" >> $GITHUB_OUTPUT
          echo "files=$(git ls-files --exclude-standard --others ${{ matrix.package }}/requirements/${{ matrix.os }}_py${{ matrix.python-version }}*.txt | wc -l | xargs)" >> $GITHUB_OUTPUT
      - name: commit & push changes
        if: steps.changes.outputs.count > 0 || steps.changes.outputs.files > 0
        shell: bash
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add ${{ matrix.package }}/requirements
          git commit -m "update dependencies for ${{ matrix.package }} (${{ matrix.os }}/py${{ matrix.python-version }})"
          git push -f origin ${{ github.ref_name }}:auto-dependency-upgrades-${{ matrix.package }}-${{ matrix.os }}-py${{ matrix.python-version }}

  pull_request:
    name: Merge all branches and open PR
    runs-on: ubuntu-latest
    needs: upgrade
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: detect auto-upgrade-dependency branches
        id: changes
        run: echo "count=$(git branch -r | grep auto-dependency-upgrades- | wc -l | xargs)" >> $GITHUB_OUTPUT
      - name: merge all auto-dependency-upgrades branches
        if: steps.changes.outputs.count > 0
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git checkout -b auto-dependency-upgrades
          git branch -r | grep auto-dependency-upgrades- | xargs -I {} git merge {}
          git rebase ${GITHUB_REF##*/}
          git push -f origin auto-dependency-upgrades
          git branch -r | grep auto-dependency-upgrades- | cut -d/ -f2 | xargs -I {} git push origin :{}
      - name: Open pull request if needed
        if: steps.changes.outputs.count > 0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        # Only open a PR if the branch is not attached to an existing one
        # note that this auto-created PR will not trigger the testing workflow, which
        # is an intentional limitation imposed by GitHub. See
        # https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
        # The simplest workaround is to close and immediately re-open the Auto PR
        run: |
          PR=$(gh pr list --head auto-dependency-upgrades --json number -q '.[0].number')
          if [ -z $PR ]; then
            gh pr create \
            --head auto-dependency-upgrades \
            --title "Automated dependency upgrades" \
            --body "Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          else
            echo "Pull request already exists, won't create a new one."
          fi