Skip to content

Manual Plugin Release #3

Manual Plugin Release

Manual Plugin Release #3

name: Manual Plugin Release
on:
workflow_dispatch:
inputs:
increment:
description: 'Version increment type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
jobs:
check_release:
runs-on: ubuntu-latest
outputs:
is_releasing: ${{ steps.check.outputs.is_releasing }}
steps:
- id: check
name: Check for running release workflows
run: |
# Get running workflows
running=$(gh api /repos/${{ github.repository }}/actions/runs \
--jq '.workflow_runs[] | select(.status=="in_progress" and (.name=="Release Obsidian Plugin" or .name=="Manual Plugin Release")) | .id' \
| wc -l)
# If any release workflows are running (besides this one), set output
if [ "$running" -gt "1" ]; then
echo "is_releasing=true" >> $GITHUB_OUTPUT
echo "::error::A release is already in progress. Please wait for it to complete."
exit 1
else
echo "is_releasing=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
needs: check_release
if: needs.check_release.outputs.is_releasing != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install dependencies
run: pnpm install
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Update package.json version
run: |
cd packages/plugin
NEW_VERSION=$(npm version ${{ github.event.inputs.increment }} --no-git-tag-version)
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
cd ../..
git add packages/plugin/package.json
- name: Update manifest.json version
run: |
cd packages/plugin
VERSION_NUMBER=${NEW_VERSION#v}
jq --arg version "$VERSION_NUMBER" '.version = $version' manifest.json > manifest.json.tmp && mv manifest.json.tmp manifest.json
git add manifest.json
cd ../..
git commit -m "chore(release): bump version to ${NEW_VERSION}"
- name: Build plugin
run: pnpm --filter "./packages/plugin" build
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version=$(node -p "require('./packages/plugin/manifest.json').version")
# Create a temporary directory for release files
mkdir release
cp packages/plugin/dist/main.js release/
cp packages/plugin/dist/styles.css release/
cp packages/plugin/manifest.json release/
# Create release notes
echo "## Changes in this release" > release/notes.md
echo "Version bump: ${{ github.event.inputs.increment }}" >> release/notes.md
# Create the release
gh release create "$version" \
--title="Version $version" \
--notes-file=release/notes.md \
--draft=false \
release/main.js \
release/styles.css \
release/manifest.json
- name: Create and push tag
run: |
cd packages/plugin
version=$(node -p "require('./manifest.json').version")
git tag -a "$version" -m "Release $version"
git push origin "$version"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}