Publish To GitHub

Action ID: github:repo:push
NPM Package:

@backstage/plugin-scaffolder-backend-module-github

Description

Initializes a git repository of contents in workspace and publishes it to GitHub.

Input Schema

PropertyTypeDescriptionRequired
tokenstringThe token to use for authorization to GitHub
repoUrlstringAccepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username
sourcePathstringPath within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.
restrictionsobject-
defaultBranchstring-
gitAuthorNamestringSets the default author name for the commit. The default value is `Scaffolder`
gitAuthorEmailstring-
gitCommitMessagestringSets the commit message on the repository. The default value is `initial commit`
dismissStaleReviewsbooleanNew reviewable commits pushed to a matching branch will dismiss pull request review approvals.
protectDefaultBranchbooleanProtect the default branch after creating the repository. The default value is `true`
protectEnforceAdminsbooleanEnforce admins to adhere to default branch protection. The default value is `true`
requiredCommitSigningboolean-
requiredLinearHistoryboolean-
requireCodeOwnerReviewsbooleanRequire an approved review in PR including files with a designated Code Owner
requireLastPushApprovalbooleanWhether the most recent push to a PR must be approved by someone other than the person who pushed it. The default value is `false`
bypassPullRequestAllowancesobject-
requireBranchesToBeUpToDatebooleanRequire branches to be up to date before merging. The default value is `true`
requiredStatusCheckContextsarrayThe list of status checks to require in order to merge into this branch
requiredApprovingReviewCountnumberSpecify the number of reviewers required to approve pull requests. Use a number between `1` and `6` or `0` to not require reviewers. Defaults to `1`.
requiredConversationResolutionbooleanRequires all conversations on code to be resolved before a pull request can be merged into this branch

Output Schema

PropertyTypeDescriptionRequired
remoteUrlstringA URL to the repository with the provider
commitHashstringThe git commit hash of the initial commit
repoContentsUrlstringA URL to the root of the repository

Usage Examples

Push to an existing GitHub repo on a feature branch

Pushes the scaffolded contents to an existing GitHub repository on a feature branch. Use this when the repository already exists and you want to add or update files generated during scaffolding.

Copy
steps:
  - id: fetch-template
    action: [fetch:template](/backstage/scaffolder-actions/fetch-template/)
    input:
      url: https://github.com/acme-org/software-templates/blob/main/service-template
      targetPath: .
      values:
        componentId: ${{ parameters.componentId }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}

  - id: push-to-github
    action: github:repo:push
    input:
      repoUrl: github.com?owner=acme-services&repo=${{ parameters.repoName }}
      branch: feature/bootstrap-${{ parameters.componentId }}
      commitMessage: "Bootstrap ${{ parameters.componentId }} via Backstage"
      authorName: "Backstage Scaffolder"
      authorEmail: "[email protected]"
      sourcePath: .
      force: false

Create a repo then push a subdirectory to main

Creates a new GitHub repository and pushes only a subdirectory of the workspace to the main branch. Use this when the template generates multiple packages and you want to publish a specific service folder.

Copy
steps:
  - id: fetch-template
    action: [fetch:template](/backstage/scaffolder-actions/fetch-template/)
    input:
      url: https://github.com/acme-org/software-templates/blob/main/monorepo-template
      targetPath: .
      values:
        workspaceName: ${{ parameters.workspaceName }}
        serviceName: ${{ parameters.componentId }}
        owner: ${{ parameters.owner }}

  - id: create-repo
    action: [github:repo:create](/backstage/scaffolder-actions/github-repo-create/)
    input:
      repoUrl: github.com?owner=acme-services&repo=${{ parameters.repoName }}

  - id: push-service
    action: github:repo:push
    input:
      repoUrl: github.com?owner=acme-services&repo=${{ parameters.repoName }}
      branch: main
      commitMessage: "Add ${{ parameters.componentId }} service scaffold"
      sourcePath: services/${{ parameters.componentId }}
      force: true