Using GitHub actions to release plugins

If you’re like me, and you some times worry whether you have uploaded the right version of the files to a GitHub release, this might help you a little!

I’m using GitHub actions to automate this. My workflow looks like this:

  1. Write code, fix stuff, etc. and commit my changes, pushing them to GitHub as needed.
  2. When I’m ready to release a new version,
    1. Update the manifest.json with the right version, commit and push it.
    2. use git tag <version number>, e.g. <git tag 1.0.0 using semantic versioning.
  3. Push the new tag to GitHub git push origin --tags
  4. GitHub takes care of the rest

I want to use this, what do I do?

Here’s how I’m using it in my nldates-obsidian plugin. To add this to your repository just copy the file and save it in the .github/workflows/ path, i.e. your should have a .github/workflows/releases.yml. file. Note that the .github folder is a hidden one!

Note that if you are using styles.css, you’ll need to add that file in line 29, and uncomment the last few lines.

25 Likes

Building on this base I’ve created my own version.
It doesn’t require you to update your plugin name, as it just uses the name of the repo to create the zip file (I want to do as little work as possible :sweat_smile:).
I eventually want to update it to somehow grab release notes and put them in the release. Still thinking about how I want to manage that…


I’ve also created a second script that you can trigger manually within the github interface to bump the version number (major, minor or patch — you decide) and push the updates to the manifest file and create the git tag for you, which will then trigger the release workflow.

There are two catches:

  1. You have to provide a Personal Access Token in a GitHub Secret called PAT — this is so the push will trigger the second workflow. It doesn’t get triggered when you use secrets.GITHUB_TOKEN
  2. You should probably provide an .npmrc file in the root of your repo which has tag-version-prefix = "" to get rid of the v from the start of the version number
    (I do want to get rid of this requirement now I have half an idea what I’m doing. I shouldn’t need to rely on NPM to do the bumping for me)
4 Likes

Maybe this helps someone :blush:
I created a very simple bash script that I use locally to update the release numbers and push a tag: obsidian-tasks/release.sh at main · schemar/obsidian-tasks · GitHub
The only dependency is jq.

If you run ./release.sh 1.0.1 0.11.13, the script will update your plugin version to 1.0.1 in the package and manifest file. It will also set the minimum required obsidian version to 0.11.13 in the manifest and versions files (with a new entry in versions).

It will also (after confirmation) create and push a tag with the new version. Combined with @argentum’s GitHub action, this will then create a release :grimacing:

2 Likes

A friend of mine and I have a few tools we use for building obsidian plugins. There’s a tool for publishing there too, if you’re interested: obsidian-tools/packages/auto-plugin-obsidian at main · zephraph/obsidian-tools · GitHub

It uses a tool called auto to do the publishing. You can see it in action here: obsidian-plugin-prettier/main.yml at main · hipstersmoothie/obsidian-plugin-prettier · GitHub

2 Likes

Hi,

can someone help me? My release action ran about 6 hours in github and then timeouted. Sounds like something went into an eternal loop. This is the first time I’m trying this. Here’s the workflow file and the plugin repository: Release 0.1.0 · Taitava/[email protected] · GitHub

Thank you for your support! :slight_smile:

P.S. How long should it usually run? Should it be over in just a minute or can it take longer even if everything is alright?

cc @SkepticMystic didn’t you have an issue with that as well earlier today?

1 Like

@koala @Jare yes, I did have this issue.
There were some recommendations on how to fix it posted on the plugin-dev channel. I’ll find them and post here when able. I didn’t try them yet, though

1 Like

Here is the message I posted in the Discord, with some suggestions for a fix posted below.

Thanks. I saw one related answer in the discussion by AIDurber on 2021-08-28. I’ll quote it here:

Yeah I had an issue with that. I could also replicate it locally with a build so I assumed it was something with rollup. obsidian-plugin-cli build seems to work fine though so I just swapped it out. "build": "obsidian-plugin build src/main.ts -o ."

I just don’t have a clue where I should put the "build": "obsidian-plugin build src/main.ts -o ." part? What is it supposed to replace?

And what is obsidian-plugin-cli?

Thanks for support! :slight_smile:

I think it’s this line in the package.json file: image

1 Like

Thanks, I’ll try it! I though it would be somewhere in .github/workflows/release.yml and was confused :grin: .

I try to remember to post back here how it goes. I don’t currently have a new version to release, so I won’t test this yet, although I will make the change now.

1 Like

Now I tried it again. It doesn’t run forever anymore, but it has some other error now.

The failed run

A quote from the failed run:

Run npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]~2.3.2 (node_modules/rollup/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] No repository field.

added 40 packages from 79 contributors and audited 42 packages in 3.929s

5 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


> [email protected] build /home/runner/work/obsidian-shellcommands/obsidian-shellcommands
> obsidian-plugin build src/main.ts -o .

sh: 1: obsidian-plugin: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] build: `obsidian-plugin build src/main.ts -o .`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-09-10T04_34_01_646Z-debug.log
Error: Process completed with exit code 1.

(Is there a way to make this big block of text to only show the first few lines and a “Show more link”?)

TL;DR I’m not really looking for solutions to this problem anymore. I just wanted to give you an update in case there are people in the same situation and maybe wondering if I was able to make it work or not. It’s not too much work to create releases manually and upload main.js and manifest.json. So I’ll stop here. :slightly_smiling_face:

Here is my version of the version bumping workflow. Shows the current last released version, and then prompts for a new version number. The number is then updated in manifest.json and version.json, pushed to the remote repo, and then released.

No dependencies required, tested on Mac with zsh.

#!/bin/zsh
# cd to git root https://stackoverflow.com/a/38843585
r=$(git rev-parse --git-dir) && r=$(cd "$r" && pwd)/ && cd "${r%%/.git/*}"

if [[ ! -f "./manifest.json" ]] ; then
	echo "manifest.json does not exist yet"
	return
fi
if [[ ! -f "./.github/workflows/release.yml" ]] ; then
	echo "/.github/workflows/release.yml does not exist yet"
	return
fi

# get version number from the manifest of the latest release
repoURL=$(git remote -v | grep [email protected] | grep fetch | head -n1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/[email protected]/https:\/\//' -e 's/\.git//' )
manifestURL="$repoURL"/releases/latest/download/manifest.json
lastVersion=$(curl -sL "$manifestURL" | grep "version" | cut -d\" -f4)
echo "last version: $lastVersion"

# Ask for new version number
echo -n "next version: "
read nextVersion

# set version number in `manifest.json`
sed -E -i '' "s/\"version\".*/\"version\": \"$nextVersion\",/" "manifest.json"

# add version number in `versions.json`, assuming same compatibility
cat "versions.json" | egrep -v "^$" | grep -v "}" | sed -e '$ d' > temp
minObsidianVersion=$(cat "versions.json" | egrep -v "^$" | grep -v "}" | tail -n1 | cut -d\" -f4)
echo "  \"$lastVersion\": \"$minObsidianVersion\"," >> temp
echo "  \"$nextVersion\": \"$minObsidianVersion\"" >> temp
echo "}" >> temp
mv temp versions.json

# push the manifest and versions JSONs
git add -A
git commit -m "version bump to $nextVersion"
git push

# trigger the release action
git tag "$nextVersion"
git push origin --tags