Dispatch a GitHub Action via a fine-grained Personal Access Token

Finally, I made a move with my blog to start using two repositories in production. One repository holds all the markdown content and assets, and another contains the content of my website.

The reason for this change is that I want to use the content of my blog for testing out other static-site generators and frameworks.

info Here is an example of how to use it with Astro by symlinking the content and assets

I have been testing it out, and the flow works great. To make my site go live with this new setup, I needed to configure a GitHub Action to build and deploy my site.

What I want to achieve is the following:

Show image Trigger a new build
Trigger a new build

GitHub Action Trigger

The first thing I needed to do was add the trigger on my Repository 1 containing the website’s sources.

1
2
3
on:
  repository_dispatch:
    types: update

Once you add this to the build flow, you can call a webhook on the repository to trigger the build.

Trigger the GitHub Action

On the repository 2 containing my blog’s content, I needed to add a new workflow to trigger the build. When you go to the documentation, it will tell you to use a Personal Access Token (PAT) with the repo scope.

In my case, I wanted to use the fine-grained personal access token, as it allows more control over the permissions of the token.

To be able to call the webhook, you will need to add a token with the following scopes:

  • Read access to metadata (by default enabled)
  • Read and Write access to contents
Show image Fine-grained permissions
Fine-grained permissions

Once you have the token, add it to the secrets of your repository, and configure the following workflow to trigger the build:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
name: Trigger blog to build

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  trigger:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger blog build
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: <username>/<repository>
          event-type: update

Comments

Back to top