Skip to content

Publish to JetBrains Marketplace #61

Publish to JetBrains Marketplace

Publish to JetBrains Marketplace #61

name: Publish to JetBrains Marketplace
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 1.1.0) - leave empty for automatic nightly build'
required: false
type: string
channel:
description: 'Marketplace channel (stable, nightly) - leave empty for automatic detection'
required: false
type: string
release:
types: [created, published]
schedule:
# Run every day at 2 AM UTC to publish nightly builds
- cron: '0 2 * * *'
jobs:
publish-marketplace:
runs-on: ubuntu-latest
if: github.repository == 'redhat-developer/intellij-dependency-analytics'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Validate required secrets
env:
JETBRAINS_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -z "$JETBRAINS_TOKEN" ]; then
echo "Error: JETBRAINS_MARKETPLACE_TOKEN secret is not set"
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN secret is not set"
exit 1
fi
echo "✅ Required secrets are available"
- name: Check for changes since last nightly
if: github.event_name == 'schedule'
id: changes_check
run: |
# Get the date from yesterday
YESTERDAY=$(date -d 'yesterday' +%Y-%m-%d)
echo "Checking for changes since: $YESTERDAY"
# Get the last nightly build commit hash (you might want to store this in a file or use a tag)
# For now, we'll check if there are any commits in the last 24 hours
COMMIT_COUNT=$(git log --since="$YESTERDAY" --oneline | wc -l)
if [ "$COMMIT_COUNT" -gt 0 ]; then
echo "✅ Found $COMMIT_COUNT commits since $YESTERDAY - proceeding with nightly build"
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "ℹ️ No commits since $YESTERDAY - skipping nightly build"
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Determine version and channel
id: version_info
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# Manual trigger - check if inputs are provided
if [ "${{ github.event.inputs.version }}" != "" ] && [ "${{ github.event.inputs.channel }}" != "" ]; then
# Manual trigger with specific inputs
VERSION="${{ github.event.inputs.version }}"
CHANNEL="${{ github.event.inputs.channel }}"
else
# Manual trigger without inputs - treat as nightly build
BASE_VERSION=$(grep 'projectVersion=' gradle.properties | cut -d'=' -f2)
DATE=$(date +%Y%m%d)
VERSION="${BASE_VERSION/-SNAPSHOT/-nightly.${DATE}}"
CHANNEL="nightly"
fi
elif [ "${{ github.event_name }}" == "release" ]; then
# Release event - publish to stable channel
VERSION="${GITHUB_REF#refs/tags/}"
CHANNEL="stable"
elif [ "${{ github.event_name }}" == "schedule" ]; then
# Scheduled run - check if we should publish nightly
if [ "${{ steps.changes_check.outputs.has_changes }}" == "true" ]; then
# Get current version from gradle.properties and append date (like 1.1.0-nightly.20240901)
BASE_VERSION=$(grep 'projectVersion=' gradle.properties | cut -d'=' -f2)
DATE=$(date +%Y%m%d)
VERSION="${BASE_VERSION/-SNAPSHOT/-nightly.${DATE}}"
CHANNEL="nightly"
else
# No changes, set dummy values (workflow will exit early)
VERSION="no-changes"
CHANNEL="none"
fi
else
echo "Unknown trigger: ${{ github.event_name }}"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "CHANNEL=$CHANNEL" >> $GITHUB_OUTPUT
echo "Publishing version $VERSION to $CHANNEL channel"
- name: Build nightly version
if: (github.event_name == 'schedule' && steps.changes_check.outputs.has_changes == 'true') || github.event_name == 'workflow_dispatch'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Building nightly version from source..."
if ! ./gradlew buildPlugin -Pgpr.username=rhdevelopers-ci -Pgpr.token="$GITHUB_TOKEN" -PprojectVersion=${{ steps.version_info.outputs.VERSION }}; then
echo "Error: Gradle build failed"
exit 1
fi
echo "✅ Build completed successfully"
- name: Skip nightly build
if: github.event_name == 'schedule' && steps.changes_check.outputs.has_changes == 'false'
run: |
echo "ℹ️ Skipping nightly build - no changes detected since yesterday"
echo "This is expected behavior to avoid unnecessary builds"
- name: Download from release
if: github.event_name == 'release'
run: |
# Download the ZIP file from the GitHub release
RELEASE_VERSION="${{ steps.version_info.outputs.VERSION }}"
ZIP_URL="https://github.com/${{ github.repository }}/releases/download/${RELEASE_VERSION}/Dependency-Analytics-${RELEASE_VERSION}.zip"
echo "Downloading from: $ZIP_URL"
mkdir -p build/distributions
if ! curl -L -f -o "build/distributions/intellij-dependency-analytics-${RELEASE_VERSION}.zip" "$ZIP_URL"; then
echo "Error: Failed to download ZIP file from release"
echo "URL: $ZIP_URL"
exit 1
fi
echo "✅ Downloaded ZIP file successfully"
- name: Verify ZIP file exists
if: steps.version_info.outputs.CHANNEL != 'none'
run: |
ls -la build/distributions/
ZIP_FILE="build/distributions/intellij-dependency-analytics-${{ steps.version_info.outputs.VERSION }}.zip"
if [ ! -f "$ZIP_FILE" ]; then
echo "Error: ZIP file not found: $ZIP_FILE"
echo "Available files:"
ls -la build/distributions/ || echo "No files found in build/distributions/"
exit 1
fi
# Verify the ZIP file is not empty and is a valid ZIP
if [ ! -s "$ZIP_FILE" ]; then
echo "Error: ZIP file is empty: $ZIP_FILE"
exit 1
fi
if ! file "$ZIP_FILE" | grep -q "Zip archive"; then
echo "Error: File is not a valid ZIP archive: $ZIP_FILE"
file "$ZIP_FILE"
exit 1
fi
echo "✅ ZIP file verified: $ZIP_FILE"
- name: Publish to JetBrains Marketplace
if: steps.version_info.outputs.CHANNEL != 'none'
run: >
./gradlew publishPlugin
-PjetBrainsToken=${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
-PprojectVersion=${{ steps.version_info.outputs.VERSION }}
-PjetBrainsChannel=${{ steps.version_info.outputs.CHANNEL }}
-Pgpr.username=rhdevelopers-ci
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
- name: Publish success notification
if: success()
run: |
echo "✅ Successfully published version ${{ steps.version_info.outputs.VERSION }} to ${{ steps.version_info.outputs.CHANNEL }} channel"
echo "📦 ZIP file: build/distributions/intellij-dependency-analytics-${{ steps.version_info.outputs.VERSION }}.zip"