Skip to content

Commit 6b0f819

Browse files
chore: create files containing git actions
Let's track these files outside of the docs.
1 parent 3365d1e commit 6b0f819

4 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Backup Theme Settings
2+
3+
on:
4+
schedule: # run the settings backup every hour
5+
- cron: "0 */1 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
backup:
10+
runs-on: ubuntu-latest
11+
env:
12+
SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }}
13+
SHOPIFY_FLAG_STORE: ${{ vars.SHOPIFY_FLAG_STORE }}
14+
SHOPIFY_FLAG_PATH: ${{ vars.SHOPIFY_FLAG_PATH }}
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
SETTINGS_APPROVER: ${{ secrets.SETTINGS_APPROVER }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: "19"
22+
cache: "yarn"
23+
- uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: 3.2
26+
bundler: "latest"
27+
- name: Install packages
28+
run: yarn install
29+
- name: Download published theme settings
30+
run: npx shopkeeper theme settings download
31+
- name: Store the settings
32+
run: npx shopkeeper bucket save --bucket production
33+
- name: Set up up git user
34+
run: |
35+
# Setup username and email
36+
git config user.name "GitHub Actions Bot"
37+
git config user.email "ops@thebeyondgroup.la"
38+
- name: Store datetime
39+
run: echo "NOW=$(date +"%Y-%m-%d-%H")" >> $GITHUB_ENV
40+
- name: Store branch name
41+
run: echo "NEW_BRANCH=github-action/settings-$NOW" >> $GITHUB_ENV
42+
- name: Create PR
43+
run: |
44+
if [[ -z $(git status -s) ]]
45+
then
46+
echo "No changes. Nothing to commit"
47+
else
48+
gh label create settings-update --force
49+
git checkout -b $NEW_BRANCH
50+
git add .
51+
git commit -m "Update theme settings as of $NOW"
52+
git push origin $NEW_BRANCH
53+
gh pr create --title "Update theme settings as of $NOW" --body "Update to latest theme settings"--label settings-update
54+
# We can't approve the PR with same token that created it.
55+
OLD_GITHUB_TOKEN=$GITHUB_TOKEN
56+
GITHUB_TOKEN=$SETTINGS_APPROVER
57+
gh pr review --approve
58+
GITHUB_TOKEN=$OLD_GITHUB_TOKEN
59+
gh pr merge --merge
60+
fi

docs/github-actions/blue-green.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Shopify Blue/Green Deploy
2+
3+
# Controls when the action will run.
4+
# Triggers the workflow on push or pull request events but only for the master branch
5+
on:
6+
push:
7+
branches: [main]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
deploy:
14+
# The type of runner that the job will run on
15+
runs-on: ubuntu-latest
16+
env:
17+
SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }}
18+
SHOPIFY_FLAG_STORE: ${{ vars.SHOPIFY_FLAG_STORE }}
19+
SHOPIFY_FLAG_PATH: ${{ vars.SHOPIFY_FLAG_PATH }}
20+
SKR_FLAG_BLUE_THEME_ID: ${{ secrets.SKR_FLAG_BLUE_THEME_ID }}
21+
SKR_FLAG_GREEN_THEME_ID: ${{ secrets.SKR_FLAG_GREEN_THEME_ID }}
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v3
25+
with:
26+
node-version: "19"
27+
cache: "yarn"
28+
- name: Install packages
29+
run: yarn install
30+
- name: Select theme settings
31+
run: npx shopkeeper bucket restore --bucket production
32+
- name: Build assets
33+
run: yarn build:prod
34+
- name: Deploy to on deck theme
35+
uses: nick-fields/retry@v2
36+
with:
37+
timeout_minutes: 10
38+
max_attempts: 3
39+
retry_on: error
40+
command: npx shopkeeper theme deploy
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Delete Preview Theme
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches-ignore: ["github-action/**"]
7+
8+
jobs:
9+
delete:
10+
runs-on: ubuntu-latest
11+
env:
12+
SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }}
13+
SHOPIFY_FLAG_STORE: ${{ secrets.SHOPIFY_FLAG_STORE }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: rlespinasse/github-slug-action@v4
17+
with:
18+
slug-maxlength: 50 # Shopify preview environment name cannot be more than 50 chars
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: "19"
22+
cache: "yarn"
23+
- name: Install packages
24+
run: yarn install
25+
- name: Delete theme
26+
run: npx shopkeeper theme delete --theme ${{ env.GITHUB_REF_NAME_SLUG_URL }} --force
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Generate Preview
2+
3+
on:
4+
pull_request:
5+
types:
6+
- reopened
7+
branches-ignore:
8+
- "github-action/**"
9+
push:
10+
branches-ignore:
11+
- "master"
12+
- "github-action/**"
13+
14+
workflow_dispatch:
15+
16+
jobs:
17+
preview:
18+
runs-on: ubuntu-latest
19+
env:
20+
SHOPIFY_CLI_THEME_TOKEN: ${{ secrets.SHOPIFY_CLI_THEME_TOKEN }}
21+
SHOPIFY_FLAG_STORE: ${{ vars.SHOPIFY_FLAG_STORE }}
22+
SHOPIFY_FLAG_PATH: ${{ vars.SHOPIFY_FLAG_PATH }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: rlespinasse/github-slug-action@v4
26+
with:
27+
slug-maxlength: 50 # Shopify preview environment name cannot be more than 50 chars
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version: "19"
31+
cache: "yarn"
32+
- uses: 8BitJonny/gh-get-current-pr@2.2.0
33+
id: pr_status
34+
with:
35+
# Verbose setting SHA when using Pull_Request event trigger
36+
sha: ${{ github.event.pull_request.head.sha }}
37+
# Only return if PR is still open. (By default it returns PRs in any state.)
38+
filterOutClosed: true
39+
# Only return if PR is not in draft state. (By default it returns PRs in any state.)
40+
filterOutDraft: true
41+
- name: Install packages
42+
run: yarn install
43+
- name: Select theme settings
44+
run: npx shopkeeper bucket restore --bucket production
45+
- name: Build assets
46+
run: yarn build:prod
47+
- name: Create theme
48+
uses: nick-fields/retry@v2
49+
with:
50+
timeout_minutes: 10
51+
max_attempts: 3
52+
retry_on: error
53+
command: npx shopkeeper theme create --theme ${{ env.GITHUB_REF_NAME_SLUG_URL }}
54+
- name: Get theme ID
55+
run: echo "THEME_ID=$(npx shopkeeper theme get --theme ${{ env.GITHUB_REF_NAME_SLUG_URL }})" >> $GITHUB_ENV
56+
- name: Add preview link to PR
57+
if: steps.pr_status.outputs.pr_found == 'true'
58+
uses: unsplash/comment-on-pr@master
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
with:
62+
msg: |
63+
**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)
64+
delete_prev_regex_msg: "Preview:" # OPTIONAL

0 commit comments

Comments
 (0)