Skip to content

Commit d8e5c47

Browse files
committed
Update actions/github-script to v7
1 parent aee3f0b commit d8e5c47

File tree

1 file changed

+98
-98
lines changed

1 file changed

+98
-98
lines changed

.github/workflows/check-changeset.yml

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -51,117 +51,117 @@ jobs:
5151
run: cat ./PR_NUMBER
5252

5353
- name: 💬 Remove Existing Changeset Comment
54-
uses: actions/github-script@v3.1.0
54+
uses: actions/github-script@v7
5555
with:
5656
github-token: ${{ env.GH_TOKEN }}
5757
script: |
58-
const fs = require('fs');
59-
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
60-
const REPO_OWNER = context.repo.owner;
61-
const REPO_NAME = context.repo.repo;
62-
63-
// Fetch all comments on the pull request.
64-
const comments = await github.issues.listComments({
58+
const fs = require('fs');
59+
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
60+
const REPO_OWNER = context.repo.owner;
61+
const REPO_NAME = context.repo.repo;
62+
63+
const comments = await github.rest.issues.listComments({
64+
owner: REPO_OWNER,
65+
repo: REPO_NAME,
66+
issue_number: PR_NUMBER,
67+
});
68+
69+
console.log("COMMENTS_URL: https://api.github.com/repos/" + REPO_NAME + "/issues/" + PR_NUMBER + "/comments");
70+
71+
for (const comment of comments.data) {
72+
console.log("COMMENT_OWNER: " + comment.user.login);
73+
74+
if (
75+
comment.body.includes("🦋 Changeset detected") ||
76+
comment.body.includes("⚠️ No Changeset found") ||
77+
comment.body.includes("❌ Invalid Changeset detected")
78+
) {
79+
console.log("COMMENT_ID_TO_DELETE: " + comment.id);
80+
81+
await github.rest.issues.deleteComment({
6582
owner: REPO_OWNER,
6683
repo: REPO_NAME,
67-
issue_number: PR_NUMBER,
68-
});
69-
70-
console.log("COMMENTS_URL: https://api.github.com/repos/" + REPO_NAME + "/issues/" + PR_NUMBER + "/comments");
71-
72-
for (const comment of comments.data) {
73-
console.log("COMMENT_OWNER: " + comment.user.login);
74-
75-
// Identify the changeset comment by its heading.
76-
if (comment.body.includes("🦋 Changeset detected") || comment.body.includes("⚠️ No Changeset found") || comment.body.includes("❌ Invalid Changeset detected")) {
77-
console.log("COMMENT_ID_TO_DELETE: " + comment.id);
78-
79-
// Remove the changeset comment using the comment ID.
80-
await github.issues.deleteComment({
81-
owner: REPO_OWNER,
82-
repo: REPO_NAME,
83-
comment_id: comment.id,
84-
});
85-
}
84+
comment_id: comment.id,
85+
});
8686
}
87+
}
8788
8889
- name: 💬 Add Changeset Comment
89-
uses: actions/github-script@v3.1.0
90+
uses: actions/github-script@v7
9091
with:
9192
github-token: ${{ env.GH_TOKEN }}
9293
script: |
93-
const fs = require('fs');
94-
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
95-
const REPO_OWNER = context.repo.owner;
96-
const REPO_NAME = context.repo.repo;
97-
const IS_RELEASE_MODE = process.env.IS_RELEASE_MODE === 'true';
98-
99-
const files = await github.pulls.listFiles({
100-
owner: REPO_OWNER,
101-
repo: REPO_NAME,
102-
pull_number: PR_NUMBER,
103-
});
104-
105-
const CHANGED_FILES = files.data.map(file => file.filename);
106-
console.log("CHANGED_FILES_URL: https://api.github.com/repos/" + REPO_NAME + "/pulls/" + PR_NUMBER + "/files");
107-
console.log("CHANGED_FILES:", CHANGED_FILES);
108-
109-
const CHANGESET_FILES = CHANGED_FILES.filter(filename => /^\.changeset\/.*\.md$/.test(filename));
110-
const CHANGES_COUNT = CHANGESET_FILES.length;
111-
console.log("CHANGES_COUNT:", CHANGES_COUNT);
112-
console.log("IS_RELEASE_MODE:", IS_RELEASE_MODE);
113-
114-
let invalidChangesets = [];
115-
116-
// Check for major/minor changesets in release mode (master branch)
117-
if (IS_RELEASE_MODE && CHANGES_COUNT > 0) {
118-
for (const changesetFile of CHANGESET_FILES) {
119-
try {
120-
const fileResponse = await github.repos.getContent({
121-
owner: REPO_OWNER,
122-
repo: REPO_NAME,
123-
path: changesetFile,
124-
ref: `refs/pull/${PR_NUMBER}/head`
125-
});
126-
127-
const content = Buffer.from(fileResponse.data.content, 'base64').toString('utf8');
128-
console.log("CHANGESET_CONTENT:", changesetFile, content);
129-
130-
// Parse changeset frontmatter to check for major/minor releases
131-
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
132-
if (frontmatterMatch) {
133-
const frontmatter = frontmatterMatch[1];
134-
if (frontmatter.includes(': major') || frontmatter.includes(': minor')) {
135-
invalidChangesets.push({
136-
file: changesetFile,
137-
type: frontmatter.includes(': major') ? 'major' : 'minor'
138-
});
139-
}
140-
}
141-
} catch (error) {
142-
console.log("Error reading changeset file:", changesetFile, error.message);
143-
}
94+
const fs = require('fs');
95+
const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim());
96+
const REPO_OWNER = context.repo.owner;
97+
const REPO_NAME = context.repo.repo;
98+
const IS_RELEASE_MODE = process.env.IS_RELEASE_MODE === 'true';
99+
100+
const files = await github.rest.pulls.listFiles({
101+
owner: REPO_OWNER,
102+
repo: REPO_NAME,
103+
pull_number: PR_NUMBER,
104+
});
105+
106+
const CHANGED_FILES = files.data.map(file => file.filename);
107+
console.log("CHANGED_FILES_URL: https://api.github.com/repos/" + REPO_NAME + "/pulls/" + PR_NUMBER + "/files");
108+
console.log("CHANGED_FILES:", CHANGED_FILES);
109+
110+
const CHANGESET_FILES = CHANGED_FILES.filter(filename => /^\.changeset\/.*\.md$/.test(filename));
111+
const CHANGES_COUNT = CHANGESET_FILES.length;
112+
console.log("CHANGES_COUNT:", CHANGES_COUNT);
113+
console.log("IS_RELEASE_MODE:", IS_RELEASE_MODE);
114+
115+
let invalidChangesets = [];
116+
117+
if (IS_RELEASE_MODE && CHANGES_COUNT > 0) {
118+
for (const changesetFile of CHANGESET_FILES) {
119+
try {
120+
const fileResponse = await github.rest.repos.getContent({
121+
owner: REPO_OWNER,
122+
repo: REPO_NAME,
123+
path: changesetFile,
124+
ref: `refs/pull/${PR_NUMBER}/head`
125+
});
126+
127+
const content = Buffer.from(fileResponse.data.content, 'base64').toString('utf8');
128+
console.log("CHANGESET_CONTENT:", changesetFile, content);
129+
130+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
131+
if (frontmatterMatch) {
132+
const frontmatter = frontmatterMatch[1];
133+
if (frontmatter.includes(': major') || frontmatter.includes(': minor')) {
134+
invalidChangesets.push({
135+
file: changesetFile,
136+
type: frontmatter.includes(': major') ? 'major' : 'minor'
137+
});
138+
}
144139
}
140+
} catch (error) {
141+
console.log("Error reading changeset file:", changesetFile, error.message);
142+
}
145143
}
146-
147-
let COMMENT;
148-
if (CHANGES_COUNT > 0) {
149-
if (IS_RELEASE_MODE && invalidChangesets.length > 0) {
150-
console.log("Invalid changesets detected in release mode:", invalidChangesets);
151-
const invalidFiles = invalidChangesets.map(cs => `- \`${cs.file}\` (${cs.type})`).join('\n');
152-
COMMENT = `<h3>❌ Invalid Changeset detected</h3><p><b>🚀 WSO2 Identity Server release mode is currently activated!</b></p><p>The following changesets contain major/minor versions, but the master branch only allows patch releases:</p>\n${invalidFiles}\n<p><b>📋 Action Required:</b></p><ul><li>🔧 Update these changesets to use patch versions only, OR</li><li>🎯 Target the <code>next</code> branch for minor/major releases</li></ul><p>📚 Refer <a href="https://github.com/wso2/identity-apps/blob/master/docs/release/README.md">Release Documentation</a> to learn about our release strategy.</p>`;
153-
} else {
154-
console.log("Changeset detected");
155-
COMMENT = `<h3>🦋 Changeset detected</h3><p><b>The changes in this PR will be included in the next version bump.</b></p><p>Not sure what this means? <a href="https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md">Click here to learn what changesets are</a>.</p>`;
156-
}
144+
}
145+
146+
let COMMENT;
147+
if (CHANGES_COUNT > 0) {
148+
if (IS_RELEASE_MODE && invalidChangesets.length > 0) {
149+
console.log("Invalid changesets detected in release mode:", invalidChangesets);
150+
const invalidFiles = invalidChangesets.map(cs => `- \`${cs.file}\` (${cs.type})`).join('\n');
151+
COMMENT = `<h3>❌ Invalid Changeset detected</h3><p><b>🚀 WSO2 Identity Server release mode is currently activated!</b></p><p>The following changesets contain major/minor versions, but the master branch only allows patch releases:</p>\n${invalidFiles}\n<p><b>📋 Action Required:</b></p><ul><li>🔧 Update these changesets to use patch versions only, OR</li><li>🎯 Target the <code>next</code> branch for minor/major releases</li></ul><p>📚 Refer <a href="https://github.com/wso2/identity-apps/blob/master/docs/release/README.md">Release Documentation</a> to learn about our release strategy.</p>`;
157152
} else {
158-
console.log("No changeset detected");
159-
COMMENT = `<h3>⚠️ No Changeset found</h3>Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.</p><p><b>If these changes should result in a version bump, you need to add a changeset.</b></p><p>Refer <a href="https://github.com/wso2/identity-apps/blob/master/docs/release/README.md">Release Documentation</a> to learn how to add a changeset.`;
153+
console.log("Changeset detected");
154+
COMMENT = `<h3>🦋 Changeset detected</h3><p><b>The changes in this PR will be included in the next version bump.</b></p><p>Not sure what this means? <a href="https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md">Click here to learn what changesets are</a>.</p>`;
160155
}
156+
} else {
157+
console.log("No changeset detected");
158+
COMMENT = `<h3>⚠️ No Changeset found</h3>Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.</p><p><b>If these changes should result in a version bump, you need to add a changeset.</b></p><p>Refer <a href="https://github.com/wso2/identity-apps/blob/master/docs/release/README.md">Release Documentation</a> to learn how to add a changeset.`;
159+
}
160+
161+
await github.rest.issues.createComment({
162+
owner: REPO_OWNER,
163+
repo: REPO_NAME,
164+
issue_number: PR_NUMBER,
165+
body: COMMENT,
166+
});
161167
162-
await github.issues.createComment({
163-
owner: REPO_OWNER,
164-
repo: REPO_NAME,
165-
issue_number: PR_NUMBER,
166-
body: COMMENT,
167-
});

0 commit comments

Comments
 (0)