name: Release on: push: branches: - main tags: # Only trigger for release tags (e.g., v1.0.0, v2.3.4) # Excludes prerelease tags (e.g., v2.8.0-beta.3, v1.0.0-rc.1) - "v[0-9]+.[0-9]+.[0-9]" - "v[0-9]+.[0-9]+.[0-9][0-9]" - "v[0-9]+.[0-9]+.[0-9][0-9][0-9]" - "v[0-9]+.[0-9][0-9].[0-9]" - "v[0-9]+.[0-9][0-9].[0-9][0-9]" - "v[0-9]+.[0-9][0-9].[0-9][0-9][0-9]" env: PLUGIN_NAME: share-to-notionnext # Change this to match the id of your plugin. CHANGELOG_FILENAME: CHANGELOG.md jobs: build: name: release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v3 with: node-version: "18" # - name: Generate changelog # id: changelog # uses: saadmk11/changelog-ci@v1.1.2 # with: # github_token: ${{ secrets.REPO_ACCESS_TOKEN }} # release_version: ${{ github.ref }} # changelog_filename: CHANGELOG.md - name: Build id: build run: | npm install npm run build mkdir ${{ env.PLUGIN_NAME }} cp main.js manifest.json ${{ env.PLUGIN_NAME }} zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }} ls echo "tag_name=$(git tag --sort version:refname | tail -n 1)" >> $GITHUB_OUTPUT - name: Generate release notes if: startsWith(github.ref, 'refs/tags/') run: | node - <<'NODE' const fs = require('fs'); const tag = process.env.GITHUB_REF_NAME; if (!tag) { throw new Error('GITHUB_REF_NAME is not set'); } const changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); const lines = changelog.split(/\r?\n/); const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const headerRe = new RegExp(`^##\\s+${escapeRegex(tag)}\\b`); const start = lines.findIndex((line) => headerRe.test(line)); if (start === -1) { throw new Error(`Could not find changelog section for tag "${tag}"`); } let end = lines.length; for (let i = start + 1; i < lines.length; i++) { if (/^##\s+/.test(lines[i])) { end = i; break; } } let section = lines.slice(start, end); while (section.length > 0 && section[section.length - 1].trim() === '') { section.pop(); } if (section.length > 0 && section[section.length - 1].trim() === '---') { section.pop(); while (section.length > 0 && section[section.length - 1].trim() === '') { section.pop(); } } fs.writeFileSync('release-notes.md', `${section.join('\n')}\n`); NODE - name: Create Release id: create_release if: startsWith(github.ref, 'refs/tags/') uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} VERSION: ${{ github.ref }} with: tag_name: ${{ github.ref_name }} release_name: ${{ github.ref_name }} body_path: release-notes.md draft: false prerelease: false - name: Upload zip file id: upload-zip if: startsWith(github.ref, 'refs/tags/') uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./${{ env.PLUGIN_NAME }}.zip asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip asset_content_type: application/zip - name: Upload main.js id: upload-main if: startsWith(github.ref, 'refs/tags/') uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./main.js asset_name: main.js asset_content_type: text/javascript - name: Upload manifest.json id: upload-manifest if: startsWith(github.ref, 'refs/tags/') uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./manifest.json asset_name: manifest.json asset_content_type: application/json - name: Upload markdown template id: upload-md if: startsWith(github.ref, 'refs/tags/') uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./obsidian_template.md asset_name: template.md asset_content_type: text/markdown # - name: Upload styles.css # id: upload-css # uses: actions/upload-release-asset@v1 # env: # GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} # with: # upload_url: ${{ steps.create_release.outputs.upload_url }} # asset_path: ./styles.css # asset_name: styles.css # asset_content_type: text/css