Static Site Builds with Contentful and Github Actions
A step-by-step guide based on experience and other resources
Stage Setting
A team that manages static contents using Contentful was able to setup a webhook from Contentful against a repository in Github so that the team can rebuild the site on changes in Contentful. The team needs to input the access token in plain text into Contentful as a secret to give it access to the repository
How were they able to do it?
They used the following reference to achieve the goal by using a personal access token:
We don’t need to do all those, just a few steps for the machine_user or “Bot”
The Challenge
The token would have access to ALL private repositories (inside the organization). The team would like to restrict access to a specific repository. For example, https://github.com/the-org/contentful-repository.
Solution
To achieve this, we need to do the following:
- Create an email address for the bot. Since we need this for step 2.
- Register the newly created user in Github.
- Add the “Machine User” or Bot to the organization and provide repository access to only one specific repository.
4. Generate a personal access token for the “machine_user” account.
Add The Bot as Collaborator to the Organization
After step 1 and step 2, it’s time to configure the bot. For this example we will use Contentful Bot. The picture is Gir from the animated TV series Invader Zim.
Make sure your “bot” have only one access which is the private repository.
Generate the Personal Token for the Bot
You can achieve this by logging in as the Bot and go straight to the profile settings.
Developer Settings
Personal access tokens
Click on [repo]
After this step, it showed the token. Copied it and sent it to the ticket reporter. Reporter confirmed that the bot/machine_user worked as expected.
Get Involved
Not a fan of paywall, but would appreciate donation for some coffee… Or pizza.