-
Notifications
You must be signed in to change notification settings - Fork 7
185 lines (151 loc) · 5.55 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Publish artifacts to Sonatype Repo
on:
push:
branches:
- master
- version-[0-9].[0-9]+.x
tags:
- v[0-9].[0-9]+.[0-9]+
pull_request:
env:
NATIVE_DIR: zwaves_jni/javalib/src/main/resources/META-INF/native
GRADLE_EXTRA_ARGS: --console=plain -Ppr=${{ github.event.number }} -Pref=${{ github.ref }}
# GITHUB_CONTEXT: ${{ toJson(github) }} # For debugging purposes
jobs:
build-native:
name: ${{ matrix.platform }}/${{ matrix.arch }} library
runs-on: ${{ matrix.os }}
env:
# Where a library should be
target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }}
# Rust build target
build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }}
# Rust target directory
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
strategy:
matrix:
platform: [ linux, osx, windows ]
arch: [ aarch64, amd64, x86 ]
exclude:
- platform: osx
arch: x86
- platform: windows
arch: aarch64
include:
- platform: linux
os: ubuntu-20.04
build-platform: unknown-linux-gnu
artifact: libzwaves_jni.so
jni-platform: linux64
- platform: linux
arch: aarch64
extra-packages: gcc-aarch64-linux-gnu
- platform: linux
arch: x86
extra-packages: gcc-multilib
jni-platform: linux32
- platform: osx
os: macos-latest
build-platform: apple-darwin
artifact: libzwaves_jni.dylib
jni-platform: osx64
- platform: windows
os: windows-2019
build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume"
artifact: zwaves_jni.dll
jni-platform: windows64
- platform: windows
arch: x86
jni-platform: windows32
- arch: aarch64
build-arch: aarch64
- arch: amd64
build-arch: x86_64
- arch: x86
build-arch: i686
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Print debug information
run: |
echo "Build target: ${{ env.build-target }}"
echo "Target path: ${{ env.target-path }}"
- name: Install build tools
if: ${{ matrix.extra-packages }}
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.extra-packages }}
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ env.build-target }}
- name: Enable Rust dependencies caching
uses: Swatinem/rust-cache@v2
- name: Run Rust tests
# Architecture is always x86-64: https://stackoverflow.com/a/71220337
if: matrix.arch == 'amd64'
run: |
cd zwaves_jni
cargo test --lib --target ${{ env.build-target }}
- name: Build native libraries
run: |
cd zwaves_jni
cargo build --release --target ${{ env.build-target }}
cd ..
cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }}
- name: Upload result
uses: actions/upload-artifact@v3
with:
name: native-libraries
path: ${{ env.NATIVE_DIR }}/**/*
build-jni:
name: Build JNI library
runs-on: ubuntu-20.04
needs: build-native
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 8
distribution: temurin
cache: gradle
- uses: actions/download-artifact@v3
with:
name: native-libraries
path: ${{ env.NATIVE_DIR }}
- name: Print debug information
run: |
cd ./zwaves_jni/javalib
# About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709
VERSION=$(./gradlew -q $GRADLE_EXTRA_ARGS printVersion)
PUBLISHING_TYPE=$(./gradlew -q $GRADLE_EXTRA_ARGS publishingType)
# echo "$GITHUB_CONTEXT" # For debugging purposes
echo "Gradle extra arguments: ${GRADLE_EXTRA_ARGS}"
echo "Building ${VERSION}, publishing type: ${PUBLISHING_TYPE}"
# Make environment variables available in the next step
echo "PUBLISHING_TYPE=${PUBLISHING_TYPE}" >> $GITHUB_ENV
- name: Run tests
run: |
cd zwaves_jni/javalib
./gradlew ${GRADLE_EXTRA_ARGS} test
- name: Publish snapshot version
if: ${{ env.PUBLISHING_TYPE == 'snapshot' }}
run: |
cd zwaves_jni/javalib
./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype \
-PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \
-PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \
-PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \
-PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}'
- name: Publish staging version
if: ${{ env.PUBLISHING_TYPE == 'staging' }}
run: |
cd zwaves_jni/javalib
./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype closeAndReleaseSonatypeStagingRepository \
-PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \
-PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \
-PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \
-PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}'