This GitHub Action updates your profile README.md based on data in the Contentful headless CMS. Right now it can show the following:
- Header
- Subheader
- Footer
- Website URL (formatted like a button)
- Current position
- Projects
The code is built around my Contentful setup so it probably won't work for you out of the box, luckily it is easy to modify:
- Edit
src/queries/readme.gqlto provide the data that you want to display - Create
.env.contentful-codegenwith the following template, adding the corresponding values after the=:
CONTENTFUL_CONTENT_TOKEN=
CONTENTFUL_MANAGEMENT_TOKEN=
CONTENTFUL_SPACE_ID=- Run
yarn gql-codegento generate TypeScript typings for your GraphQL objects (usesfix-contentful-schemaso the required properties in the typings will match the required option in your Contentful content type definitions) - Update any type/interface names in the files in the
srcdirectory that may have changed from the code generation - Edit
src/main.tsandaction.ymlto define the action inputs - Edit
src/generate.tsto use the values from the query (right now there's some code to handle key value pair objects but you can remove that if you want)
Required Contentful content access token
Required Contentful space ID (not the name)
Required The name of the Key-Value pair in Contentful with the header text
The name of the Key-Value pair in Contentful with the subheader text
The name of the Key-Value pair in Contentful with the footer text
The ID of the set of projects in Contentful to display
The name of the Key-Value pair in Contentful with a URL for a website to link to
The limit of the number of projects to display
Path of your README.md file.
Required Set this to: ${{ secrets.GITHUB_TOKEN }}
This article applies to the repository that this is based on. Most of it will also apply to this repository but you will need to make changes to the parameters and uses field, see the example below.
-
Article on Medium: https://medium.com/@theboi/how-to-dynamically-update-your-github-profile-readme-using-github-actions-684be5db9932
-
Create a repository named your username, add a
README.mdfile. -
Create a workflow and paste this under
steps:
- name: Update README
id: github-contentful-readme
uses: Merlin04/github-contentful-readme@v[Insert latest release here, see https://github.com/Merlin04/github-contentful-readme/releases]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
headerKey: "github-header"
subheaderKey: "github-subheader"
footerKey: "github-footer"
setOfProjectsCollectionId: "projects-collection-id"
urlKey: "website-url"
projectsLimit: 4
contentfulAccessToken: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
contentfulSpaceId: ${{ secrets.CONTENTFUL_SPACE_ID }}```
- You might want to schedule this to run every 10 mins, paste this under `on`:
```yaml
schedule:
- cron: "*/10 * * * *"- This will now run, updating your README with the latest values from Contentful, every 10 mins.