Skip to content

Manual Plugin Release #17

Manual Plugin Release

Manual Plugin Release #17

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 to ensure all history is available
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
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"
# Export the new version for subsequent steps
echo "version=${VERSION_NUMBER}" >> "$GITHUB_OUTPUT"
# Update root manifest.json to match the new version
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
run: git push origin HEAD
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build plugin
run: pnpm --filter "./packages/plugin" build
- name: Generate Release Notes
id: release_notes
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
# Build the release-notes package
pnpm --filter "@file-organizer/release-notes" build
# Generate the release notes
cd packages/plugin
previous_version=$(node -p "require('./manifest.json').version")
NOTES_JSON=$(node -r ts-node/register ../release-notes/dist/index.js $previous_version )
echo "NOTES_JSON<<EOF" >> $GITHUB_ENV
echo "$NOTES_JSON" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- 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 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('./manifest.json').version")
# Parse release notes JSON
RELEASE_NAME=$(echo "$NOTES_JSON" | jq -r '.name')
RELEASE_DESC=$(echo "$NOTES_JSON" | jq -r '.description')
TECHNICAL_CHANGES=$(echo "$NOTES_JSON" | jq -r '.technicalChanges | join("\n- ")')
# Create release notes markdown
{
echo "# $RELEASE_NAME"
echo ""
echo "$RELEASE_DESC"
echo ""
echo "## Technical Changes"
echo "- $TECHNICAL_CHANGES"
echo ""
echo "## SHA-256 Checksums"
cat release-artifacts/checksums.txt
} > release-notes.md
# Create the GitHub release
gh release create "$version" \
--title="$RELEASE_NAME" \
--notes-file=release-notes.md \
--draft=false \
release-artifacts/main.js \
release-artifacts/styles.css \
release-artifacts/manifest.json \
release-artifacts/checksums.txt