|
| 1 | +name: API Compatibility & Version Bump |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + api-check: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout PR |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 # required to compare API changes |
| 20 | + |
| 21 | + - name: Set up JDK |
| 22 | + uses: actions/setup-java@v4 |
| 23 | + with: |
| 24 | + distribution: temurin |
| 25 | + java-version: 17 |
| 26 | + |
| 27 | + - name: Run Kotlin apiDump |
| 28 | + run: ./gradlew apiDump |
| 29 | + |
| 30 | + - name: Detect API changes |
| 31 | + id: changes |
| 32 | + run: | |
| 33 | + if git diff --quiet --exit-code '**/*.api'; then |
| 34 | + echo "api_changed=false" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "api_changed=true" >> $GITHUB_OUTPUT |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Bump version in gradle.properties |
| 40 | + run: | |
| 41 | + version_file=gradle.properties |
| 42 | + version_line=$(grep '^version=' $version_file) |
| 43 | + current_version="${version_line#version=}" |
| 44 | +
|
| 45 | + # Split version like 1.21.4-2.13.3 |
| 46 | + IFS='.-' read -r major minor patch lib_major lib_minor lib_patch <<<"$current_version" |
| 47 | +
|
| 48 | + if [[ "${{ steps.changes.outputs.api_changed }}" == "true" ]]; then |
| 49 | + lib_minor=$((lib_minor + 1)) |
| 50 | + lib_patch=0 |
| 51 | + else |
| 52 | + lib_patch=$((lib_patch + 1)) |
| 53 | + fi |
| 54 | +
|
| 55 | + new_version="$major.$minor.$patch-$lib_major.$lib_minor.$lib_patch" |
| 56 | + echo "New version: $new_version" |
| 57 | + sed -i "s/^version=.*/version=$new_version/" $version_file |
| 58 | +
|
| 59 | + - name: Commit and push changes |
| 60 | + run: | |
| 61 | + if git diff --quiet; then |
| 62 | + echo "No changes to commit." |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | +
|
| 66 | + git config user.name "github-actions[bot]" |
| 67 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 68 | +
|
| 69 | + git add gradle.properties '**/*.api' |
| 70 | + git commit -m "chore: update apiDump and bump version [skip ci]" |
| 71 | + git push |
0 commit comments