GitHub Action: Create automated theme previews for Shopify stores

David Süßlin | Aktualisiert am 12. Jan. 2023, 14:04

In this article, you'll learn how to properly incorporate and leverage our GitHub Action to make your store development processes even easier and smoother.

Shopify is a popular platform for building online stores and is often managed and maintained using a GitHub repository. To make the CI/CD processes within a project even easier, we implemented a GitHub Composite Action, which especially facilitates the integration process of changes to the theme and, above all, saves precious time during development.

Über den Autor
David.png
David Süßlin | Fullstack Webdeveloper

David Süßlin ist Frontend-/Backend-Webentwickler der Brand Boosting GmbH, und beschäftigt sich mit der Entwicklung von Shopify Shops, insbesondere bezogen auf benutzerdefinierte Lösungen.

"Create Shopify Theme Preview" is an action on the GitHub Marketplace that allows developers to preview their Shopify theme without having to set up a Shopify test environment.

In this article.

1. advantages of using our action
2. setup of the GitHub Action
3. usage example

Advantages of using our Action

In order to transition changes from specific pull requests to the actual theme, several correction loops often take place.
Reconciling changes in this process can be tedious, as previews only run locally at the respective developer and long-lived preview links have to be created manually before they can be shared with project managers or clients.

To simplify this process, we created a GitHub action that automatically previews a pull request and leaves a comment about the pull request with a link to the preview. If you need to review changes from multiple open pull requests, this action simplifies this many times over.

You don't have to manually create a preview for each pull request using the Shopify CLI, but just leave a comment with the specific predefined keyword. The action then automatically generates the desired links.

The Action is inspired by the Vercel Preview Deployment feature, which allows developers to automatically create a preview as soon as a new commit has taken place.

The Action is especially useful for developers who work on large theme projects and make frequent changes. It also allows project members who have little understanding of code to also have a preview generated without setting up their own local environment.

However, the action is also useful for developers who are working on smaller theme projects and want to preview quickly without requiring a lot of effort.
This can help speed up the development process and improve the quality of themes.

Setting up the GitHub Action

In order for the Action to work for you without any problems, it needs to be set up for each repository it will be used in. Below is the common method via github.com for implementation pointed out and explained:

  1. navigate to the correct repository.
  2. click on the Actions tab
  3. click on New Workflow
  4. copy the code below and save the file (see code snippet)
  5. replace the inputs shopify_flag_store and shopify_cli_theme_token with your own input values
  6. (optional) replace the inputs build_step and dir

Preview.yml

run-name: Create Theme Preview by @${{ github.actor }}
on:
  issue_comment:      
    types: [created]    
jobs:                   
  deploy:
    name: preview
    runs-on: ubuntu-latest
    if: contains(github.event.comment.body, '!preview')
    steps:
      - uses: Brand-Boosting-GmbH/shopify-theme-preview@v1
        with:
          shopify_flag_store: 'your-shop.myshopify.com'
          shopify_cli_theme_token: 'your-cli-theme-token'
          build_step: 'npm i && npm run build'
          dir: 'dist'

Example of use

This action can be triggered by adding the keyword !preview to a pull request comment. The keyword can be customized to filter for a different string in the pull request comments.

github_action1.png

After a few seconds, the entire comment is replaced with a table showing the information and loading status.

github_action2.png

Then, the first table is replaced by another table containing a preview and editor link.

github_action3.png

We have created a repository where the whole thing can be tried out as an example.
You can find an example of how to use it here!

👍 Tip

Don't forget to generate a shopify_cli_theme_token for the repository and provide it as input to this action, along with the shopify_flag_store which is your store URL.

Optional inputs

Optionally, you can add the build_step and dir inputs to the composite action. These inputs are used when there are specific requirements to preview the theme, such as a custom build step or changing the path to a different path before the preview is deployed.

⚠️ Note.

For more information on setting up the shopify_cli_theme_token, see this Theme Access App Guide

Inputs

github_action_inputs.png

The action includes the following steps:

  1. get the current date and time.
  2. create a comment on the pull request with a table containing the name of the store, the preview creation status, and the date and time of the action.
  3. check out the current pull request.
  4. set up Node.js and Ruby.
  5. install the Shopify CLI.
  6. optional build step using the "build-step" input.
  7. use the Shopify CLI to build a preview and save the returned preview link in an output object (optional path via "dir"-input).
    Update the table to display the preview links. 9.
  8. if any of the previous steps fail, create a comment on the pull request with an error message.

Helpful links

GitHub Action
GitHub Marketplace
Example Usage
Theme Access App Guide

brand-boosting.de

Vercel for GitHub
Vercel Preview Deployment

Kontaktieren Sie uns!

Stellen Sie jetzt hier Ihre Anfrage.
Wir sind für Sie per E-Mail, Telefon oder Kontaktformular erreichbar.

+49 7431 9493440 Mo - Fr 10:00 - 18:00 Uhr
info@brand-boosting.de Antwort innerhalb von einem Werktag

Sichere Übermittlung

*Bereits mit dem Klick auf 'Weiter' stimmen Sie der Speicherung Ihrer (personenbezogenen) Daten zur Kontaktaufnahme durch die Brand Boosting GmbH zu.

Vereinbaren Sie jetzt ein kostenloses Erstgespräch!