Sign inSign up

humanoids/sanity-webhook-github

By humanoids

•Updated about 6 years ago

A webhook handler for the headless CMS Sanity that triggers a GitHub Action on each content change.

Image
0

410

humanoids/sanity-webhook-github repository overview

⁠Sanity Webhook Github

A module that creates an authenticated Sanity webhook that triggers a GitHub action on each change to a Sanity dataset.

🏠 Humanoids⁠

⁠🤝 Pre-requisites

⁠🚀 Usage

Create or extend an .env file in the root of your project and add the following keys:

  • GITHUB_ORGANIZATION = insert github organization name (string)
  • GITHUB_REPOSITORY = insert repository name string (string)
  • GITHUB_TOKEN = insert github access token authorized for the target repo (string)
  • HUM_SHARED_SECRET = insert secret query parameter suffixed to this repo endpoint (string)

Configure a GitHub Action⁠ in your GitHub Repository by adding a workflow file that will take certain steps once it is triggered. The following is an example of a workflow file that simply echoes once it is triggered:

name: repository_dispatch
on: 
  repository_dispatch:
    types: production_build
jobs:
  build:
    name: Trigger workflow
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "Workflow triggered by Sanity webhook"

You can specify your GitHub action⁠ to run when a specific event_type value is sent in the repository_dispatch webhook payload. By default the event_type is 'production_build', which is triggered on changes made to the 'production' [Sanity dataset](https://www.sanity.io/docs/datasets⁠.

In case you have defined multiple Sanity datasets, you can define specific GitHub actions for these datasets by using a specific event_type for this space.

Next, navigate to the API configuration panel in your Sanity Studio dashboard and add a new webhook by supplying a URL endpoint at which the current project can receive POST requests. Append this endpoint with:

?hum_shared_secret=*insert a shared secret here*

Finally run the following command to activate the Sanity webhook:

$ npm start

⁠🤝 Contributing

Contributions, issues and feature requests are welcome.
Feel free to check issues page⁠ if you want to contribute.

⁠Author

👤 Humanoids

⁠Contributors

👤 Robbin Habermehl

👤 Ruben Werdmüller

👤 Dylan Jongbloed

⁠📝 License

Copyright © 2020 Humanoids BV⁠.

Tag summary

Content type

Image

Digest

Size

59.9 MB

Last updated

about 6 years ago

docker pull humanoids/sanity-webhook-github