Release #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g., 1.2.0)' | |
| required: true | |
| type: string | |
| publish_to_marketplace: | |
| description: 'Publish to JetBrains Marketplace' | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| validate-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.extract-version.outputs.version }} | |
| is_prerelease: ${{ steps.extract-version.outputs.is_prerelease }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract version | |
| id: extract-version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION="${{ github.ref_name }}" | |
| VERSION=${VERSION#v} # Remove 'v' prefix if present | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Check if this is a prerelease (contains alpha, beta, rc) | |
| if [[ $VERSION =~ (alpha|beta|rc) ]]; then | |
| echo "is_prerelease=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_prerelease=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Release version: $VERSION" | |
| echo "Is prerelease: $(echo $VERSION | grep -E '(alpha|beta|rc)' && echo 'true' || echo 'false')" | |
| build-and-test: | |
| needs: validate-version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' # Cache Gradle dependencies | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| cache-read-only: false | |
| - name: Update version in gradle.properties | |
| run: | | |
| # Update version directly without Gradle to avoid cache invalidation | |
| sed -i "s/^pluginVersion = .*/pluginVersion = ${{ needs.validate-version.outputs.version }}/" gradle.properties | |
| echo "Updated plugin version to ${{ needs.validate-version.outputs.version }}" | |
| - name: Build, test, and analyze | |
| run: ./gradlew buildPlugin test detekt detektSarif --build-cache | |
| # Note: Plugin Verifier is skipped - JetBrains Marketplace will verify compatibility during publishing | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: plugin-artifact | |
| path: build/distributions/*.zip | |
| retention-days: 30 | |
| create-release: | |
| needs: [validate-version, build-and-test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to create releases | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch full history for changelog generation | |
| - name: Setup Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| cache-read-only: true # Read-only for release job | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: plugin-artifact | |
| path: build/distributions/ | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Extract changes since last tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| CHANGELOG="Initial release" | |
| else | |
| CHANGELOG=$(git log --pretty=format:"- %s" $LAST_TAG..HEAD | head -20) | |
| fi | |
| # Save changelog to file for GitHub release | |
| echo "## What's Changed" > changelog.md | |
| echo "" >> changelog.md | |
| if [ "$CHANGELOG" = "Initial release" ]; then | |
| echo "Initial release of the OpenRouter IntelliJ Plugin" >> changelog.md | |
| else | |
| echo "$CHANGELOG" >> changelog.md | |
| fi | |
| echo "" >> changelog.md | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LAST_TAG}...v${{ needs.validate-version.outputs.version }}" >> changelog.md | |
| # Set output for use in release creation | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| cat changelog.md >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ needs.validate-version.outputs.version }} | |
| name: Release ${{ needs.validate-version.outputs.version }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| prerelease: ${{ needs.validate-version.outputs.is_prerelease }} | |
| files: build/distributions/*.zip | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| publish-to-marketplace: | |
| needs: [validate-version, build-and-test, create-release] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to update releases with marketplace link | |
| if: | | |
| (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_to_marketplace == 'true') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| cache-read-only: true # Read-only for publish job | |
| - name: Update version in gradle.properties | |
| run: | | |
| # Update version directly without Gradle to avoid cache invalidation | |
| sed -i "s/^pluginVersion = .*/pluginVersion = ${{ needs.validate-version.outputs.version }}/" gradle.properties | |
| echo "Updated plugin version to ${{ needs.validate-version.outputs.version }}" | |
| - name: Sign and publish plugin to JetBrains Marketplace | |
| run: ./gradlew signPlugin publishPlugin --build-cache | |
| env: | |
| CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }} | |
| PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
| PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }} | |
| PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} | |
| - name: Update release with marketplace link | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: 'v${{ needs.validate-version.outputs.version }}' | |
| }); | |
| // Update release body to include marketplace link | |
| const marketplaceLink = '\n\n---\n\n🎉 **Plugin Published!**\n\nThe plugin has been successfully published to the JetBrains Marketplace.\n\n📦 [View on Marketplace](https://plugins.jetbrains.com/plugin/org.zhavoronkov.openrouter)'; | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id, | |
| body: release.data.body + marketplaceLink | |
| }); |