Skip to content

Commit

Permalink
feat: Enable renovate changeset action to work with dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottGuymer committed May 5, 2024
1 parent 772cef0 commit ee3524b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
8 changes: 6 additions & 2 deletions renovate-changesets/action.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 17 additions & 0 deletions renovate-changesets/dependencyConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as core from '@actions/core';

export type DependencyMangerConfig = {
branchPrefix: string;
changesetPrefix: string;
};

export const dependencyMangerConfig: Record<string, DependencyMangerConfig> = {
renovate: { branchPrefix: 'renovate/', changesetPrefix: 'renovate' },
dependabot: { branchPrefix: 'dependabot/', changesetPrefix: 'dependabot' },
};

export const getDependencyManager = () => {
return core.getInput('dependency-manager', {
required: false,
});
};
16 changes: 12 additions & 4 deletions renovate-changesets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ 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,
});

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ee3524b

Please sign in to comment.