Gradle Publish [snapshot] #7
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: Gradle Publish [snapshot] | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 15 * * 5" # friday 15:00 UTC | |
| jobs: | |
| check-branch: | |
| name: Check Branch | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check Branch | |
| if: startsWith(github.ref, 'refs/heads/') | |
| run: | | |
| BRANCH="${GITHUB_REF#refs/heads/}" | |
| if [[ "$BRANCH" != "main" && "$BRANCH" != "dev" && "$BRANCH" != dev-* && "$BRANCH" != release-* ]]; then | |
| echo "::error title=wrong branch selected::this workflow must be run on 'main', 'dev', 'dev-*' or 'release-*' branches" | |
| exit 1 | |
| fi | |
| check-updates: | |
| name: Check Updates | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_run: ${{ steps.check.outputs.should_run }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Check if SNAPSHOT publish is applicable | |
| id: check | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "::notice::publish will always execute on manual trigger" | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| else | |
| if git log --since="7 days ago" --oneline | grep .; then | |
| echo "::notice::commits found within last 7 days window, publish will execute" | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "::notice::no commits found within last 7 days window, publish will abort" | |
| echo "should_run=false" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| publish-snapshot: | |
| name: Publish problem4j-core SNAPSHOT | |
| needs: [check-branch, check-updates] | |
| if: needs.check-updates.outputs.should_run == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v5 | |
| - name: Evaluate Version | |
| id: version | |
| env: | |
| VERSION_FILE: .github/utils/next_version.txt | |
| run: | | |
| if [ -n "${VERSION_FILE:-}" ] && [ -f "$VERSION_FILE" ]; then | |
| bash .github/utils/validate_version_file.sh "$VERSION_FILE" | |
| NEXT_VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]') # trim whitespaces | |
| echo "::notice::using version from $VERSION_FILE: $NEXT_VERSION" | |
| else | |
| echo "::error::file $VERSION_FILE not found" | |
| exit 1 | |
| fi | |
| NEXT_VERSION="${NEXT_VERSION#v}" # strip leading 'v' if present | |
| SNAPSHOT_VERSION="${NEXT_VERSION}-SNAPSHOT" | |
| echo "::notice::evaluated snapshot version: $SNAPSHOT_VERSION" | |
| echo "version=$SNAPSHOT_VERSION" >> $GITHUB_OUTPUT | |
| - name: Publish Snapshot | |
| env: | |
| SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | |
| SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | |
| PUBLISHING_USERNAME: ${{ secrets.PUBLISHING_USERNAME }} | |
| PUBLISHING_PASSWORD: ${{ secrets.PUBLISHING_PASSWORD }} | |
| GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false" | |
| run: | | |
| ./gradlew -Pversion="${{ steps.version.outputs.version }}" publishAllPublicationsToCentralPortalSnapshots |