From a5796937aed946045e7a827fc28ff99d72de0778 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Wed, 4 Jun 2025 08:12:29 +0200 Subject: [PATCH] chore: migrate to new actions format Signed-off-by: benjdlambert --- .changeset/orange-masks-decide.md | 5 + .../report.api.md | 50 ++++- .../src/actions/fetch/rails/index.test.ts | 4 +- .../src/actions/fetch/rails/index.ts | 206 ++++++++---------- 4 files changed, 146 insertions(+), 119 deletions(-) create mode 100644 .changeset/orange-masks-decide.md diff --git a/.changeset/orange-masks-decide.md b/.changeset/orange-masks-decide.md new file mode 100644 index 0000000000..0ddb7a7e48 --- /dev/null +++ b/.changeset/orange-masks-decide.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-rails': patch +--- + +Migrate to new actions format diff --git a/plugins/scaffolder-backend-module-rails/report.api.md b/plugins/scaffolder-backend-module-rails/report.api.md index 0d7618852d..a8abcfee1e 100644 --- a/plugins/scaffolder-backend-module-rails/report.api.md +++ b/plugins/scaffolder-backend-module-rails/report.api.md @@ -4,7 +4,6 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; -import { JsonObject } from '@backstage/types'; import { ScmIntegrations } from '@backstage/integration'; import { TemplateAction } from '@backstage/plugin-scaffolder-node'; import { UrlReaderService } from '@backstage/backend-plugin-api'; @@ -45,12 +44,51 @@ export function createFetchRailsAction(options: { }): TemplateAction< { url: string; - targetPath?: string; - values: JsonObject; - imageName?: string; + values: { + railsArguments?: + | { + template?: string | undefined; + database?: + | 'sqlite3' + | 'mysql' + | 'postgresql' + | 'oracle' + | 'sqlserver' + | 'jdbcmysql' + | 'jdbcsqlite3' + | 'jdbcpostgresql' + | 'jdbc' + | undefined; + api?: boolean | undefined; + force?: boolean | undefined; + minimal?: boolean | undefined; + railsVersion?: 'edge' | 'master' | 'dev' | 'fromImage' | undefined; + skipActionCable?: boolean | undefined; + skipActionMailbox?: boolean | undefined; + skipActionMailer?: boolean | undefined; + skipActionText?: boolean | undefined; + skipActiveStorage?: boolean | undefined; + skipBundle?: boolean | undefined; + skipTest?: boolean | undefined; + skipWebpackInstall?: boolean | undefined; + skipActiveRecord?: boolean | undefined; + webpacker?: + | 'react' + | 'angular' + | 'vue' + | 'elm' + | 'stimulus' + | undefined; + } + | undefined; + }; + targetPath?: string | undefined; + imageName?: string | undefined; }, - JsonObject, - 'v1' + { + [x: string]: any; + }, + 'v2' >; // @public diff --git a/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.test.ts b/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.test.ts index fc9443efc0..aaff033c21 100644 --- a/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.test.ts +++ b/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.test.ts @@ -56,7 +56,9 @@ describe('fetch:rails', () => { url: 'https://rubyonrails.org/generator', targetPath: 'something', values: { - help: 'me', + railsArguments: { + minimal: true, + }, }, }, templateInfo: { diff --git a/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.ts b/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.ts index 0e27810db3..ca8416654a 100644 --- a/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.ts +++ b/plugins/scaffolder-backend-module-rails/src/actions/fetch/rails/index.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { JsonObject } from '@backstage/types'; import { InputError } from '@backstage/errors'; import { ScmIntegrations } from '@backstage/integration'; import fs from 'fs-extra'; @@ -51,124 +50,104 @@ export function createFetchRailsAction(options: { }) { const { reader, integrations, containerRunner } = options; - return createTemplateAction<{ - url: string; - targetPath?: string; - values: JsonObject; - imageName?: string; - }>({ + return createTemplateAction({ id: 'fetch:rails', description: 'Downloads a template from the given `url` into the workspace, and runs a rails new generator on it.', examples, schema: { input: { - type: 'object', - required: ['url'], - properties: { - url: { - title: 'Fetch URL', + url: z => + z.string({ description: 'Relative path or absolute URL pointing to the directory tree to fetch', - type: 'string', - }, - targetPath: { - title: 'Target Path', - description: - 'Target path within the working directory to download the contents to.', - type: 'string', - }, - values: { - title: 'Template Values', - description: 'Values to pass on to rails for templating', - type: 'object', - properties: { - railsArguments: { - title: 'Arguments to pass to new command', - description: - 'You can provide some arguments to create a custom app', - type: 'object', - properties: { - minimal: { - title: 'minimal', + }), + targetPath: z => + z + .string({ + description: + 'Target path within the working directory to download the contents to.', + }) + .optional(), + values: z => + z.object({ + railsArguments: z + .object({ + minimal: z + .boolean({ description: 'Preconfigure a minimal rails app', - type: 'boolean', - }, - skipBundle: { - title: 'skipBundle', + }) + .optional(), + skipBundle: z + .boolean({ description: "Don't run bundle install", - type: 'boolean', - }, - skipWebpackInstall: { - title: 'skipWebpackInstall', + }) + .optional(), + skipWebpackInstall: z + .boolean({ description: "Don't run Webpack install", - type: 'boolean', - }, - skipTest: { - title: 'skipTest', + }) + .optional(), + skipTest: z + .boolean({ description: 'Skip test files', - type: 'boolean', - }, - skipActionCable: { - title: 'skipActionCable', + }) + .optional(), + skipActionCable: z + .boolean({ description: 'Skip Action Cable files', - type: 'boolean', - }, - skipActionMailer: { - title: 'skipActionMailer', + }) + .optional(), + skipActionMailer: z + .boolean({ description: 'Skip Action Mailer files', - type: 'boolean', - }, - skipActionMailbox: { - title: 'skipActionMailbox', + }) + .optional(), + skipActionMailbox: z + .boolean({ description: 'Skip Action Mailbox gem', - type: 'boolean', - }, - skipActiveStorage: { - title: 'skipActiveStorage', + }) + .optional(), + skipActiveStorage: z + .boolean({ description: 'Skip Active Storage files', - type: 'boolean', - }, - skipActionText: { - title: 'skipActionText', + }) + .optional(), + skipActionText: z + .boolean({ description: 'Skip Action Text gem', - type: 'boolean', - }, - skipActiveRecord: { - title: 'skipActiveRecord', + }) + .optional(), + skipActiveRecord: z + .boolean({ description: 'Skip Active Record files', - type: 'boolean', - }, - - force: { - title: 'force', + }) + .optional(), + force: z + .boolean({ description: 'Overwrite files that already exist', - type: 'boolean', - }, - api: { - title: 'api', + }) + .optional(), + api: z + .boolean({ description: 'Preconfigure smaller stack for API only apps', - type: 'boolean', - }, - template: { - title: 'template', + }) + .optional(), + template: z + .string({ description: 'Path to some application template (can be a filesystem path or URL)', - type: 'string', - }, - webpacker: { - title: 'webpacker', + }) + .optional(), + webpacker: z + .enum(['react', 'vue', 'angular', 'elm', 'stimulus'], { description: 'Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus)', - type: 'string', - enum: ['react', 'vue', 'angular', 'elm', 'stimulus'], - }, - database: { - title: 'database', - description: - 'Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)', - type: 'string', - enum: [ + }) + .optional(), + database: z + .enum( + [ 'mysql', 'postgresql', 'sqlite3', @@ -179,25 +158,28 @@ export function createFetchRailsAction(options: { 'jdbcpostgresql', 'jdbc', ], - }, - railsVersion: { - title: 'Rails version in Gemfile', + { + description: + 'Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)', + }, + ) + .optional(), + railsVersion: z + .enum(['dev', 'edge', 'master', 'fromImage'], { description: 'Set up the application with Gemfile pointing to a specific version (options: fromImage, dev, edge, master)', - type: 'string', - enum: ['dev', 'edge', 'master', 'fromImage'], - }, - }, - }, - }, - }, - imageName: { - title: 'Rails Docker image', - description: - 'Specify a Docker image to run rails new. Used only when a local rails is not found.', - type: 'string', - }, - }, + }) + .optional(), + }) + .optional(), + }), + imageName: z => + z + .string({ + description: + 'Specify a Docker image to run rails new. Used only when a local rails is not found.', + }) + .optional(), }, }, async handler(ctx) {