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:
Write code, fix stuff, etc. and commit my changes, pushing them to GitHub as needed.
When I’m ready to release a new version,
Update the manifest.json with the right version, commit and push it.
use git tag <version number>, e.g. <git tag 1.0.0 using semantic versioning.
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.
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 ).
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:
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
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)
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
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/obsidian-shellcommands@61901f1 · GitHub
Thank you for your support!
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?
@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
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?
Thanks, I’ll try it! I though it would be somewhere in .github/workflows/release.yml and was confused .
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.
Run npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~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.
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/git@/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