Skip to content

Commit 3fba86a

Browse files
authored
Fix part of #353: Migrate GitHub Actions to Node.js 20 (#354)
* Phase 1: Migrate GitHub Actions to Node.js 20 * Removed the test ci check and updated the test coverage
1 parent 1828c99 commit 3fba86a

File tree

12 files changed

+277745
-270656
lines changed

12 files changed

+277745
-270656
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ inputs:
1717
required: true
1818

1919
runs:
20-
using: "node12"
20+
using: "node20"
2121
main: "actions_build/index.js"

actions/src/issues/checkIssueLabels.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
*/
1818

1919
const core = require('@actions/core');
20-
const { context, GitHub } = require('@actions/github');
20+
const github = require('@actions/github');
2121
const whitelist = require('../../../userWhitelist.json');
2222
const GOOD_FIRST_LABEL = 'good first issue';
2323
const prLabels = ['dependencies', 'stale'];
2424

2525
const checkLabels = async () => {
2626
core.info('Checking newly added label...');
2727
const token = core.getInput('repo-token');
28-
const label = context.payload.label;
29-
const octokit = new GitHub(token);
30-
const user = context.payload.sender.login;
28+
const label = github.context.payload.label;
29+
const octokit = github.getOctokit(token);
30+
const user = github.context.payload.sender.login;
3131

3232
if (
3333
label.name === GOOD_FIRST_LABEL &&
@@ -48,28 +48,28 @@ const checkLabels = async () => {
4848
* @param {String} user - Username of the user that added the label.
4949
*/
5050
const handleGoodFirstIssueLabel = async (octokit, user) => {
51-
const issueNumber = context.payload.issue.number;
51+
const issueNumber = github.context.payload.issue.number;
5252
// Comment on the issue and ping the onboarding team lead.
5353
var commentBody = (
5454
'Hi @' + user + ', only certain users are allowed to add good ' +
55-
'first issue labels. Looping in @oppia/oppia-good-first-issue-labelers ' +
55+
'first issue labels. Looping in @oppia/oppia-good-first-issue-labelers ' +
5656
'to add the label. Thanks!'
5757
);
5858
await octokit.issues.createComment(
5959
{
6060
body: commentBody,
6161
issue_number: issueNumber,
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
62+
owner: github.context.repo.owner,
63+
repo: github.context.repo.repo,
6464
}
6565
);
6666
// Remove the label.
6767
core.info('Removing the label.');
6868
await octokit.issues.removeLabel({
6969
issue_number: issueNumber,
7070
name: GOOD_FIRST_LABEL,
71-
owner: context.repo.owner,
72-
repo: context.repo.repo
71+
owner: github.context.repo.owner,
72+
repo: github.context.repo.repo
7373
});
7474
};
7575

@@ -81,7 +81,7 @@ const handleGoodFirstIssueLabel = async (octokit, user) => {
8181
* @param {String} user - Username of the user that added the label.
8282
*/
8383
const handlePRLabel = async (octokit, label, user) => {
84-
const issueNumber = context.payload.issue.number;
84+
const issueNumber = github.context.payload.issue.number;
8585
const linkText = 'here';
8686
// Add link to wiki.
8787
const link = linkText.link(
@@ -96,8 +96,8 @@ const handlePRLabel = async (octokit, label, user) => {
9696
{
9797
body: commentBody,
9898
issue_number: issueNumber,
99-
owner: context.repo.owner,
100-
repo: context.repo.repo,
99+
owner: github.context.repo.owner,
100+
repo: github.context.repo.repo,
101101
}
102102
);
103103

@@ -106,8 +106,8 @@ const handlePRLabel = async (octokit, label, user) => {
106106
await octokit.issues.removeLabel({
107107
issue_number: issueNumber,
108108
name: label,
109-
owner: context.repo.owner,
110-
repo: context.repo.repo
109+
owner: github.context.repo.owner,
110+
repo: github.context.repo.repo
111111
});
112112
};
113113

actions/src/pull_requests/checkWipDraftPR.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
const core = require('@actions/core');
21-
const { context, GitHub } = require('@actions/github');
21+
const github = require('@actions/github');
2222
const { commentAndAssignUsers } = require('../utils');
2323

2424
/**
@@ -44,11 +44,11 @@ const isWIPPr = ({ title, body }) => {
4444
* @returns {Promise<Boolean>}
4545
*/
4646
const isSkipCICommit = async (octokit) => {
47-
const pullRequest = context.payload.pull_request;
47+
const pullRequest = github.context.payload.pull_request;
4848

4949
const commitParams = {
5050
commit_sha: pullRequest.head.sha,
51-
...context.repo
51+
...github.context.repo
5252
};
5353
const commitResponse = await octokit.git.getCommit(commitParams);
5454

@@ -60,8 +60,8 @@ const isSkipCICommit = async (octokit) => {
6060

6161
module.exports.checkWIP = async () => {
6262
const token = core.getInput('repo-token');
63-
const octokit = new GitHub(token);
64-
const pullRequest = context.payload.pull_request;
63+
const octokit = github.getOctokit(token);
64+
const pullRequest = github.context.payload.pull_request;
6565
const prAuthor = pullRequest.user.login;
6666

6767
if (isDraftPr(pullRequest) || isWIPPr(pullRequest)) {

actions/src/pull_requests/claCheck.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
const core = require('@actions/core');
20-
const { context, GitHub } = require('@actions/github');
20+
const github = require('@actions/github');
2121
const { google } = require('googleapis');
2222

2323
/**
@@ -44,10 +44,10 @@ const authorize = async function() {
4444

4545
const generateOutput = async (hasClaSigned) => {
4646
const GITHUB_TOKEN = core.getInput('repo-token');
47-
const octokit = new GitHub(GITHUB_TOKEN);
48-
const PR_NUMBER = context.payload.pull_request.number;
49-
const PR_AUTHOR = context.payload.pull_request.user.login;
50-
const REPO_NAME = context.payload.repository.name;
47+
const octokit = github.getOctokit(GITHUB_TOKEN);
48+
const PR_NUMBER = github.context.payload.pull_request.number;
49+
const PR_AUTHOR = github.context.payload.pull_request.user.login;
50+
const REPO_NAME = github.context.payload.repository.name;
5151

5252
let LINK_RESULT = '';
5353

@@ -76,15 +76,15 @@ const generateOutput = async (hasClaSigned) => {
7676
await octokit.issues.update({
7777
issue_number: PR_NUMBER,
7878
state: 'closed',
79-
owner: context.repo.owner,
80-
repo: context.repo.repo,
79+
owner: github.context.repo.owner,
80+
repo: github.context.repo.repo,
8181
});
8282
await octokit.issues.createComment(
8383
{
8484
body: comment,
8585
issue_number: PR_NUMBER,
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
86+
owner: github.context.repo.owner,
87+
repo: github.context.repo.repo,
8888
}
8989
);
9090
core.setFailed(PR_AUTHOR + ' has not signed the CLA');
@@ -99,7 +99,7 @@ const generateOutput = async (hasClaSigned) => {
9999
* @param {google.auth.OAuth2} auth The authenticated Google OAuth client.
100100
*/
101101
const checkSheet = async (auth) => {
102-
const PR_AUTHOR = context.payload.pull_request.user.login;
102+
const PR_AUTHOR = github.context.payload.pull_request.user.login;
103103
const sheets = google.sheets({ version: 'v4', auth });
104104
const SPREADSHEET_ID = core.getInput('cla-sheet-id');
105105
await sheets.spreadsheets.values.get(

0 commit comments

Comments
 (0)