Shopify Github Action for versioning
Shopify recently updated their admin panel again and started to display the value of theme_version
from config/settings_schema.json
onto the theme listing page. Example (yellow highlight):
With our setup, all our client themes are connected to Github and every release gets tagged a version in SYMVER format.
Depending on a developer or release manager to manually update config/settings_schema.json
before releasing is not ideal; even with a process guide or release checklist, there is a chance it can be missed. We wanted an automated solution to update the theme_version
value upon a tag being pushed to the master
branch.
We have come up with the following solution (.github/workflows/schema_version.yml
):
name: Schema version
on:
create:
tags: [ v* ]
jobs:
replacement:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Update settings_schema.json
run: |
sed -i 's/"theme_version": ".*"/"theme_version": "'${GITHUB_REF_NAME:1}'"/g' config/settings_schema.json
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
push: origin HEAD:master
default_author: github_actions
message: "Updated settings_schema.json to version '${{ github.ref_name }}'"
add: config/settings_schema.json
Now, anytime a version tag gets pushed to the master
branch, the action will do the following:
- Confirm the action to only run upon tagging; lines 3-5
- Confirm the steps will only run if tagging happened; line 10
- Checkout the repository; lines 12-13
- Utilize
sed
to inline-replace thetheme_version
value to${GITHUB_REF_NAME}
(removes thev
); line 17 - Commit the changes to the schema with a commit message containing the version; lines 19-25
Hopefully this is a helpful starting point for any other developers looking to do the same process.