Skip to content

Commit 777aef2

Browse files
Update signjars.yml
1 parent 729c4eb commit 777aef2

File tree

1 file changed

+60
-26
lines changed

1 file changed

+60
-26
lines changed

.github/workflows/signjars.yml

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Java CI with Maven
1+
name: Sign jars and internal native libraries
22

33
on:
44
push:
@@ -8,49 +8,83 @@ on:
88

99
jobs:
1010
build:
11-
1211
runs-on: macos-latest
1312

1413
steps:
15-
- uses: actions/checkout@v3
16-
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
1717
- name: Set up JDK 17
1818
uses: actions/setup-java@v3
1919
with:
2020
java-version: '17'
2121
distribution: 'temurin'
2222

23-
- name: Sign JARs
23+
- name: Codesign JARs and Internal Native Libraries
24+
env:
25+
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
26+
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
2427
run: |
25-
# Export secrets as environment variables
26-
export JARSIGNER_KEYSTORE_B64=${{ secrets.JARSIGNER_REL_KEYSTORE_B64 }}
27-
export JARSIGNER_STOREPASS=${{ secrets.JARSIGNER_REL_STOREPASS }}
28-
export JARSIGNER_ALIAS=${{ secrets.JARSIGNER_REL_ALIAS }}
29-
30-
# Set up the keystore file path
31-
KEYSTORE_FILE="${PWD}/{{secrets.JARSIGNER_KEYSTORE}}"
32-
echo "Keystore file: ${KEYSTORE_FILE}"
33-
34-
# Decode and save the base64-encoded keystore to the file
35-
printf "%s" "${JARSIGNER_KEYSTORE_B64}" | base64 -d > "${KEYSTORE_FILE}"
28+
# Step 1: Decode and import the certificate into a keychain
29+
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
30+
/usr/bin/security create-keychain -p espressif build.keychain
31+
/usr/bin/security default-keychain -s build.keychain
32+
/usr/bin/security unlock-keychain -p espressif build.keychain
33+
/usr/bin/security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PWD -T /usr/bin/codesign
34+
/usr/bin/security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k espressif build.keychain
3635
37-
# Sign all JAR files located in the specified directory
36+
# Step 2: Define the directory containing the JARs and native libraries and the temp directory for signed JARs
3837
LIB_DIR="${PWD}/BUNDLES/com.espressif.idf.serial.monitor/lib"
39-
echo "Signing JAR files in ${LIB_DIR}"
38+
SIGNED_JARS_DIR="${RUNNER_TEMP}/signed-jars" # Use GitHub's RUNNER_TEMP for storing signed JARs
39+
mkdir -p "$SIGNED_JARS_DIR"
40+
41+
# Step 3: Extract, sign native libraries, repackage, and sign the JARs with Apple codesign
4042
for jar in "${LIB_DIR}"/*.jar; do
41-
echo "Signing JAR file: ${jar}"
42-
jarsigner -keystore "${KEYSTORE_FILE}" \
43-
-storepass "${JARSIGNER_STOREPASS}" \
44-
-signedjar "${jar}" \
45-
"${jar}" "${JARSIGNER_ALIAS}"
43+
echo "Processing JAR file: ${jar}"
44+
45+
# Check if the JAR exists
46+
if [ -f "$jar" ]; then
47+
echo "JAR file found: ${jar}"
48+
else
49+
echo "JAR file not found: ${jar}"
50+
continue
51+
fi
52+
53+
# Create a temporary directory to extract the JAR contents
54+
TEMP_DIR=$(mktemp -d)
55+
unzip -q "$jar" -d "$TEMP_DIR"
56+
57+
# Find and sign all .jnilib and .dylib files in the extracted JAR directory
58+
find "$TEMP_DIR" -name "*.jnilib" -o -name "*.dylib" | while read lib; do
59+
echo "Signing native library: ${lib}"
60+
/usr/bin/codesign -vvvv --entitlements $PWD/releng/com.espressif.idf.product/entitlements/espressif-ide.entitlement --options runtime --force -s "ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD. (QWXF6GB4AV)" --timestamp --deep "$lib"
61+
done
62+
63+
# Repackage the signed JAR
64+
pushd "$TEMP_DIR"
65+
zip -r "${SIGNED_JARS_DIR}/$(basename "$jar")" * # Save signed JAR to the temporary signed directory
66+
popd
67+
68+
# Sign the entire JAR with Apple codesign, using the same entitlements
69+
echo "Signing repackaged JAR: ${SIGNED_JARS_DIR}/$(basename "$jar")"
70+
/usr/bin/codesign -vvvv --entitlements $PWD/releng/com.espressif.idf.product/entitlements/espressif-ide.entitlement --force --deep --options runtime --timestamp -s "ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD. (QWXF6GB4AV)" "${SIGNED_JARS_DIR}/$(basename "$jar")"
71+
72+
# Verify the signed JAR
73+
echo "Verifying signed JAR: ${SIGNED_JARS_DIR}/$(basename "$jar")"
74+
/usr/bin/codesign -dvv "${SIGNED_JARS_DIR}/$(basename "$jar")"
75+
76+
# Clean up extracted directory (but leave the signed JAR in SIGNED_JARS_DIR)
77+
rm -rf "$TEMP_DIR"
4678
done
4779
48-
# Clean up the keystore file
49-
rm -v "${KEYSTORE_FILE}"
80+
- name: Check if signed JAR files exist
81+
run: |
82+
echo "Checking signed JAR files in ${SIGNED_JARS_DIR}:"
83+
ls -al ${SIGNED_JARS_DIR}
5084
5185
- name: Upload Signed JAR Files
5286
if: ${{ !cancelled() }}
5387
uses: actions/upload-artifact@v4
5488
with:
5589
name: signed-jar-files
56-
path: BUNDLES/com.espressif.idf.serial.monitor/lib/*.jar
90+
path: ${{ runner.temp }}/signed-jars/*

0 commit comments

Comments
 (0)