|
| 1 | +name: Clippy changelog check |
| 2 | + |
| 3 | +on: |
| 4 | + merge_group: |
| 5 | + pull_request: |
| 6 | + types: [opened, reopened, edited] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + # For a given workflow, if we push to the same PR, cancel all previous builds on that PR. |
| 10 | + # If the push is not attached to a PR, we will cancel all builds on the same branch. |
| 11 | + group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + changelog: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + |
| 22 | + steps: |
| 23 | + # Run |
| 24 | + - name: Check Changelog |
| 25 | + if: ${{ github.event_name == 'pull_request' }} |
| 26 | + run: | |
| 27 | + body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR_NUMBER" | \ |
| 28 | + python -c "import sys, json; print(json.load(sys.stdin)['body'])") |
| 29 | + output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || { |
| 30 | + echo "ERROR: pull request message must contain 'changelog: ...'. Please add it." |
| 31 | + exit 1 |
| 32 | + } |
| 33 | + echo "changelog: $output" |
| 34 | + env: |
| 35 | + PYTHONIOENCODING: 'utf-8' |
| 36 | + PR_NUMBER: '${{ github.event.number }}' |
| 37 | + |
| 38 | + # We need to have the "conclusion" job also on PR CI, to make it possible |
| 39 | + # to add PRs to a merge queue. |
| 40 | + conclusion_changelog: |
| 41 | + needs: [ changelog ] |
| 42 | + # We need to ensure this job does *not* get skipped if its dependencies fail, |
| 43 | + # because a skipped job is considered a success by GitHub. So we have to |
| 44 | + # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run |
| 45 | + # when the workflow is canceled manually. |
| 46 | + # |
| 47 | + # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! |
| 48 | + if: ${{ !cancelled() }} |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + # Manually check the status of all dependencies. `if: failure()` does not work. |
| 52 | + - name: Conclusion |
| 53 | + run: | |
| 54 | + # Print the dependent jobs to see them in the CI log |
| 55 | + jq -C <<< '${{ toJson(needs) }}' |
| 56 | + # Check if all jobs that we depend on (in the needs array) were successful. |
| 57 | + jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' |
0 commit comments