fix: Update snapshot action to run on MacOS #2
Workflow file for this run
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: Test Publish SNAPSHOT | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - Update-Snapshot-Action | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to test (without -SNAPSHOT suffix). Leave empty to auto-detect from open Release Please PR." | |
| required: false | |
| type: string | |
| jobs: | |
| test-publish-snapshot: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Determine source branch | |
| id: source | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if [ -n "${{ inputs.version }}" ]; then | |
| echo "ref=${{ github.ref }}" >> "$GITHUB_OUTPUT" | |
| echo "version=${{ inputs.version }}-SNAPSHOT" >> "$GITHUB_OUTPUT" | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Using manually provided version: ${{ inputs.version }}-SNAPSHOT" | |
| else | |
| PR_JSON=$(gh pr list --repo "${{ github.repository }}" --label "autorelease: pending" --json headRefName,number --jq '.[0]') | |
| if [ -z "$PR_JSON" ] || [ "$PR_JSON" = "null" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "No open Release Please PR found. Skipping test." | |
| exit 0 | |
| fi | |
| BRANCH=$(echo "$PR_JSON" | jq -r '.headRefName') | |
| PR_NUMBER=$(echo "$PR_JSON" | jq -r '.number') | |
| echo "ref=$BRANCH" >> "$GITHUB_OUTPUT" | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Found Release Please PR #${PR_NUMBER} on branch: $BRANCH" | |
| fi | |
| - uses: actions/checkout@v5 | |
| if: steps.source.outputs.skip != 'true' | |
| with: | |
| ref: ${{ steps.source.outputs.ref }} | |
| - name: Extract version from build.gradle.kts | |
| if: ${{ steps.source.outputs.skip != 'true' && !inputs.version }} | |
| id: extracted | |
| run: | | |
| VERSION=$(grep 'ext\["version"\]' build.gradle.kts | sed 's/.*"\(.*\)"/\1/') | |
| echo "version=${VERSION}-SNAPSHOT" >> "$GITHUB_OUTPUT" | |
| echo "Detected version from Release Please branch: ${VERSION}-SNAPSHOT" | |
| - name: Set final version | |
| if: steps.source.outputs.skip != 'true' | |
| id: final | |
| run: | | |
| VERSION="${{ steps.source.outputs.version || steps.extracted.outputs.version }}" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Publishing SNAPSHOT version: $VERSION" | |
| - name: Override version in build.gradle.kts | |
| if: steps.source.outputs.skip != 'true' | |
| run: | | |
| sed -i '' 's/ext\["version"\] = "[^"]*"/ext["version"] = "${{ steps.final.outputs.version }}"/' build.gradle.kts | |
| echo "Updated build.gradle.kts:" | |
| grep 'ext\["version"\]' build.gradle.kts | |
| - name: Setup Gradle | |
| if: steps.source.outputs.skip != 'true' | |
| uses: gradle/actions/setup-gradle@v5 | |
| - name: Set up JDK 17 | |
| if: steps.source.outputs.skip != 'true' | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: 17 | |
| distribution: "zulu" | |
| - name: Grant Permission for Gradlew to Execute | |
| if: steps.source.outputs.skip != 'true' | |
| run: chmod +x gradlew | |
| - name: Test Build | |
| if: steps.source.outputs.skip != 'true' | |
| run: ./gradlew assemble publishToMavenLocal --no-daemon --stacktrace | |
| - name: Verify Published Variants | |
| if: steps.source.outputs.skip != 'true' | |
| run: | | |
| VERSION="${{ steps.final.outputs.version }}" | |
| REPO_DIR="$HOME/.m2/repository/dev/openfeature" | |
| echo "Checking for published artifacts in Maven Local..." | |
| # List of expected variant directories | |
| VARIANTS=( | |
| "kotlin-sdk" | |
| "kotlin-sdk-android" | |
| "kotlin-sdk-jvm" | |
| "kotlin-sdk-js" | |
| "kotlin-sdk-linuxx64" | |
| "kotlin-sdk-iosarm64" | |
| "kotlin-sdk-iossimulatorarm64" | |
| ) | |
| MISSING=0 | |
| for VARIANT in "${VARIANTS[@]}"; do | |
| POM_FILE="$REPO_DIR/$VARIANT/$VERSION/$VARIANT-$VERSION.pom" | |
| if [ -f "$POM_FILE" ]; then | |
| echo "✅ Found $VARIANT" | |
| else | |
| echo "❌ Missing $VARIANT ($POM_FILE not found)" | |
| MISSING=1 | |
| fi | |
| done | |
| if [ $MISSING -eq 1 ]; then | |
| echo "Error: One or more variants failed to publish to Maven Local." | |
| exit 1 | |
| else | |
| echo "Success: All expected variants were published correctly." | |
| fi |