Skip to content

docebo/plugin-scaffolder-backend-module-projen

Repository files navigation

plugin-scaffolder-backend-module-projen

Welcome to the run:projen action for the scaffolder-backend.

Getting started

You need to configure the action in your backend:

From your Backstage root directory

# From your Backstage root directory
yarn add --cwd packages/backend @backstage/plugin-scaffolder-backend-module-projen

Configure the action: (you can check the docs to see all options):

// packages/backend/src/plugins/scaffolder.ts

const actions = [
  createRunProjenAction(),
  ...createBuiltInActions({
    containerRunner,
    catalogClient,
    integrations,
    config: env.config,
    reader: env.reader,
  }),
];

return await createRouter({
  containerRunner,
  catalogClient,
  actions,
  logger: env.logger,
  config: env.config,
  database: env.database,
  reader: env.reader,
});

After that you can use the action in your template:

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: projen-demo
  title: Projen Test
  description: Projen example
spec:
  owner: backstage/techdocs-core
  type: service

  parameters:
    - title: Fill in some steps
      required:
        - name
        - owner
      properties:
        name:
          title: Name
          type: string
          description: Unique name of the component
          ui:autofocus: true
          ui:options:
            rows: 5
        owner:
          title: Owner
          type: string
          description: Owner of the component
          ui:field: OwnerPicker
          ui:options:
            allowedKinds:
              - Group
        system:
          title: System
          type: string
          description: System of the component
          ui:field: EntityPicker
          ui:options:
            allowedKinds:
              - System
            defaultKind: System

    - title: Choose a location
      required:
        - repoUrl
        - dryRun
      properties:
        repoUrl:
          title: Repository Location
          type: string
          ui:field: RepoUrlPicker
          ui:options:
            allowedHosts:
              - github.com
        dryRun:
          title: Only perform a dry run, don't publish anything
          type: boolean
          default: false

  steps:
    - id: projen
      name: Projen
      action: run:projen
      input:
        namespace: org:codeowners
        options:
          codeowners: '@${{ parameters.owner }}'

    - id: publish
      if: ${{ parameters.dryRun !== true }}
      name: Publish
      action: publish:github
      input:
        allowedHosts:
          - github.com
        description: This is ${{ parameters.name }}
        repoUrl: ${{ parameters.repoUrl }}

    - id: register
      if: ${{ parameters.dryRun !== true }}
      name: Register
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
        catalogInfoPath: '/catalog-info.yaml'

    - name: Results
      if: ${{ parameters.dryRun }}
      action: debug:log
      input:
        listWorkspace: true

  output:
    links:
      - title: Repository
        url: ${{ steps.publish.output.remoteUrl }}
      - title: Open in catalog
        icon: catalog
        entityRef: ${{ steps.register.output.entityRef }}

You can also visit the /create/actions route in your Backstage application to find out more about the parameters this action accepts when it's installed to configure how you like.

Projen Generators setup

Projen should be installed a dependency of your backstage/packages/backend in package.json

"projen": "^1.2.3"

Alternatively it can be installed globally in the environment using, e.g.: npm install -g projen.