Skip to content

Instantly share code, notes, and snippets.

@mxmauro
Created February 13, 2024 14:08
Show Gist options
  • Save mxmauro/bc9538417001a869884fe9c6efd0fe58 to your computer and use it in GitHub Desktop.
Save mxmauro/bc9538417001a869884fe9c6efd0fe58 to your computer and use it in GitHub Desktop.
Using custom GitHub application to enhance GitHub actions

Using custom GitHub application to enhance GitHub actions

Application creation

  1. Go to your GitHub company's profile settings: https://github.com/organizations/{company name}/settings/profile
  2. Under developer settings on the left side menu, click on GitHub Apps.
  3. Click on New GitHub App buttton.
  4. Enter the application name, homepage url, disable webhook unless you need it.
  5. Set up repository access permissions. For e.g., read only access to Content, Packages and Metadata.
  6. Set up organization access permissions. For e.g., read only access to Members.
  7. Set up the rest of the options depending on your needs.
  8. Click on the Create GitHub App button.
  9. Take note of the Application and Client IDs for future usage.

Client secret generation

  1. Back in the application's settings, click on the Generate a New Client Secret button.
  2. Copy it into a secure place.

Private key generation

  1. Again, in the application's settings, click on the Generate a Privte Key button at the bottom of the page.
  2. The browser will ask to download the privte key file. Store it on a safe place.

Installation

  1. On the left side menu of the application's settings, click on Install App option. Your company will be listed.
  2. Click on the install button and select the repositories you will allow access. You will be redirected to an URL like this:
    https://github.com/organizations/{company name}/settings/installations/{id}
    
  3. Store the ID number as the application installation ID for future usage.

Using the application in a GitHub Action

Assuming you save both the application ID and private key in two different organization secrets named APP_ID and PRIVATE_KEY, below an example workflow:

jobs:
  sample-job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/create-github-app-token@v1
        id: app-token
        with:
          app-id: ${{ secrets.APP_ID }}
          private-key: ${{ secrets.PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}
          repositories: "repo1"

      - uses: actions/checkout@v4
        with:
          repository: ${{ github.repository_owner }}/repo1
          token: ${{ steps.app-token.outputs.token }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment