From b0b1e4ac91e02143ec8d0ecfdc6a9bce8dcee770 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 4 Sep 2025 13:47:22 +0800 Subject: [PATCH 1/4] fix: step "Check for changes since last nightly" needs to run before "Determine version and channel" --- .github/workflows/publish-marketplace.yml | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/publish-marketplace.yml b/.github/workflows/publish-marketplace.yml index f1cc4054..d42716bd 100644 --- a/.github/workflows/publish-marketplace.yml +++ b/.github/workflows/publish-marketplace.yml @@ -33,6 +33,26 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew + - 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: | @@ -74,26 +94,6 @@ jobs: echo "CHANNEL=$CHANNEL" >> $GITHUB_OUTPUT echo "Publishing version $VERSION to $CHANNEL channel" - - 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: Build nightly version if: (github.event_name == 'schedule' && steps.changes_check.outputs.has_changes == 'true') || github.event_name == 'workflow_dispatch' run: | From 66b71f246579c1d32101cc9be2a33b97516bb6f2 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 4 Sep 2025 13:58:52 +0800 Subject: [PATCH 2/4] chore: add some validations and logging information --- .github/workflows/publish-marketplace.yml | 53 ++++++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-marketplace.yml b/.github/workflows/publish-marketplace.yml index d42716bd..ee14e973 100644 --- a/.github/workflows/publish-marketplace.yml +++ b/.github/workflows/publish-marketplace.yml @@ -33,6 +33,21 @@ jobs: - 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 @@ -98,7 +113,11 @@ jobs: if: (github.event_name == 'schedule' && steps.changes_check.outputs.has_changes == 'true') || github.event_name == 'workflow_dispatch' run: | echo "Building nightly version from source..." - ./gradlew buildPlugin -Pgpr.username=rhdevelopers-ci -Pgpr.token=${{ secrets.GITHUB_TOKEN }} -PprojectVersion=${{ steps.version_info.outputs.VERSION }} + if ! ./gradlew buildPlugin -Pgpr.username=rhdevelopers-ci -Pgpr.token=${{ secrets.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' @@ -114,17 +133,39 @@ jobs: 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 - curl -L -o "build/distributions/intellij-dependency-analytics-${RELEASE_VERSION}.zip" "$ZIP_URL" + + 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 run: | ls -la build/distributions/ - # For stable releases, expect the exact filename - if [ ! -f "build/distributions/intellij-dependency-analytics-${{ steps.version_info.outputs.VERSION }}.zip" ]; then - echo "Error: ZIP file not found!" + 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 - echo "✅ ZIP file verified: build/distributions/intellij-dependency-analytics-${{ steps.version_info.outputs.VERSION }}.zip" + + 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' From 33b3591f57009cfda3c4e527e4df00c0492290ab Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 4 Sep 2025 14:22:53 +0800 Subject: [PATCH 3/4] fix: avoid Avoid expanding secrets in a run block check failure in SonarCloud Code Analysis --- .github/workflows/publish-marketplace.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-marketplace.yml b/.github/workflows/publish-marketplace.yml index ee14e973..9f87ba34 100644 --- a/.github/workflows/publish-marketplace.yml +++ b/.github/workflows/publish-marketplace.yml @@ -111,9 +111,11 @@ jobs: - 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=${{ secrets.GITHUB_TOKEN }} -PprojectVersion=${{ steps.version_info.outputs.VERSION }}; then + 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 From 32809262d0f4158fcc69010eb3c3a4d7c2f8993a Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 4 Sep 2025 16:06:12 +0800 Subject: [PATCH 4/4] fix: make the action only runs on the redhat-developer/intellij-dependency-analytics repository --- .github/workflows/publish-marketplace.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-marketplace.yml b/.github/workflows/publish-marketplace.yml index 9f87ba34..ea58c1a7 100644 --- a/.github/workflows/publish-marketplace.yml +++ b/.github/workflows/publish-marketplace.yml @@ -19,6 +19,7 @@ on: jobs: publish-marketplace: runs-on: ubuntu-latest + if: github.repository == 'redhat-developer/intellij-dependency-analytics' steps: - name: Checkout repository uses: actions/checkout@v4