Repository navigation
101 lines (82 loc) · 4.26 KB
/
Copy pathRustVersionCheck.yml
File metadata and controls
101 lines (82 loc) · 4.26 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
# A workflow that checks for changes to the channel field in rust-toolchain.toml on pull requests.
#
##
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0
##
name: Rust Version Change Detection
on:
workflow_call:
jobs:
check-rust-version:
runs-on: ubuntu-latest
if: github.repository_owner == 'OpenDevicePartnership'
steps:
- name: Generate Token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.PATINA_AUTOMATION_APPLICATION_ID }}
private-key: ${{ secrets.PATINA_AUTOMATION_APPLICATION_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: ✅ Checkout PR ✅
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: ✅ Fetch the base branch ✅
run: git fetch origin ${{ github.event.pull_request.base.ref }}
- name: 🔍 Check for rust-version changes 🔍
id: check-changes
run: |
DIFF=$(git diff origin/${{ github.event.pull_request.base.ref }}..HEAD -- rust-toolchain.toml)
if echo "$DIFF" | grep -E "^[-+].*channel\s*="; then
echo "rust_version_changed=true" >> $GITHUB_OUTPUT
OLD_VERSION=$(echo "$DIFF" | grep -E "^-.*channel\s*=" | sed -E 's/^-.*channel\s*=\s*["]?([^"\s]+)["]?.*/\1/' || echo "unknown")
NEW_VERSION=$(echo "$DIFF" | grep -E "^\+.*channel\s*=" | sed -E 's/^\+.*channel\s*=\s*["]?([^"\s]+)["]?.*/\1/' || echo "unknown")
echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
else
echo "rust_version_changed=false" >> $GITHUB_OUTPUT
fi
- name: ✍️ Comment on PR ✍️
if: steps.check-changes.outputs.rust_version_changed == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const oldVersion = '${{ steps.check-changes.outputs.old_version }}';
const newVersion = '${{ steps.check-changes.outputs.new_version }}';
// Check if we've already commented on this PR
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const workflowCommentExists = comments.data.some(comment =>
comment.body.includes('*This comment was automatically generated by the rust-version-check workflow.*')
);
if (workflowCommentExists) {
console.log('Rust version change comment already exists on this PR. Skipping comment creation.');
return;
}
const comment = `## Rust Version is Being Changed!
This pull request modifies the \`channel\` field in \`rust-toolchain.toml\`:
**Previous version:** \`${oldVersion}\`
**New version:** \`${newVersion}\`
### ⚠️ Reviewer Action Required
Please verify that:
- [ ] All team members have sufficient review time for the change
- [ ] CI/CD pipelines support the new Rust version
- [ ] Documentation is updated if needed
- [ ] The \`rust-version\` field in Cargo.toml is updated if the minimum supported Rust version must change.
- See the "Updating the Minimum Supported Rust Version" section in the readme for more details.
- [ ] The PR meets the requirements in the [Rust Version Update Policy](https://github.com/OpenDevicePartnership/patina/blob/main/README.md)
---
*This comment was automatically generated by the rust-version-check workflow.*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});