Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/npm-f4e71bc59b
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnAngela authored Dec 26, 2023
2 parents fe655d0 + 05bdbd7 commit 8715127
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/ganerateCommitsHistory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import path from "path";
exportVariable("linguist-generated-ganerateCommitsHistory", JSON.stringify(["src/global/zh/MediaWiki:GHIAHistory.json"]));

if (!isInMasterBranch) {
console.info("Not running in non-master branch, exit.");
console.info("Not running in master branch, exit.");
process.exit(0);
}
console.info("Initialization done.");
Expand Down
7 changes: 4 additions & 3 deletions scripts/modules/createCommit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import console from "../modules/console.js";
import git from "../modules/git.js";
import { exportVariable } from "@actions/core";
import { isInGithubActions, isPullRequest } from "../modules/octokit.js";
import { isInGithubActions } from "../modules/octokit.js";
import upstream from "../modules/getUpstream.js";

/**
* @param {string} message
Expand All @@ -12,8 +13,8 @@ export default async (message) => {
console.info("Not running in github actions, exit.");
return false;
}
if (isPullRequest) {
console.info("Running in github actions, but in pull request event, skip creating commits...");
if (!upstream) {
console.info("Running in github actions, but HEAD is not tracking any remote branch, exit.");
return false;
}
console.info("[createCommit] Running in github actions, try to create commit.");
Expand Down
18 changes: 18 additions & 0 deletions scripts/modules/getUpstream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import console from "./console.js";
import git from "./git.js";
import { isInGithubActions } from "./octokit.js";
if (!isInGithubActions) {
console.info("Not running in github actions, exit.");
process.exit(0);
}
/**
* @type { string | false } when false, it means the current branch is not tracking any remote branch.
*/
let result;
try {
result = await git.revparse(["--abbrev-ref", "--symbolic-full-name", "@{upstream}"]);
} catch (e) {
console.error(e);
result = false;
}
export default result;
7 changes: 6 additions & 1 deletion scripts/postCommit/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { startGroup, endGroup } from "@actions/core";
import git from "../modules/git.js";
import { isInGithubActions } from "../modules/octokit.js";
import readWorkflowEvent from "../modules/workflowEvent.js";
import upstream from "../modules/getUpstream.js";
if (!isInGithubActions) {
console.info("Not running in github actions, exit.");
process.exit(0);
}
if (!upstream) {
console.info("Running in github actions, but HEAD is not tracking any remote branch, exit.");
process.exit(0);
}
const GITHUB_EVENT = await readWorkflowEvent();
const { before, after } = GITHUB_EVENT;
const isBeforeExists = before && after && (await git.branch(["--contains", before]).catch(() => ({ current: "" }))).current.length > 0;
Expand All @@ -22,7 +27,7 @@ startGroup("changedFiles:");
console.info(changedFiles);
endGroup();
console.info("Running in github actions, start to check unpushed commits...");
const unpushedCommits = (await git.raw(["cherry", "-v"])).trim();
const unpushedCommits = (await git.raw(["cherry", "-v", upstream])).trim();
if (unpushedCommits.length === 0) {
console.info("No unpushed commit.");
process.exit(0);
Expand Down

0 comments on commit 8715127

Please sign in to comment.