From 74f9321362a089825014271669edaba9adb4c68b Mon Sep 17 00:00:00 2001 From: Kacper Kula Date: Thu, 22 May 2025 11:22:36 +0100 Subject: [PATCH] chore: new release mechanism with changesets --- .github/workflows/publish.yml | 59 ----------------------------------- .github/workflows/release.yml | 43 +++++++++++++++++++++++++ package.json | 4 ++- scripts/tag-and-publish.sh | 28 +++++++++++++++++ 4 files changed, 74 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100755 scripts/tag-and-publish.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 1fbfb92..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Publish -on: - workflow_run: - workflows: [CI] - branches: [main] - types: [completed] - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -permissions: - contents: write - pull-requests: write - -jobs: - publish: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 10 - - uses: actions/setup-node@v4 - with: - node-version: 18.x - cache: "pnpm" - - name: Get package version - id: package-version - run: | - VERSION=$(node -p "require('./package.json').version") - echo "VERSION=$VERSION" >> $GITHUB_OUTPUT - - run: pnpm install --frozen-lockfile - - name: Create Release Pull Request or Publish - id: changesets - uses: changesets/action@v1 - with: - publish: pnpm run release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Send Discord notification - if: steps.changesets.outputs.published == 'true' - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Get release URL using gh cli - RELEASE_URL=$(gh release view "${{ steps.package-version.outputs.VERSION }}" --json url -q .url) - - # Create a JSON file with the message - cat > discord_payload.json << EOF - { - "content": "šŸŽ‰ New release ${{ steps.package-version.outputs.VERSION }} is now available!\n\nšŸ“ Changes:\n${{ steps.release-notes.outputs.NOTES }}\n\nšŸ”— Release: $RELEASE_URL" - } - EOF - - # Send to Discord using curl - curl -H "Content-Type: application/json" \ - -d @discord_payload.json \ - $DISCORD_WEBHOOK \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..010fccc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Publish +on: + push: + branches: + - main + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +permissions: + contents: write + pull-requests: write + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 10 + - uses: actions/setup-node@v4 + with: + node-version: 18.x + cache: "pnpm" + - name: Get package version + id: package-version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + - run: pnpm install --frozen-lockfile + - name: Create Release Pull Request or Publish + id: changesets + uses: changesets/action@v1 + with: + publish: pnpm run ci:publish + version: pnpm run ci:version + title: "Release: $VERSION" + commit: "release: Release $VERSION" + createGithubReleases: false # this is handled inside ci:publish script + setupGitUser: false # this is handled inside ci:publish script + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index 03ce4e3..54a81ee 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,9 @@ "docs:dev": "vitepress dev docs", "docs:build": "vitepress build docs", "docs:preview": "vitepress preview docs", - "test": "jest" + "test": "jest", + "ci:publish": "./scripts/tag-and-publish.sh", + "ci:version": "pnpm run version && changeset version" }, "keywords": [ "Obsidian", diff --git a/scripts/tag-and-publish.sh b/scripts/tag-and-publish.sh new file mode 100755 index 0000000..649f743 --- /dev/null +++ b/scripts/tag-and-publish.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Get Release Notes +version="${{ steps.package-version.outputs.VERSION }}" + +awk -v version="$version" ' +BEGIN { found=0; content="" } +/^# [0-9]+\.[0-9]+\.[0-9]+/ { + if (found) { exit } + if ($2 ~ "^"version"($| \\()") { found=1; next } +} +found { content = content $0 "\n" } +END { printf "%s", content } +' CHANGELOG.md > release_notes.txt + +cat release_notes.txt >> $NOTES + +# Create and push tag +git config user.name "GitHub Actions" +git config user.email "actions@github.com" +git tag -a "${{version}}" -m "Release version ${{version}}" +git push origin "${{version}}" + +# Create release +gh release create "${{version}}" \ +--title="${{version}}" \ +--notes="${{ NOTES }}" \ +main.js manifest.json styles.css \ No newline at end of file