Skip to content

Manual Plugin Release #35

Manual Plugin Release

Manual Plugin Release #35

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: |
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 [ "$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:
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: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- 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 and generate artifacts
id: release_prep
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
# Build all packages including release-notes
echo "Building packages..."
pnpm build --filter "@file-organizer/release-notes"
# Create a temporary file for the release data
echo "Preparing release data..."
node -e "
const { updateVersions, generateReleaseArtifacts, prepareReleaseArtifacts, generateReleaseNotes } = require('./packages/release-notes/dist');
async function run() {
try {
const repoRoot = process.cwd();
// Step 1: Update versions
console.log('Updating versions...');
const versionInfo = await updateVersions('${{ github.event.inputs.increment }}', repoRoot);
console.log('Version info:', JSON.stringify(versionInfo));
// Step 2: Build plugin
console.log('Building plugin...');
await generateReleaseArtifacts(versionInfo.previous, {
repoRoot,
openAIApiKey: process.env.OPENAI_API_KEY
});
// Step 3: Generate release notes
console.log('Generating release notes...');
const notes = await generateReleaseNotes(versionInfo.previous, {
repoRoot,
openAIApiKey: process.env.OPENAI_API_KEY
});
// Step 4: Prepare artifacts
console.log('Preparing artifacts...');
const artifacts = await prepareReleaseArtifacts(versionInfo.new);
console.log('Generated artifacts:', artifacts);
// Write the complete release data to a file
const releaseData = { versionInfo, notes };
require('fs').writeFileSync('release-data.json', JSON.stringify(releaseData, null, 2));
console.log('Release data written to release-data.json');
} catch (error) {
console.error('Error during release preparation:', error);
process.exit(1);
}
}
run().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});
"
- name: Save release data
id: save_release_data
run: |
if [ ! -f "release-data.json" ]; then
echo "Error: release-data.json was not created"
exit 1
fi
# Read the file and set outputs
VERSION=$(jq -r '.versionInfo.new' release-data.json)
RELEASE_NAME=$(jq -r '.notes.name' release-data.json)
RELEASE_DESC=$(jq -r '.notes.description' release-data.json)
TECHNICAL_CHANGES=$(jq -r '.notes.technicalChanges | join("\n- ")' release-data.json)
# Save to outputs
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "release_name=${RELEASE_NAME}" >> $GITHUB_OUTPUT
# Use delimiter for multiline strings
echo "release_desc<<EOF" >> $GITHUB_OUTPUT
echo "${RELEASE_DESC}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "technical_changes<<EOF" >> $GITHUB_OUTPUT
echo "${TECHNICAL_CHANGES}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Push changes
run: git push origin HEAD
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify artifacts
run: |
# Check if required files exist
for file in main.js styles.css manifest.json checksums.txt; do
if [ ! -f "release-artifacts/$file" ]; then
echo "Error: release-artifacts/$file is missing"
exit 1
fi
done
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create release notes markdown
{
echo "# ${{ steps.save_release_data.outputs.release_name }}"
echo ""
echo "${{ steps.save_release_data.outputs.release_desc }}"
echo ""
echo "## Technical Changes"
echo "- ${{ steps.save_release_data.outputs.technical_changes }}"
echo ""
echo "## SHA-256 Checksums"
cat release-artifacts/checksums.txt
} > release-notes.md
# Verify release notes were created
if [ ! -f "release-notes.md" ]; then
echo "Error: Failed to create release notes"
exit 1
fi
# Create the GitHub release
gh release create "${{ steps.save_release_data.outputs.version }}" \
--title="${{ steps.save_release_data.outputs.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