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