Skip to content

Commit 3c77a04

Browse files
authored
Modify CI/CD pipeline to create a separate publish task for each changed module (#195)
1 parent 029d323 commit 3c77a04

2 files changed

Lines changed: 65 additions & 16 deletions

File tree

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,68 @@
11
name: Publish package to GitHub Packages
2-
on: workflow_dispatch
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
run_all:
6+
description: "Publish all subprojects"
7+
required: true
8+
default: "false"
9+
run_specific:
10+
description: "Publish specific subproject"
11+
required: false
12+
default: ""
13+
push:
14+
branches: [ "master" ]
315
jobs:
16+
detect-changes:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.set-matrix.outputs.matrix }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Detect changed subprojects
23+
id: changes
24+
run: |
25+
# get all projects
26+
CHANGED=$(./gradlew projects --quiet | grep "Project " | awk '{print $3}' | sed "s/'\|://g")
27+
28+
#handle if project is specified
29+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
30+
if [ "${{ inputs.run_all }}" = "false" ]; then
31+
CHANGED=${{ inputs.run_specific }}
32+
fi
33+
else #merge to master, detect specific changes
34+
CHANGED=$(grep -F -o -f <(echo "$CHANGED") <(git diff --name-only HEAD~ HEAD))
35+
fi
36+
37+
CHANGED=$(echo -n "$CHANGED" | base64 -w 0)
38+
39+
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
40+
- name: Build matrix
41+
id: set-matrix
42+
run: |
43+
ENCODED=${{ steps.changes.outputs.changed }}
44+
CHANGED=$(echo -n "$ENCODED" | base64 --decode)
45+
ARR=$(echo "$CHANGED" | jq -R -s -c 'split("\n")[:-1]')
46+
echo "matrix={\"project\":$ARR}" >> $GITHUB_OUTPUT
47+
448
publish:
49+
needs: detect-changes
550
runs-on: ubuntu-latest
6-
permissions:
7-
contents: read
8-
packages: write
51+
strategy:
52+
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
53+
fail-fast: false
954
steps:
10-
- name: Checkout
11-
uses: actions/checkout@v3
55+
- uses: actions/checkout@v4
1256
with:
13-
fetch-depth: 0
1457
submodules: recursive
15-
- uses: actions/setup-java@v4
16-
with:
17-
java-version: '17'
18-
distribution: 'temurin'
19-
- name: Setup Gradle
20-
uses: gradle/actions/setup-gradle@017a9effdb900e5b5b2fddfb590a105619dca3c3 # v4.4.2
21-
22-
- name: Publish package
23-
run: ./gradlew publish --continue #don't block progress for other packages
58+
- name: Publish project
59+
run: |
60+
echo "Publishing ${{ matrix.project }}"
61+
VERSION=$(./gradlew --quiet :${{ matrix.project }}:printVersion)
62+
if [ "${{ github.event_name }}" = "push" ]; then
63+
VERSION="${VERSION}-SNAPSHOT"
64+
fi
65+
./gradlew :${{ matrix.project }}:build -Pversion="$VERSION" -x test
66+
./gradlew :${{ matrix.project }}:publish -Pversion="$VERSION"
2467
env:
2568
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ subprojects {
2323
testImplementation "junit:junit:4.13.1"
2424
}
2525

26+
task printVersion {
27+
doLast {
28+
print project.version
29+
}
30+
}
31+
2632
sourceCompatibility = 17
2733
targetCompatibility = 17
2834

0 commit comments

Comments
 (0)