Home

Awesome

Contentful Action Example

An example application for how you can integrate content migrations in your continuous delivery pipeline using Contentful's GitHub Action.

What is this about?

This example contains a folder of Migration Scripts. Whenever a new script is added to this repo, it's evaluated against a Contentful space. If the migration is added via pull request, a new environment is created on Contentful and the migration is run against that. If a new script is added to master (either directly or via merging a PR) then a new environment is created, migrations are run against that environment and then the alias for master is updated to point to that new environment.

You can read our conceptual guide on how to utilize Contentful Environments inside your continuous delivery pipeline.

You can further expand this example by integrating other GitHub actions, such as testing and deployment options.

Getting started

Requirements

To use the continuous delivery pipeline of this project you need accounts for the following services:

Setup

The Contentful part (required)

The continuous delivery pipeline

Since we're using GitHub Actions, we'll be able to use the existing Contentful-Action repo. Just add the following code into your github workflow.

    - name: Contentful Migration
      id: migrate
      uses: contentful-userland/contentful-action@main
      with:
        # delete_feature: true
        # set_alias: true
        # master_pattern: "main-[YY]-[MM]-[DD]-[hh]-[mm]"
        # feature_pattern: "sandbox-[branch]"
        # version_field: versionCounter
        # version_content_type: environmentVersion
        # migrations_dir: contentful/migrations
        space_id: ${{ secrets.SPACE_ID }}
        management_api_key: ${{ secrets.MANAGEMENT_API_KEY }}
      # env:
        # LOG_LEVEL: verbose

You can view the main.yml for example of a full working configuration.

Screenshot of GitHub Secret Panel

You'll also need to add your SPACE_ID and MANAGEMENT_API_KEY in the secrets tab of the settings on your repository. You can optionally add a MIGRATIONS_DIR secret if you're storing your migration scripts somewhere besides the migrations folder.

License

Copyright (c) 2020 Contentful GmbH. Code released under the MIT license.