|
| 1 | +name: CI |
| 2 | +concurrency: |
| 3 | + group: ${{ github.head_ref }} |
| 4 | + cancel-in-progress: true |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - reopened |
| 11 | + - labeled |
| 12 | + - unlabeled |
| 13 | + - synchronize |
| 14 | + branches: |
| 15 | + - main |
| 16 | + - stable-* |
| 17 | + tags: |
| 18 | + - '*' |
| 19 | + |
| 20 | +jobs: |
| 21 | + auto_changelog: |
| 22 | + name: changelog / black formatting |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout the collection repository |
| 26 | + uses: actions/checkout@v3 |
| 27 | + with: |
| 28 | + fetch-depth: "0" |
| 29 | + |
| 30 | + - name: Set up Python '3.9' |
| 31 | + uses: actions/setup-python@v4 |
| 32 | + with: |
| 33 | + python-version: '3.9' |
| 34 | + |
| 35 | + # black should be defined as input parameter of the action |
| 36 | + - name: Install python dependencies |
| 37 | + run: | |
| 38 | + pip install -U pyyaml pygithub tox |
| 39 | + shell: bash |
| 40 | + |
| 41 | + - name: Download script |
| 42 | + run: >- |
| 43 | + curl -o /tmp/add_changelog.py |
| 44 | + https://raw.githubusercontent.com/abikouo/gha_testing/main/tools/add_changelog.py |
| 45 | +
|
| 46 | + - name: Validate or add pull request changelog |
| 47 | + run: |
| 48 | + python3 /tmp/add_changelog.py |
| 49 | + env: |
| 50 | + PR_REPOSITORY: ${{ github.repository }} |
| 51 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 52 | + |
| 53 | + - name: Run black check |
| 54 | + id: black_check |
| 55 | + continue-on-error: true |
| 56 | + run: | |
| 57 | + tox -e black -vv 2>/tmp/black_check.txt |
| 58 | + shell: bash |
| 59 | + |
| 60 | + - name: Run black formatting |
| 61 | + run: | |
| 62 | + tox -e black_format -vv -- $(grep "would reformat" /tmp/black_check.txt | cut -d ' ' -f3 | tr '\n' ' ') |
| 63 | + shell: bash |
| 64 | + if: steps.black_check.outcome != 'success' |
| 65 | + |
| 66 | + - name: (debug only) list files in diff |
| 67 | + run: | |
| 68 | + git status |
| 69 | + shell: bash |
| 70 | + if: steps.black_check.outcome != 'success' |
| 71 | + |
| 72 | + - name: commit and push changes |
| 73 | + id: commit |
| 74 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 75 | + with: |
| 76 | + commit_message: "automated changes for changelog and/or black formatting" |
0 commit comments