From ee3524b79738b6fe8459a8195bd1ec5a279d11fd Mon Sep 17 00:00:00 2001 From: Scott Guymer Date: Sun, 5 May 2024 18:22:44 +0200 Subject: [PATCH] feat: Enable renovate changeset action to work with dependabot --- renovate-changesets/action.yaml | 8 ++++++-- renovate-changesets/dependencyConfig.ts | 17 +++++++++++++++++ renovate-changesets/index.ts | 16 ++++++++++++---- ...enovateChangesets.ts => manageChangesets.ts} | 8 +++++++- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 renovate-changesets/dependencyConfig.ts rename renovate-changesets/{renovateChangesets.ts => manageChangesets.ts} (93%) diff --git a/renovate-changesets/action.yaml b/renovate-changesets/action.yaml index 6e01851..d9c7561 100644 --- a/renovate-changesets/action.yaml +++ b/renovate-changesets/action.yaml @@ -1,10 +1,14 @@ -name: Backstage Renovate Changeset Creator -description: Create changesets on the renovate bot PR's if needed +name: Backstage Dependency Manager Changeset Creator +description: Create changesets on the dependency manager bot PR's if needed inputs: multiple-workspaces: description: If it's this repository is a collection of workspaces required: false default: 'false' + dependency-manager: + description: The dependency manager to use + required: false + default: 'renovate' outputs: {} runs: diff --git a/renovate-changesets/dependencyConfig.ts b/renovate-changesets/dependencyConfig.ts new file mode 100644 index 0000000..82dab84 --- /dev/null +++ b/renovate-changesets/dependencyConfig.ts @@ -0,0 +1,17 @@ +import * as core from '@actions/core'; + +export type DependencyMangerConfig = { + branchPrefix: string; + changesetPrefix: string; +}; + +export const dependencyMangerConfig: Record = { + renovate: { branchPrefix: 'renovate/', changesetPrefix: 'renovate' }, + dependabot: { branchPrefix: 'dependabot/', changesetPrefix: 'dependabot' }, +}; + +export const getDependencyManager = () => { + return core.getInput('dependency-manager', { + required: false, + }); +}; diff --git a/renovate-changesets/index.ts b/renovate-changesets/index.ts index c89fbc5..54dabf1 100644 --- a/renovate-changesets/index.ts +++ b/renovate-changesets/index.ts @@ -7,11 +7,15 @@ import { getChangedFiles, getChangesetFilename, listPackages, -} from './renovateChangesets'; +} from './manageChangesets'; import { relative as relativePath, resolve as resolvePath } from 'path'; +import { + dependencyMangerConfig, + getDependencyManager, +} from './dependencyConfig'; async function main() { - core.info('Running Renovate Changesets'); + core.info(`Running ${getDependencyManager()} Changesets`); const isMultipleWorkspaces = core.getBooleanInput('multiple-workspaces', { required: false, @@ -19,8 +23,12 @@ async function main() { const branchName = await getBranchName(); - if (!branchName.startsWith('renovate/')) { - core.info('Not a renovate branch, skipping'); + if ( + !branchName.startsWith( + dependencyMangerConfig[getDependencyManager()].branchPrefix, + ) + ) { + core.info(`Not a ${getDependencyManager()} branch, skipping`); return; } diff --git a/renovate-changesets/renovateChangesets.ts b/renovate-changesets/manageChangesets.ts similarity index 93% rename from renovate-changesets/renovateChangesets.ts rename to renovate-changesets/manageChangesets.ts index d37c280..fac81f4 100644 --- a/renovate-changesets/renovateChangesets.ts +++ b/renovate-changesets/manageChangesets.ts @@ -2,6 +2,10 @@ import { getExecOutput, exec } from '@actions/exec'; import fs from 'fs/promises'; import { resolve as resolvePath, relative as relativePath } from 'path'; import { getPackages, type Package } from '@manypkg/get-packages'; +import { + dependencyMangerConfig, + getDependencyManager, +} from './dependencyConfig'; export async function getBranchName() { const { stdout } = await getExecOutput('git', ['branch', '--show-current']); @@ -34,7 +38,9 @@ export async function getChangesetFilename() { const { stdout: shortHash } = await getExecOutput( 'git rev-parse --short HEAD', ); - return `.changeset/renovate-${shortHash.trim()}.md`; + return `.changeset/${ + dependencyMangerConfig[getDependencyManager()].changesetPrefix + }-${shortHash.trim()}.md`; } export async function createChangeset(