Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.

Commit c8e0795

Browse files
committed
Update CI
1 parent 6efffc5 commit c8e0795

File tree

9 files changed

+315
-93
lines changed

9 files changed

+315
-93
lines changed

.github/workflows/build.yml

Lines changed: 185 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
name: build
1+
name: CI/CD
2+
23
on:
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+
719
jobs:
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

.github/workflows/publish.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

build.gradle

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
def project_version = "dev"
2-
3-
def version_override = System.getenv("CSJ_VERSION")
4-
if (version_override != null) {
5-
// Remove leading "v" if present
6-
if (version_override.startsWith("v"))
7-
version_override = version_override.substring(1)
8-
project_version = version_override.trim()
9-
}
10-
111
allprojects {
122
group = "org.native4j"
13-
version = project_version
3+
version = "0.0.2-SNAPSHOT"
144
}
155

166
subprojects {

ci-setup.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sudo apt install -y build-essential \
77
git \
88
wget \
99
cmake \
10+
clang \
1011
mingw-w64 \
1112
gcc-arm-linux-gnueabihf \
1213
gcc-aarch64-linux-gnu \
@@ -31,7 +32,7 @@ setup_osxcross() {
3132
cd osxcross
3233

3334
# Install osxcross dependencies
34-
./tools/get_dependencies.sh
35+
sudo ./tools/get_dependencies.sh
3536

3637
# Download Big Sur 11.1 SDK
3738
wget -nc https://github.com/joseluisq/macosx-sdks/releases/download/11.1/MacOSX11.1.sdk.tar.xz
@@ -40,6 +41,12 @@ setup_osxcross() {
4041
# Build clang
4142
UNATTENDED=yes OSX_VERSION_MIN=11.1 ./build.sh
4243

44+
# Check if target exists
45+
if [ ! -d "target" ]; then
46+
echo "target directory does not exist"
47+
exit 1
48+
fi
49+
4350
cd ../
4451
}
4552

jreleaser.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
project:
2+
name: capstone-java
3+
description: Capstone bindings for Java.
4+
longDescription: Capstone bindings for Java.
5+
links:
6+
homepage: https://github.com/native4j/capstone-java
7+
authors:
8+
- Justin Phelps
9+
license: MIT
10+
inceptionYear: "2023"
11+
copyright: The Native4J Authors
12+
stereotype: NONE
13+
java:
14+
version: "11"
15+
groupId: org.native4j
16+
artifactId: capstone-java
17+
snapshot:
18+
pattern: .*-SNAPSHOT
19+
label: '{{projectVersion}}'
20+
21+
release:
22+
github:
23+
overwrite: true
24+
tagName: '{{projectVersion}}'
25+
changelog:
26+
formatted: ALWAYS
27+
preset: conventional-commits
28+
contributors:
29+
format: '- {{contributorName}}{{#contributorUsernameAsLink}} ({{.}}){{/contributorUsernameAsLink}}'
30+
31+
distributions:
32+
dist:
33+
type: SINGLE_JAR
34+
artifacts:
35+
- path: native4j-capstone/build/libs/capstone-java-{{projectVersion}}.jar
36+
37+
signing:
38+
active: RELEASE
39+
mode: MEMORY
40+
armored: true
41+
verify: true
42+
artifacts: true
43+
checksums: true
44+
files: false
45+
46+
deploy:
47+
maven:
48+
nexus2:
49+
maven-central:
50+
active: RELEASE
51+
sign: true
52+
url: https://s01.oss.sonatype.org/service/local
53+
snapshotUrl: https://s01.oss.sonatype.org/content/repositories/snapshots/
54+
applyMavenCentralRules: true
55+
stagingRepositories:
56+
- native4j-capstone/build/staging-deploy
57+
closeRepository: false
58+
releaseRepository: false

0 commit comments

Comments
 (0)