Skip to content

Manual Plugin Release #4

Manual Plugin Release

Manual Plugin Release #4

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 versions
id: version
run: |
cd packages/plugin
echo "Current directory: $(pwd)"
echo "Current package.json version: $(node -p "require('./package.json').version")"
echo "Current manifest.json version: $(node -p "require('./manifest.json').version")"
echo "Increment type: ${{ github.event.inputs.increment }}"
# Update package.json and get new version
NEW_VERSION=$(npm version ${{ github.event.inputs.increment }} --no-git-tag-version)
VERSION_NUMBER=${NEW_VERSION#v}
echo "New version (with v): $NEW_VERSION"
echo "New version (without v): $VERSION_NUMBER"
echo "version=$VERSION_NUMBER" >> $GITHUB_OUTPUT
# Update manifest.json
jq --arg version "$VERSION_NUMBER" '.version = $version' manifest.json > manifest.json.tmp && mv manifest.json.tmp manifest.json
echo "Updated package.json version: $(node -p "require('./package.json').version")"
echo "Updated manifest.json version: $(node -p "require('./manifest.json').version")"
# Stage and commit changes
git add package.json manifest.json
cd ../..
echo "Files to be committed:"
git status --porcelain
git commit -m "chore(release): bump version to $VERSION_NUMBER"
echo "Commit created with version $VERSION_NUMBER"
- name: Build plugin
run: pnpm --filter "./packages/plugin" build
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
# 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
env:
VERSION: ${{ steps.version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"