Skip to content

Commit 3e738bb

Browse files
authored
Merge pull request wso2#9466 from ThaminduR/add-workflow
Add GitHub Action to check for pnpm-lock.yaml changes in pull requests
2 parents e387fd0 + a042f9d commit 3e738bb

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# -------------------------------------------------------------------------------------
2+
#
3+
# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
4+
#
5+
# WSO2 LLC. licenses this file to you under the Apache License,
6+
# Version 2.0 (the "License"); you may not use this file except
7+
# in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
# --------------------------------------------------------------------------------------
20+
21+
# This workflow will check if a submitted PR has changes to pnpm-lock.yaml
22+
23+
name: 🔒 Check Lockfile Changes
24+
25+
on:
26+
workflow_run:
27+
workflows: ["📩 Receive PR"]
28+
types:
29+
- completed
30+
31+
env:
32+
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
33+
34+
jobs:
35+
check-lockfile:
36+
runs-on: ubuntu-latest
37+
if: >
38+
github.event.workflow_run.event == 'pull_request' &&
39+
github.event.workflow_run.conclusion == 'success'
40+
steps:
41+
- name: 📥 Download PR Number Artifact
42+
uses: actions/download-artifact@v4
43+
with:
44+
name: pr-number
45+
github-token: ${{ env.GH_TOKEN }}
46+
repository: ${{ github.repository }}
47+
run-id: ${{ github.event.workflow_run.id }}
48+
49+
- name: 📝 Display PR Number
50+
run: cat ./PR_NUMBER
51+
52+
- name: 💬 Remove Existing Lockfile Comment
53+
uses: actions/[email protected]
54+
with:
55+
github-token: ${{ env.GH_TOKEN }}
56+
script: |
57+
const fs = require('fs');
58+
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
59+
const REPO_OWNER = context.repo.owner;
60+
const REPO_NAME = context.repo.repo;
61+
62+
const comments = await github.issues.listComments({
63+
owner: REPO_OWNER,
64+
repo: REPO_NAME,
65+
issue_number: PR_NUMBER,
66+
});
67+
68+
for (const comment of comments.data) {
69+
if (comment.body.includes("⚠️ Lockfile Change Detected")) {
70+
await github.issues.deleteComment({
71+
owner: REPO_OWNER,
72+
repo: REPO_NAME,
73+
comment_id: comment.id,
74+
});
75+
}
76+
}
77+
78+
- name: 💬 Add Lockfile Comment
79+
uses: actions/[email protected]
80+
with:
81+
github-token: ${{ env.GH_TOKEN }}
82+
script: |
83+
const fs = require('fs');
84+
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
85+
const REPO_OWNER = context.repo.owner;
86+
const REPO_NAME = context.repo.repo;
87+
88+
const files = await github.pulls.listFiles({
89+
owner: REPO_OWNER,
90+
repo: REPO_NAME,
91+
pull_number: PR_NUMBER,
92+
});
93+
94+
const CHANGED_FILES = files.data.map(file => file.filename);
95+
const LOCKFILE_CHANGED = CHANGED_FILES.includes('pnpm-lock.yaml');
96+
97+
console.log("LOCKFILE_CHANGED:", LOCKFILE_CHANGED);
98+
99+
if (LOCKFILE_CHANGED) {
100+
const COMMENT = `<h3>⚠️ Lockfile Change Detected</h3><p>This pull request modifies <code>pnpm-lock.yaml</code>.</p><p>If this change is intentional (e.g., dependency updates), please ensure:</p><ul><li>All changes are reviewed carefully</li><li>If this change is unintentional, consider reverting it</li></ul><p><i>This is an automated warning to help maintain dependency stability.</i></p>`;
101+
102+
await github.issues.createComment({
103+
owner: REPO_OWNER,
104+
repo: REPO_NAME,
105+
issue_number: PR_NUMBER,
106+
body: COMMENT,
107+
});
108+
109+
core.setFailed('pnpm-lock.yaml has been modified in this PR. Please review the changes carefully.');
110+
}

0 commit comments

Comments
 (0)