Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyguenther committed Mar 2, 2024
1 parent 997abfe commit e1ccbbb
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions docs/the_complete_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build system to support the development of a theme for a client.
Unfortunately, the Shopify GitHub integration doesn't work in this case. It
expects a single usage of a theme to be represented by a single repo. It will
automatically open PRs as customizations are made and there is no way to
separate a theme's data from its files.
separate a theme's data from its files.

We want to use a single theme and repo for all three expansion stores to
reduce development effort. We only want a store's settings to differ. We also
Expand All @@ -29,9 +29,10 @@ The first step to build this workflow is to establish a way to manage theme
settings. Theme settings are important because they are the data that defines
how a storefront looks. Mess them up and the storefront is broken. How to sync
settings from the live theme to a new theme is something that theme developers
have to consider as they work.
have to consider as they work.

## Manage Settings

To manage theme settings we create buckets of settings. These buckets of settings
are kept in a `.shopkeeper` directory in the root of your project.

Expand Down Expand Up @@ -81,6 +82,7 @@ settings:
npx shopify bucket init
npx shopify bucket create --bucket production
```

We also install [direnv](https://direnv.net) in our shell so our environment
variables are updated anytime we update our `.env` file.

Expand Down Expand Up @@ -120,6 +122,7 @@ down the latest settings from our live theme:
```console
shopify theme settings download
```

This pulls down the latest settings into `theme`. We can then store these in
our `production` bucket by running:

Expand Down Expand Up @@ -186,8 +189,8 @@ into account.

Shopkeeper supports multiple deployment strategies:

* Basic
* Blue/Green
- Basic
- Blue/Green

By default, Shopkeeper assumes you want to use a [blue/green deployment
strategy](https://en.wikipedia.org/wiki/Blue–green_deployment). A blue/green
Expand Down Expand Up @@ -250,6 +253,7 @@ When you're ready, you can publish the on-deck theme by running:
```console
shopify theme publish --theme $SKR_FLAG_<color>_THEME_ID
```

You can also publish it from the admin.

And now for the grand finale. It's time to bring in the robots. :robot:
Expand All @@ -260,9 +264,9 @@ Shopkeeper is a handy when used locally. Where it really shines :sparkles:
is when used in combination with [GitHub Actions](https://docs.github.com/en/actions).

To automate your workflow with GitHub Actions, the following workflows are needed:
| Workflow | Purpose |
| Workflow | Purpose |
|--------------- | --------------- |
| [Blue/Green Deploy](#automate-bluegreen-deploys) | On merge to `main`, deploy code to on-deck theme |
| [Blue/Green Deploy](#automate-bluegreen-deploys) | On merge to `main`, deploy code to on-deck theme |
| [Backup Theme Settings](#backup-theme-settings) | On a set interval, create PRs for theme settings |
| [Generate Preview Theme](#generate-preview-theme) | When a branch receives a push, create/update a preview theme |
| [Delete Preview Theme](#delete-preview-theme) | When a PR is closed, delete the preview theme |
Expand All @@ -272,7 +276,7 @@ a `build:prod` script in your `package.json` that takes care of prepare `theme`

#### Automate Blue/Green Deploys

Let's start with automating our blue/green deploys.
Let's start with automating our blue/green deploys.

In `.github/workflows/blue-green.yml`, write:

Expand Down Expand Up @@ -302,8 +306,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "19"
cache: "yarn"
node-version: '19'
cache: 'yarn'
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
Expand Down Expand Up @@ -335,7 +339,7 @@ name: Backup Theme Settings
on:
schedule: # run the settings backup every hour
- cron: "0 */1 * * *"
- cron: '0 */1 * * *'
workflow_dispatch:
jobs:
Expand All @@ -351,8 +355,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "19"
cache: "yarn"
node-version: '19'
cache: 'yarn'
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
Expand Down Expand Up @@ -412,11 +416,11 @@ on:
types:
- reopened
branches-ignore:
- "github-action/**"
- 'github-action/**'
push:
branches-ignore:
- "master"
- "github-action/**"
- 'main'
- 'github-action/**'
workflow_dispatch:
Expand All @@ -434,8 +438,8 @@ jobs:
slug-maxlength: 50 # Shopify preview environment name cannot be more than 50 chars
- uses: actions/setup-node@v3
with:
node-version: "19"
cache: "yarn"
node-version: '19'
cache: 'yarn'
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
Expand Down Expand Up @@ -471,9 +475,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
**Preview:** [Storefront](https://${{ vars.SHOPIFY_FLAG_STORE }}?preview_theme_id=${{ env.THEME_ID }}) | [Admin](https://${{ vars.SHOPIFY_FLAG_STORE }}/admin/themes/${{ env.THEME_ID }}/editor)
delete_prev_regex_msg: "Preview:" # OPTIONAL
**Preview:** [Storefront](https://${{ vars.SHOPIFY_FLAG_STORE }}?preview_theme_id=${{ env.THEME_ID }}) | [Admin](https://${{ vars.SHOPIFY_FLAG_STORE }}/admin/themes/${{ env.THEME_ID }}/editor)
delete_prev_regex_msg: 'Preview:' # OPTIONAL
```

To generate a preview theme, we listen to pushes on any branch other than `main`
and ones starting with `github-action/`. Branches starting with `github-action/`
are used for settings commits. We restore the theme settings from our
Expand All @@ -486,7 +491,7 @@ are used for settings commits. We restore the theme settings from our
> the same name, so it cannot be used.

When a PR is opened, we generate a comment on the PR with a link to the preview
theme on Shopify.
theme on Shopify.

#### Delete Preview Theme

Expand All @@ -498,7 +503,7 @@ name: Delete Preview Theme
on:
pull_request:
types: [closed]
branches-ignore: ["github-action/**"]
branches-ignore: ['github-action/**']
jobs:
delete:
Expand All @@ -513,8 +518,8 @@ jobs:
slug-maxlength: 50 # Shopify preview environment name cannot be more than 50 chars
- uses: actions/setup-node@v3
with:
node-version: "19"
cache: "yarn"
node-version: '19'
cache: 'yarn'
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
Expand All @@ -524,6 +529,7 @@ jobs:
- name: Delete theme
run: npx shopify theme delete --theme ${{ env.GITHUB_REF_NAME_SLUG_URL }} --force
```

Latest but not least, we clean up after ourselves. When a PR is closed, we
delete the theme corresponding to its branch.

Expand Down

0 comments on commit e1ccbbb

Please sign in to comment.