-
Notifications
You must be signed in to change notification settings - Fork 103
88 lines (74 loc) · 2.49 KB
/
build-without-lockfile.yml
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
name: Build without committed Cargo.lock
on:
push:
branches:
- main
- release-*
tags:
# YYYYMMDD
- "20[0-9][0-9][0-1][0-9][0-3][0-9]*"
schedule:
- cron: "0 0 * * 1"
pull_request:
# Only run on PRs if dependencies were modified.
paths:
- "**/Cargo.toml"
- "**/Cargo.lock"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-ignore-lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
with:
prefix-key: v1-rust
- name: Build without committed Cargo.lock
run: |
cargo generate-lockfile
cargo check --all-targets
- name: Comment on PR
uses: actions/github-script@v7
if: failure() && github.event_name == 'pull_request'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const runUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const commentTitle = "Unable to build without Cargo.lock file"
const commentBody = `${commentTitle}.
This means that after this change 3rd party projects may have
difficulties using crates in this repo as a dependency. If this
isn't easy to fix please open an issue so we can fix it later.
For the first failing build see: ${runUrl}
To reproduce locally run
\`\`\`
cargo generate-lockfile
cargo check --all-targets
\`\`\`
This PR can still be merged.`;
// Fetch existing comments
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Find existing comment
const existingComment = comments.find(c => c.body.startsWith(commentTitle));
if (!existingComment) {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: commentBody
});
} else {
console.log("Already commented.")
}