Skip to content

Commit

Permalink
feat: add additional target options for dev and production dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
groozin committed Feb 8, 2024
1 parent 18a935d commit f02dd50
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ inputs:
required: false
default: false
target:
description: 'Auto-merge on major, minor, patch updates based on Semantic Versioning'
description: 'Auto-merge on major, minor, patch updates based on Semantic Versioning for both dev and production dependencies'
required: false
default: 'any'
development-target:
description: 'Auto-merge on major, minor, patch updates based on Semantic Versioning when dependency is a dev dependency'
required: false
default: 'any'
production-target:
description: 'Auto-merge on major, minor, patch updates based on Semantic Versioning when dependency is a production dependency'
required: false
default: 'any'
pr-number:
Expand Down
18 changes: 14 additions & 4 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ module.exports = async function run({
APPROVE_ONLY,
USE_GITHUB_AUTO_MERGE,
TARGET,
DEV_TARGET,
PROD_TARGET,
PR_NUMBER,
SKIP_COMMIT_VERIFICATION,
SKIP_VERIFICATION,
} = getInputs(inputs)

let target = TARGET
if (dependabotMetadata.dependencyType === 'direct:development') {
target = DEV_TARGET
} else if (dependabotMetadata.dependencyType === 'direct:production') {
target = PROD_TARGET
}

try {
toolkit.logActionRefWarning()

Expand Down Expand Up @@ -85,7 +94,7 @@ module.exports = async function run({
}

if (
TARGET !== updateTypes.any &&
target !== updateTypes.any &&
updateTypesPriority.indexOf(updateType) < 0
) {
core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.skippedInvalidVersion)
Expand All @@ -94,13 +103,14 @@ module.exports = async function run({
}

if (
TARGET !== updateTypes.any &&
target !== updateTypes.any &&
updateTypesPriority.indexOf(updateType) >
updateTypesPriority.indexOf(TARGET)
updateTypesPriority.indexOf(target)
) {
core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.skippedBumpHigherThanTarget)
// TODO: Improve error message for higher than target - specify which target
logWarning(`Semver bump is higher than allowed in TARGET.
Tried to do a '${updateType}' update but the max allowed is '${TARGET}'`)
Tried to do a '${updateType}' update but the max allowed is '${target}'`)
return
}

Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ exports.getInputs = inputs => {
APPROVE_ONLY: /true/i.test(inputs['approve-only']),
USE_GITHUB_AUTO_MERGE: /true/i.test(inputs['use-github-auto-merge']),
TARGET: mapUpdateType(inputs['target']),
DEV_TARGET: mapUpdateType(inputs['development-target']),
PROD_TARGET: mapUpdateType(inputs['production-target']),
PR_NUMBER: inputs['pr-number'],
SKIP_COMMIT_VERIFICATION: /true/i.test(inputs['skip-commit-verification']),
SKIP_VERIFICATION: /true/i.test(inputs['skip-verification']),
Expand Down

0 comments on commit f02dd50

Please sign in to comment.