15 no code artifact publication (#16) #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: GitFlow CI | |
| permissions: | |
| contents: write | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| - 'release/*' | |
| - 'hotfix/*' | |
| - 'feature/*' | |
| pull_request: | |
| jobs: | |
| gitflow-ci: | |
| runs-on: ubuntu-latest | |
| env: | |
| NEXUS_ACTOR: ${{ secrets.NEXUS_ACTOR }} | |
| NEXUS_TOKEN: ${{ secrets.NEXUS_TOKEN }} | |
| NEXUS_REPO_URL: ${{ vars.NEXUS_REPO_URL }} | |
| NEXUS_REPO_SNAPSHOT: ${{ vars.NEXUS_REPO_SNAPSHOT }} | |
| NEXUS_REPO_RELEASE: ${{ vars.NEXUS_REPO_RELEASE }} | |
| OSH_CORE_VERSION: ${{ vars.OSH_CORE_VERSION }} | |
| # Snapshot flag: develop = snapshot, everything else = release | |
| SNAPSHOT: ${{ github.ref == 'refs/heads/develop' }} | |
| RELEASE: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release/*' || github.ref == 'refs/heads/hotfix/*'}} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Cache Gradle | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| # --------------------------------------------------------- | |
| # Detect changed modules | |
| # --------------------------------------------------------- | |
| - name: Detect changed modules | |
| id: changed | |
| run: | | |
| echo "Detecting changed modules..." | |
| git fetch --unshallow || true | |
| git fetch origin --prune | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| else | |
| BASE_SHA=$(git merge-base HEAD origin/${{ github.ref_name }} || git merge-base HEAD origin/main) | |
| fi | |
| echo "Base SHA: $BASE_SHA" | |
| git diff --name-only $BASE_SHA HEAD > changed.txt | |
| echo "Changed files:" | |
| cat changed.txt | |
| MODULES="" | |
| while read FILE; do | |
| DIR=$(dirname "$FILE") | |
| [ "$DIR" = "." ] && continue | |
| if [ -f "$DIR/build.gradle" ] || [ -f "$DIR/build.gradle.kts" ]; then | |
| MODULES="$MODULES $DIR" | |
| fi | |
| done < changed.txt | |
| echo "modules=$MODULES" >> $GITHUB_OUTPUT | |
| # --------------------------------------------------------- | |
| # Enforce version bumps | |
| # --------------------------------------------------------- | |
| - name: Enforce version bumps | |
| if: steps.changed.outputs.modules != '' | |
| run: | | |
| FAILED=0 | |
| BASE="${{ github.base_ref }}" | |
| # Fallback for push events (base_ref is empty) | |
| if [ -z "$BASE" ]; then | |
| BASE="${{ github.ref_name }}" | |
| fi | |
| for DIR in ${{ steps.changed.outputs.modules }}; do | |
| OLD_VER=$(git show origin/$BASE:$DIR/build.gradle 2>/dev/null \ | |
| | grep -E "version\s*=" \ | |
| | head -1 \ | |
| | sed "s/.*=//; s/[\"']//g; s/ //g") | |
| NEW_VER=$(grep -E "version\s*=" $DIR/build.gradle \ | |
| | head -1 \ | |
| | sed "s/.*=//; s/[\"']//g; s/ //g") | |
| echo "$DIR old=$OLD_VER new=$NEW_VER" | |
| if [ "$OLD_VER" = "$NEW_VER" ]; then | |
| FAILED=1 | |
| fi | |
| done | |
| exit $FAILED | |
| # --------------------------------------------------------- | |
| # Build & Test | |
| # --------------------------------------------------------- | |
| - name: Build & Test | |
| run: ./gradlew clean build --no-daemon -Psnapshot=$SNAPSHOT | |
| # --------------------------------------------------------- | |
| # Publish changed OR missing modules | |
| # --------------------------------------------------------- | |
| - name: Publish | |
| if: env.SNAPSHOT == 'true' || env.RELEASE == 'true' | |
| run: ./gradlew publish -Psnapshot=$SNAPSHOT --no-daemon |