|
11 | 11 | schedule:
|
12 | 12 | - cron: "0 0 * * 1"
|
13 | 13 | pull_request:
|
| 14 | + # Only run on PRs if dependencies were modified. |
| 15 | + paths: |
| 16 | + - "**/Cargo.toml" |
| 17 | + - "**/Cargo.lock" |
14 | 18 | workflow_dispatch:
|
15 | 19 |
|
16 | 20 | concurrency:
|
|
33 | 37 | run: |
|
34 | 38 | cargo generate-lockfile
|
35 | 39 | cargo check --all-targets
|
| 40 | +
|
| 41 | + - name: Comment on PR |
| 42 | + uses: actions/github-script@v7 |
| 43 | + if: failure() && github.event_name == 'pull_request' |
| 44 | + with: |
| 45 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 46 | + script: | |
| 47 | + const issue_number = context.issue.number; |
| 48 | + const owner = context.repo.owner; |
| 49 | + const repo = context.repo.repo; |
| 50 | + const runUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; |
| 51 | +
|
| 52 | + const commentTitle = "Unable to build without Cargo.lock file" |
| 53 | + const commentBody = `${commentTitle}. |
| 54 | +
|
| 55 | + This means that after this change 3rd party projects may have |
| 56 | + difficulties using crates in this repo as a dependency. If this |
| 57 | + isn't easy to fix please open an issue so we can fix it later. |
| 58 | +
|
| 59 | + For the first failing build see: ${runUrl} |
| 60 | +
|
| 61 | + To reproduce locally run |
| 62 | +
|
| 63 | + \`\`\` |
| 64 | + cargo generate-lockfile |
| 65 | + cargo check --all-targets |
| 66 | + \`\`\` |
| 67 | +
|
| 68 | + This PR can still be merged.`; |
| 69 | +
|
| 70 | + // Fetch existing comments |
| 71 | + const { data: comments } = await github.rest.issues.listComments({ |
| 72 | + owner, |
| 73 | + repo, |
| 74 | + issue_number, |
| 75 | + }); |
| 76 | +
|
| 77 | + // Find existing comment |
| 78 | + const existingComment = comments.find(c => c.body.startsWith(commentTitle)); |
| 79 | + if (!existingComment) { |
| 80 | + await github.rest.issues.createComment({ |
| 81 | + owner, |
| 82 | + repo, |
| 83 | + issue_number, |
| 84 | + body: commentBody |
| 85 | + }); |
| 86 | + } else { |
| 87 | + console.log("Already commented.") |
| 88 | + } |
0 commit comments