|
17 | 17 | lint:
|
18 | 18 | uses: delineaxpm/github-workflows/.github/workflows/lint.yml@main
|
19 | 19 | secrets: inherit
|
| 20 | + |
| 21 | + changie-validation: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check for .changes directory |
| 25 | + id: check_changes_dir |
| 26 | + run: | |
| 27 | + if [ ! -d ".changes" ]; then |
| 28 | + echo "No .changes directory found, skipping changie validation." |
| 29 | + exit 0 |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Check for changie entry |
| 33 | + id: check_changie_entry |
| 34 | + run: | |
| 35 | + if [ -z "$(ls -A .changes/unreleased)" ]; then |
| 36 | + echo "No changie entry found." |
| 37 | + echo "::set-output name=changie_entry_exists::false" |
| 38 | + else |
| 39 | + echo "Changie entry found." |
| 40 | + echo "::set-output name=changie_entry_exists::true" |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Check for no-changie-required or dependencies label |
| 44 | + id: check_no_changie_label |
| 45 | + run: | |
| 46 | + labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 47 | + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels") |
| 48 | + if echo "$labels" | grep -q "no-changie-required"; then |
| 49 | + echo "no-changie-required label found, skipping changie validation." |
| 50 | + exit 0 |
| 51 | + fi |
| 52 | + if echo "$labels" | grep -q "dependencies"; then |
| 53 | + echo "dependencies label found, skipping changie validation." |
| 54 | + exit 0 |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Fail if no changie entry and no-changie-required or dependencies label not present |
| 58 | + if: steps.check_changie_entry.outputs.changie_entry_exists == 'false' |
| 59 | + run: | |
| 60 | + echo "::error::A changie entry was not found and is required on pull requests unless bypassed." |
| 61 | + exit 1 |
| 62 | +
|
| 63 | + - name: Post comment on pull request if validation fails |
| 64 | + if: failure() |
| 65 | + run: | |
| 66 | + comment="A changie entry was not found and is required on pull requests unless bypassed." |
| 67 | + comments_url=$(jq -r .pull_request.comments_url "$GITHUB_EVENT_PATH") |
| 68 | + existing_comments=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$comments_url") |
| 69 | + if echo "$existing_comments" | grep -q "$comment"; then |
| 70 | + echo "Comment already exists, not posting again." |
| 71 | + else |
| 72 | + curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 73 | + -d "{\"body\": \"$comment\"}" \ |
| 74 | + "$comments_url" |
| 75 | + fi |
0 commit comments