1- name : build
1+ name : CI/CD
2+
23on :
34 push :
4- branches : [ "master" ]
5+ branches :
6+ - master
57 pull_request :
6- branches : [ "master" ]
8+ branches :
9+ - master
10+ workflow_dispatch :
11+ inputs :
12+ is-a-release :
13+ description : Publish release? (Only works on master, and for untagged versions)
14+ type : boolean
15+
16+ permissions :
17+ contents : write
18+ issues : write
19+ checks : write
20+ pull-requests : write
21+
722jobs :
8- build :
23+ test :
24+ name : Run test suite
25+ if : inputs.is-a-release == false
26+ strategy :
27+ fail-fast : false
28+ matrix :
29+ os : [ ubuntu-latest ]
30+ java-version : [ 11 ]
931 runs-on : ubuntu-latest
10- permissions :
11- contents : read
32+ timeout-minutes : 35
1233 steps :
13- - uses : actions/checkout@v3
14- - name : Set up JDK 11
34+ - name : Checkout
35+ uses : actions/checkout@v3
36+ - name : Setup JDK
1537 uses : actions/setup-java@v3
1638 with :
17- java-version : ' 11'
18- distribution : ' temurin'
39+ distribution : temurin
40+ java-version : ${{ matrix.java-version }}
41+ check-latest : true
1942 - name : Install Rust toolchain
2043 uses : actions-rs/toolchain@v1
2144 with :
@@ -41,4 +64,130 @@ jobs:
4164 with :
4265 arguments : test
4366 env :
44- CSJ_FULL_BUILD : 1
67+ CSJ_FULL_BUILD : 1
68+ - name : Upload test results
69+ if : always()
70+ uses : actions/upload-artifact@v3
71+ with :
72+ name : Test artifacts
73+ retention-days : 21
74+ path : |
75+ **/TEST-*
76+ **/hs_err_pid*
77+
78+ # Publishes the test results of 'test'
79+ publish-test-results :
80+ name : Publish tests results
81+ if : inputs.is-a-release == false
82+ needs : test
83+ runs-on : ubuntu-latest
84+ steps :
85+ - name : Download artifacts
86+ uses : actions/download-artifact@v3
87+ with :
88+ path : artifacts
89+ - name : Publish test results
90+ uses : EnricoMi/publish-unit-test-result-action@v2
91+ with :
92+ check_name : Unit Test results
93+ files : artifacts/unit-test-*/**/*.xml
94+
95+ # Builds the projects and attempts to publish a release if the current project version
96+ # does not match any existing tags in the repository.
97+ build-and-release :
98+ name : Publish release
99+ if : inputs.is-a-release && github.repository == 'native4j/capstone-java' && github.ref == 'refs/heads/master'
100+ strategy :
101+ fail-fast : true
102+ runs-on : ubuntu-latest
103+ timeout-minutes : 35
104+ steps :
105+ - name : Checkout
106+ uses : actions/checkout@v3
107+ with :
108+ fetch-depth : 0 # Required depth for JReleaser
109+ - name : Setup Java JDK
110+ uses : actions/setup-java@v3
111+ with :
112+ distribution : temurin
113+ java-version : 11
114+ - name : Install Rust toolchain
115+ uses : actions-rs/toolchain@v1
116+ with :
117+ toolchain : stable
118+ - name : Cache osxcross toolchain
119+ uses : actions/cache@v3
120+ with :
121+ path : |
122+ ./osxcross/target/
123+ key : ${{ runner.os }}-osxcross-${{ hashFiles('ci-setup.sh') }}
124+ - name : Validate Gradle wrapper
125+ uses : gradle/wrapper-validation-action@v1
126+ - name : Make gradlew executable
127+ run : chmod +x ./gradlew
128+ - name : Download Gradle wrapper
129+ run : ./gradlew --version
130+ - name : Extract project version to environment variable
131+ run : echo "PROJECT_VERSION=$(./gradlew properties | grep -Po '(?<=version\W ).*')" >> $GITHUB_ENV
132+ # Check if a tag exists that matches the current project version.
133+ # Write the existence state to the step output 'tagExists'.
134+ - name : Check the package version has corresponding Git tag
135+ id : tagged
136+ shell : bash
137+ run : |
138+ git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "tagExists=1" >> $GITHUB_OUTPUT || echo "tagExists=0" >> $GITHUB_OUTPUT
139+ git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "Tag for current version exists" || echo "Tag for current version does not exist"
140+ # If the tag could not be fetched, show a message and abort the job.
141+ # The wonky if logic is a workaround for: https://github.com/actions/runner/issues/1173
142+ - name : Abort if tag exists, or existence check fails
143+ if : ${{ false && steps.tagged.outputs.tagExists }}
144+ run : |
145+ echo "Output of 'tagged' step: ${{ steps.tagged.outputs.tagExists }}"
146+ echo "Failed to check if tag exists."
147+ echo "PROJECT_VERSION: ${{ env.PROJECT_VERSION }}"
148+ echo "Tags $(git tag | wc -l):"
149+ git tag
150+ git show-ref --tags --verify -- "refs/tags/${{ env.PROJECT_VERSION }}"
151+ exit 1
152+ # Run build to generate the release artifacts.
153+ # Tag does not exist AND trigger was manual. Deploy release artifacts!
154+ - name : Make CI script executable
155+ run : chmod +x ./ci-setup.sh
156+ - name : Execute CI script
157+ run : ./ci-setup.sh
158+ - name : Add osxcross to PATH
159+ run : echo "$(pwd)/osxcross/target/bin" >> $GITHUB_PATH
160+ - name : Test with Gradle
161+ uses : gradle/gradle-build-action@v2
162+ with :
163+ arguments : test
164+ env :
165+ CSJ_FULL_BUILD : 1
166+ - name : Publish with Gradle
167+ uses : gradle/gradle-build-action@v2
168+ with :
169+ arguments : publish
170+ env :
171+ CSJ_FULL_BUILD : 1
172+ # Make release with JReleaser, only running when the project version does not exist as a tag on the repository.
173+ - name : Publish release
174+ uses : jreleaser/release-action@v2
175+ with :
176+ arguments : full-release
177+ env :
178+ JRELEASER_PROJECT_VERSION : ${{ env.PROJECT_VERSION }}
179+ JRELEASER_GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180+ JRELEASER_GPG_PUBLIC_KEY : ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
181+ JRELEASER_GPG_SECRET_KEY : ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
182+ JRELEASER_GPG_PASSPHRASE : ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
183+ JRELEASER_NEXUS2_USERNAME : ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_USERNAME }}
184+ JRELEASER_NEXUS2_PASSWORD : ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_PASSWORD }}
185+ # Upload JRelease debug log
186+ - name : JReleaser output
187+ uses : actions/upload-artifact@v3
188+ if : always()
189+ with :
190+ name : jreleaser-release
191+ path : |
192+ out/jreleaser/trace.log
193+ out/jreleaser/output.properties
0 commit comments