UNPKG

@armyknife/backstage-github-template

Version:

GitHub repository template creation for Backstage

130 lines (108 loc) 3.17 kB
# Backstage GitHub Template This package provides GitHub repository template creation for Backstage. ## Installation ```bash # npm npm install @armyknife/backstage-github-template # yarn yarn add @armyknife/backstage-github-template ``` ## Usage In your `packages/backend/src/plugins/scaffolder.ts` file: ```typescript import { createRouter } from '@backstage/plugin-scaffolder-backend'; import { Router } from 'express'; import { PluginEnvironment } from '../types'; import { createGitHubRepoAction } from '@armyknife/backstage-github-template'; export default async function createPlugin( env: PluginEnvironment, ): Promise<Router> { const catalogClient = new CatalogClient({ discoveryApi: env.discovery, }); const actions = [ createGitHubRepoAction({ integrations: ScmIntegrations.fromConfig(env.config), config: env.config, catalogClient, reader: env.reader, }), // ... other actions ]; return await createRouter({ actions, logger: env.logger, config: env.config, database: env.database, reader: env.reader, catalogClient, identity: env.identity, }); } ``` ## Template Configuration Create a template with GitHub repository creation: ```yaml apiVersion: scaffolder.backstage.io/v1beta3 kind: Template metadata: name: github-repo-template title: GitHub Repository description: Create a new GitHub repository spec: owner: user:guest type: service parameters: - title: Repository Information required: - name - owner - description properties: name: title: Repository Name type: string description: Name of the repository owner: title: Repository Owner type: string description: Owner of the repository (organization or user) description: title: Description type: string description: Description of the repository visibility: title: Repository Visibility type: string enum: ['public', 'private', 'internal'] default: private description: Visibility of the repository enableSecurityFeatures: title: Enable Security Features type: boolean default: true description: Enable security features like branch protection, CODEOWNERS, etc. steps: - id: createGitHubRepo name: Create GitHub Repository action: armyknife:github:create-repo input: name: ${{ parameters.name }} owner: ${{ parameters.owner }} description: ${{ parameters.description }} visibility: ${{ parameters.visibility }} enableSecurityFeatures: ${{ parameters.enableSecurityFeatures }} - id: registerCatalog name: Register in Catalog action: catalog:register input: repoContentsUrl: ${{ steps.createGitHubRepo.output.repoContentsUrl }} catalogInfoPath: '/catalog-info.yaml' ``` ## Environment Variables You'll need to set the following environment variables: ```bash GITHUB_TOKEN=your-github-personal-access-token ``` ## License Apache-2.0