From 4bfb89226f5ec4a146210e380c24b5e8b1888901 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:52:55 +0100 Subject: [PATCH] refactor: simplify release workflow (#302) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: ben --- .github/workflows/manual-release.yml | 33 ++++++++++-- .github/workflows/release.yml | 59 -------------------- packages/plugin/commit.js | 24 --------- release.js | 81 ---------------------------- 4 files changed, 29 insertions(+), 168 deletions(-) delete mode 100644 .github/workflows/release.yml delete mode 100644 packages/plugin/commit.js delete mode 100644 release.js diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml index 2fe83e7b..be25bbc4 100644 --- a/.github/workflows/manual-release.yml +++ b/.github/workflows/manual-release.yml @@ -70,15 +70,40 @@ jobs: run: | cd packages/plugin pnpm version ${{ github.event.inputs.increment }} --no-git-tag-version + + - name: Build plugin + run: pnpm --filter "./packages/plugin" build - - name: Update manifest and versions + - name: Create Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - cd packages/plugin - pnpm run version + 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 - node commit.js + version=$(node -p "require('./manifest.json').version") + git tag -a "$version" -m "Release $version" + git push origin "$version" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 13dcd22b..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Release Obsidian Plugin - -on: - push: - tags: - - "*" - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - 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: Build plugin - run: pnpm --filter "./packages/plugin" build - - - name: Get plugin version - id: version - run: | - version=$(node -p "require('./packages/plugin/manifest.json').version") - echo "version=$version" >> $GITHUB_OUTPUT - - - name: Create Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - 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 from git log - git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD > release/notes.md - - # Create the release - gh release create "${{ steps.version.outputs.version }}" \ - --title="Version ${{ steps.version.outputs.version }}" \ - --notes-file=release/notes.md \ - --draft=false \ - release/main.js \ - release/styles.css \ - release/manifest.json \ No newline at end of file diff --git a/packages/plugin/commit.js b/packages/plugin/commit.js deleted file mode 100644 index 55bd0737..00000000 --- a/packages/plugin/commit.js +++ /dev/null @@ -1,24 +0,0 @@ -const fs = require('fs'); -const { exec } = require('child_process'); - -// Read manifest.json -fs.readFile('manifest.json', 'utf8', (err, data) => { - if (err) { - console.error(`Error reading file: ${err}`); - return; - } - - // Parse JSON - const manifest = JSON.parse(data); - const version = manifest.version; - - // Create git tag and push - exec(`git tag -a ${version} -m "${version}" && git push origin ${version}`, (err, stdout, stderr) => { - if (err) { - console.error(`Error executing git commands: ${err}`); - return; - } - - console.log(`Tag ${version} created and pushed successfully.`); - }); -}); \ No newline at end of file diff --git a/release.js b/release.js deleted file mode 100644 index e50c2d1d..00000000 --- a/release.js +++ /dev/null @@ -1,81 +0,0 @@ -const { execSync } = require('child_process'); -const readline = require('readline'); -const fs = require('fs'); - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -function executeCommand(command) { - try { - return execSync(command, { encoding: 'utf8' }); - } catch (error) { - console.error(`Error executing command: ${command}`); - console.error(error.message); - process.exit(1); - } -} - -function updatePackageVersion(version) { - const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); - packageJson.version = version; - fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2)); -} - -function updateVersionFiles() { - executeCommand('node version-bump.mjs'); -} - -async function release() { - // Get current version - const currentVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; - console.log(`Current version: ${currentVersion}`); - - // Prompt for new version - const newVersion = await new Promise(resolve => { - rl.question('Enter new version number: ', resolve); - }); - - // Prompt for release description - const description = await new Promise(resolve => { - rl.question('Enter release description: ', resolve); - }); - - // Update package.json - updatePackageVersion(newVersion); - - // Run version-bump.mjs - updateVersionFiles(); - - // Build the plugin - executeCommand('npm run build'); - - // Git commands - executeCommand('git add .'); - executeCommand(`git commit -m "Release ${newVersion}: ${description}"`); - executeCommand(`git tag -a ${newVersion} -m "${description}"`); - executeCommand('git push'); - executeCommand(`git push origin ${newVersion}`); - - // Create source code archives - executeCommand('git archive --format=zip HEAD > source-code.zip'); - executeCommand('git archive --format=tar.gz HEAD > source-code.tar.gz'); - - // Create GitHub release - const releaseCommand = `gh release create ${newVersion} \ - --title "${newVersion}" \ - --notes "${description}" \ - main.js manifest.json styles.css source-code.zip source-code.tar.gz`; - - executeCommand(releaseCommand); - - // Clean up temporary files - fs.unlinkSync('source-code.zip'); - fs.unlinkSync('source-code.tar.gz'); - - console.log(`Version ${newVersion} has been released!`); - rl.close(); -} - -release(); \ No newline at end of file