Manual Plugin Release #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Get running workflows named either "Release Obsidian Plugin" or "Manual Plugin Release" | |
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), fail early | |
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 | |
release: | |
needs: check_release | |
if: needs.check_release.outputs.is_releasing != 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
with: | |
# Use a full checkout so the version bump can be committed & pushed | |
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 }}" | |
# Bump version in package.json (using npm's built-in version command) | |
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 (stripped): $VERSION_NUMBER" | |
# Make new version available to subsequent steps | |
echo "version=${VERSION_NUMBER}" >> "$GITHUB_OUTPUT" | |
# Update root manifest.json to match | |
cd ../.. | |
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('./packages/plugin/package.json').version")" | |
echo "Updated manifest.json version: $(node -p "require('./manifest.json').version")" | |
# Stage and commit changes | |
git add packages/plugin/package.json manifest.json | |
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: Push changes | |
# Push the newly bumped version back to the repo | |
run: git push origin HEAD | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build plugin | |
run: pnpm --filter "./packages/plugin" build | |
- name: Prepare release artifacts | |
run: | | |
mkdir -p release-artifacts | |
cp packages/plugin/dist/main.js release-artifacts/ | |
cp packages/plugin/dist/styles.css release-artifacts/ | |
cp packages/plugin/manifest.json release-artifacts/ | |
# Create checksum file | |
cd release-artifacts | |
sha256sum * > checksums.txt | |
cd .. | |
- name: Create Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
version=$(node -p "require('./packages/plugin/manifest.json').version") | |
# Create release notes | |
echo "## Changes in this release" > release-notes.md | |
echo "Version bump: ${{ github.event.inputs.increment }}" >> release-notes.md | |
echo "" >> release-notes.md | |
echo "### SHA-256 Checksums" >> release-notes.md | |
cat release-artifacts/checksums.txt >> release-notes.md | |
# Create the release | |
gh release create "$version" \ | |
--title="Version $version" \ | |
--notes-file=release-notes.md \ | |
--draft=false \ | |
release-artifacts/main.js \ | |
release-artifacts/styles.css \ | |
release-artifacts/manifest.json \ | |
release-artifacts/checksums.txt |