diff --git a/README.md b/README.md index 5a97616..3dc7f7e 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,9 @@ jobs: # If the coverage percentage is not green and above or equal to this value, the badge will be orange. Otherwise it will be red. badge-threshold-orange: 70 + + # Override the default branch name. + default-branch: next ``` ### Pinning diff --git a/action.yml b/action.yml index b620c73..cfdb2d2 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,9 @@ inputs: description: If the coverage percentage is not green and above or equal to this value, the badge will be orange. Otherwise it will be red. default: "70" required: false + default-branch: + description: Override the default branch name. + required: false runs: using: node16 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index 9dc5514..25a9e5a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13845,7 +13845,7 @@ function isBranch() { return process.env.GITHUB_REF.startsWith("refs/heads/"); } -async function isMainBranch(octokit, owner, repo) { +async function isDefaultBranch(octokit, owner, repo) { let response = await octokit.rest.repos.get({ owner, repo, @@ -13853,7 +13853,7 @@ async function isMainBranch(octokit, owner, repo) { return response.data.default_branch === process.env.GITHUB_REF_NAME; } -module.exports = { isBranch, isMainBranch }; +module.exports = { isBranch, isDefaultBranch }; /***/ }), @@ -14278,7 +14278,7 @@ const core = __nccwpck_require__(2186); const github = __nccwpck_require__(5438); const { gitClone, gitUpdate } = __nccwpck_require__(109); -const { isBranch, isMainBranch } = __nccwpck_require__(6381); +const { isBranch, isDefaultBranch } = __nccwpck_require__(6381); const { getShieldURL, getJSONBadge } = __nccwpck_require__(3673); const { average } = __nccwpck_require__(8978); const { computeDiff } = __nccwpck_require__(1752); @@ -14296,6 +14296,7 @@ async function run() { const baseSummaryFilename = core.getInput("base-summary-filename"); const coverageFilename = core.getInput("coverage-filename"); const badgeThresholdOrange = core.getInput("badge-threshold-orange"); + const defaultBranch = core.getInput("default-branch"); core.info(`Cloning wiki repository...`); @@ -14315,7 +14316,8 @@ async function run() { if ( isBranch() && - (await isMainBranch(octokit, context.repo.owner, context.repo.repo)) + (defaultBranch === process.env.GITHUB_REF_NAME || + (await isDefaultBranch(octokit, context.repo.owner, context.repo.repo))) ) { core.info("Running on default branch"); const BadgeEnabled = core.getBooleanInput("badge-enabled"); diff --git a/src/branch.js b/src/branch.js index 9d44307..5ac79e1 100644 --- a/src/branch.js +++ b/src/branch.js @@ -2,7 +2,7 @@ function isBranch() { return process.env.GITHUB_REF.startsWith("refs/heads/"); } -async function isMainBranch(octokit, owner, repo) { +async function isDefaultBranch(octokit, owner, repo) { let response = await octokit.rest.repos.get({ owner, repo, @@ -10,4 +10,4 @@ async function isMainBranch(octokit, owner, repo) { return response.data.default_branch === process.env.GITHUB_REF_NAME; } -module.exports = { isBranch, isMainBranch }; +module.exports = { isBranch, isDefaultBranch }; diff --git a/src/index.js b/src/index.js index 52d5c2d..db699ef 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ const core = require("@actions/core"); const github = require("@actions/github"); const { gitClone, gitUpdate } = require("./git"); -const { isBranch, isMainBranch } = require("./branch"); +const { isBranch, isDefaultBranch } = require("./branch"); const { getShieldURL, getJSONBadge } = require("./badge"); const { average } = require("./math"); const { computeDiff } = require("./diff"); @@ -29,6 +29,7 @@ async function run() { const baseSummaryFilename = core.getInput("base-summary-filename"); const coverageFilename = core.getInput("coverage-filename"); const badgeThresholdOrange = core.getInput("badge-threshold-orange"); + const defaultBranch = core.getInput("default-branch"); core.info(`Cloning wiki repository...`); @@ -48,7 +49,8 @@ async function run() { if ( isBranch() && - (await isMainBranch(octokit, context.repo.owner, context.repo.repo)) + (defaultBranch === process.env.GITHUB_REF_NAME || + (await isDefaultBranch(octokit, context.repo.owner, context.repo.repo))) ) { core.info("Running on default branch"); const BadgeEnabled = core.getBooleanInput("badge-enabled");