Theme development - creating an automated release process

While developing my new theme I could not find much guidance for beginners on how to set up a release process, so I have come up with my own. In case it is of help to fellow amateur theme developers, I’ve outlined what I did below.

what I wanted to do was:

  1. automatically create github releases based on changes since the previously published release
  2. automatically deploy any pushed commits to my personal blog
  3. automatically deploy any published versions to my theme demo site.

The out-of-the-box Ghost github integration makes it simple to solve 2 and 3, you just need to configure two workflows, per the instructions.

Solving part I involved a bit more work:

picking a build tool and package management tool

as a novice node/javascript developer, I found the whole topic of js build tools and package managers utterly bewildering. There are too many choices! so I just stuck with gulp and npm respectively, which is how it is done in some of the standard Ghost themes.

The gulp configuration is used to do a few things:

  • concatenation and minification of css/js files
  • creation of a zip file containing all the theme assets needed to install the theme
  • running a file watcher that automatically updates the files in the built directory as you make changes to the theme code

npm is used for two things

  • managing the node package dependencies defined in package.json
  • combing various steps in the release process into single commands (more on this below)

manage github releases

I had to create a new javascript to handle the publication of changes to github. It doesn’t have any dependencies and uses the standard github REST API.

configuring release commands

npm scripts are a nice simple way to organise multiple bash commands that can all be neatly contained in the package.json. This is what I have in my configuration

"scripts": {
        "dev": "gulp dev",
        "zip": "gulp zip",
        "test": "gscan .",
        "bump-patch": "npm version patch --message 'bump patch version to %s' && git push origin main",
        "bump-minor": "npm version minor --message 'bump minor version to %s' && git push origin main",
        "bump-major": "npm version major --message 'bump major version to %s' && git push origin main",
        "create-changelog": "./release --create-changelog",
        "create-release": "./release --create-release published",
        "create-draft-release": "./release --create-release draft",
        "upload-zipfile": "./release --upload-zipfile dist/transmission.zip",
        "full-release": "gscan . && ./release --create-changelog && ./release --create-release published && gulp zip && ./release --upload-zipfile dist/transmission.zip ",
        "draft-full-release": "gscan . && ./release --create-changelog && ./release --create-release draft"
    }

so creating a new release is a simple as

# increments the package.json version and pushes to the github repo.
npm run bump-minor # (or bump-patch/bump-major) 

npm run full-release # gscan, create changelog, publish release on github

you can run the individual steps like npm create-changelog separately if you prefer (this will give you an opportunity to change the release message before publishing the release.

hope that helps someone else!

If I have reinvented the wheel, please don’t worry about hurting my feelings if you let me know :)

3 Likes

having done a bit more reading about this, I’ve now switched over to esbuild instead of gulp. It has built-in support for minfication, concatenation, sourcemaps etc and is all set up using a simple set of options. Apparently it is much faster than gulp too, not that this matters for a small theme.

using esbuild got rid of a few dependencies too which makes me happy as it is less things to try and learn about!

from:

transmission@2.0.0 /Users/nick/dev/www/themes/transmission
β”œβ”€β”€ beeper@3.0.0
β”œβ”€β”€ cssnano@7.0.6
β”œβ”€β”€ gulp-concat@2.6.1
β”œβ”€β”€ gulp-livereload@4.0.2
β”œβ”€β”€ gulp-postcss@10.0.0
β”œβ”€β”€ gulp-uglify@3.0.2
β”œβ”€β”€ gulp-zip@6.0.0
β”œβ”€β”€ gulp@5.0.0
β”œβ”€β”€ photoswipe@5.4.4
β”œβ”€β”€ postcss-easy-import@4.0.0
β”œβ”€β”€ postcss@8.4.47
β”œβ”€β”€ prism-components@1.0.0
β”œβ”€β”€ prism-themes@1.9.0
β”œβ”€β”€ prismjs@1.29.0
β”œβ”€β”€ pump@3.0.2
└── tocbot@4.30.0

to:

transmission@2.5.3 /Users/nick/dev/www/themes/transmission
β”œβ”€β”€ archiver@7.0.1
β”œβ”€β”€ browser-sync@3.0.3
β”œβ”€β”€ esbuild@0.24.0
β”œβ”€β”€ photoswipe@5.4.4
β”œβ”€β”€ prism-components@1.0.0
β”œβ”€β”€ prism-themes@1.9.0
β”œβ”€β”€ prismjs@1.29.0
└── tocbot@4.30.0

Here is the script I came up with for building the theme. It does work, although I suspect some tweaks will be needed once I get my head round ESM modules (having two different ways to import modules is another very confusing part of the JS world :slight_smile: ).

1 Like

now with live browser reload.

I could never get gulp-livereload to work with the old gulp set-up, so I am now using browsersync, which starts without any problems.

note that npm run dev will automatically open a broswer tab with the live reload view. if you don’t like this behaviour you can turn it off by setting open: false in the livereload function