Skip to content

Release Obsidian Plugin #27

Release Obsidian Plugin

Release Obsidian Plugin #27

Workflow file for this run

name: Release Obsidian Plugin
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
inputs:
version:
description: 'New version or major, minor, patch'
default: 'patch'
required: true
update_manifest:
description: 'Update manifest.json'
default: true
required: true
type: boolean
update_brat:
description: 'Update brat manifest'
default: true
required: true
type: boolean
retry:
description: "Retry release (clear created tag)"
default: false
required: true
type: boolean
env:
GH_BOT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
GH_BOT_NAME: "GitHub Action"
ZIP_ARTIFACT: slides-extended.zip
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- uses: pnpm/action-setup@v4
with:
version: 8
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
# Build the plugin
- name: Build and Tag
id: build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RETRY: ${{ github.event.inputs.retry }}
VERSION: ${{ github.event.inputs.version }}
MANIFEST: ${{ github.event.inputs.update_manifest }}
BRAT: ${{ github.event.inputs.update_brat }}
run: |
echo "version: $VERSION"
echo "retry: $RETRY"
echo "update_manifest: $MANIFEST"
echo "update_brat: $BRAT"
git config user.name ${{ env.GH_BOT_NAME }}
git config user.email ${{ env.GH_BOT_EMAIL }}
pnpm install
if [[ "$VERSION" == "test" ]]; then
RETRY=true
npm run preversion
else
if [[ "$RETRY" = "true" ]]; then
npm run preversion
else
npm version $VERSION --no-git-tag-version
fi
VERSION=$(grep '^ "version"' package.json | cut -d'"' -f4)
echo next version is $VERSION
fi
TAG_EXISTS=$(git rev-parse "refs/tags/$VERSION" > /dev/null 2>&1; echo $?)
if [[ "$TAG_EXISTS" = "0" ]]; then
if [[ "$RETRY" = "true" ]]; then
gh release delete $VERSION --yes > /dev/null 2>&1 || true
git tag -d $VERSION > /dev/null 2>&1 || true
if git push --delete origin $VERSION
then
echo "🔥 Tag $VERSION deleted"
else
echo "🛑 Failed to delete $VERSION"
exit 1
fi
else
echo "🛑 Tag $VERSION already exists"
exit 1
fi
fi
if [[ "$VERSION" != "test" ]]; then
sed -i 's|\(version":\) "[0-9\.]*"|\1 "'$VERSION'"|' distVersion.json
if [ "$MANIFEST" = "true" ]; then
sed -i 's|\(version":\) "[0-9\.]*"|\1 "'$VERSION'"|' manifest.json
fi
if [ "$BRAT" = "true" ]; then
sed -i 's|\(version":\) "[0-9\.]*"|\1 "'$VERSION'"|' manifest-beta.json
fi
git add .
git status
git commit -m "🔖 $VERSION"
git push
fi
git tag $VERSION
git push --tags
if [[ "$VERSION" == "test" ]]; then
touch release-notes.md
else
npm run brat-notes -- ${VERSION}
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
# Package the required files into a zip
- name: Package
run: |
mkdir tmp
cp -r ./build/css ./build/dist ./build/plugin ./build/template distVersion.json tmp/
cd tmp
zip -r ../${{ env.ZIP_ARTIFACT }} *
cd ..
# Create the release on github
- name: Create Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MANIFEST: ${{ github.event.inputs.update_manifest }}
BRAT: ${{ github.event.inputs.update_brat }}
run: |
prerelease=true
if [ "$MANIFEST" ]; then
prerelease=false
fi
gh release create "${{ steps.build.outputs.version }}" \
-F ./release-notes.md \
--title "Release ${{ steps.build.outputs.version }}" \
--verify-tag \
--prerelease=${prerelease}
gh release upload "${{ steps.build.outputs.version }}" --clobber \
"./${{ env.ZIP_ARTIFACT }}" \
'./build/main.js#main.js' \
'./build/styles.css#styles.css' \
'./manifest.json' \
'./manifest-beta.json'