-
Notifications
You must be signed in to change notification settings - Fork 133
fix: CI for signing jars #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kolipakakondal
wants to merge
5
commits into
master
Choose a base branch
from
signjars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: CI for signing jars #1059
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: Sign jars and internal native libraries | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: macos-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Codesign JARs and Internal Native Libraries | ||
| env: | ||
| MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }} | ||
| MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }} | ||
| run: | | ||
| # Step 1: Decode and import the certificate into a keychain | ||
| echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12 | ||
| /usr/bin/security create-keychain -p espressif build.keychain | ||
| /usr/bin/security default-keychain -s build.keychain | ||
| /usr/bin/security unlock-keychain -p espressif build.keychain | ||
| /usr/bin/security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PWD -T /usr/bin/codesign | ||
| /usr/bin/security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k espressif build.keychain | ||
|
|
||
| # Step 2: Define the directory containing the JARs and native libraries and the temp directory for signed JARs | ||
| LIB_DIR="${PWD}/BUNDLES/com.espressif.idf.serial.monitor/lib" | ||
| SIGNED_JARS_DIR="${RUNNER_TEMP}/signed-jars" # Use GitHub's RUNNER_TEMP for storing signed JARs | ||
| mkdir -p "$SIGNED_JARS_DIR" | ||
|
|
||
| # Step 3: Extract, sign native libraries, repackage, and sign the JARs with Apple codesign | ||
| for jar in "${LIB_DIR}"/*.jar; do | ||
| echo "Processing JAR file: ${jar}" | ||
|
|
||
| # Check if the JAR exists | ||
| if [ -f "$jar" ]; then | ||
| echo "JAR file found: ${jar}" | ||
| else | ||
| echo "JAR file not found: ${jar}" | ||
| continue | ||
| fi | ||
|
|
||
| # Create a temporary directory to extract the JAR contents | ||
| TEMP_DIR=$(mktemp -d) | ||
| unzip -q "$jar" -d "$TEMP_DIR" | ||
|
|
||
| # Find and sign all .jnilib and .dylib files in the extracted JAR directory | ||
| find "$TEMP_DIR" -name "*.jnilib" -o -name "*.dylib" | while read lib; do | ||
| echo "Signing native library: ${lib}" | ||
| /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" | ||
| done | ||
|
|
||
| # Repackage the signed JAR | ||
| pushd "$TEMP_DIR" | ||
| zip -r "${SIGNED_JARS_DIR}/$(basename "$jar")" * # Save signed JAR to the temporary signed directory | ||
| popd | ||
|
|
||
| # Sign the entire JAR with Apple codesign, using the same entitlements | ||
| echo "Signing repackaged JAR: ${SIGNED_JARS_DIR}/$(basename "$jar")" | ||
| /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")" | ||
|
|
||
| # Verify the signed JAR | ||
| echo "Verifying signed JAR: ${SIGNED_JARS_DIR}/$(basename "$jar")" | ||
| /usr/bin/codesign -dvv "${SIGNED_JARS_DIR}/$(basename "$jar")" | ||
|
|
||
| # Clean up extracted directory (but leave the signed JAR in SIGNED_JARS_DIR) | ||
| rm -rf "$TEMP_DIR" | ||
| done | ||
|
|
||
| - name: Verify Signed JAR Files Before Upload | ||
| run: | | ||
| for jar in ${{ runner.temp }}/signed-jars/*; do | ||
| echo "Verifying signed JAR: ${jar}" | ||
| /usr/bin/codesign -dvv "${jar}" | ||
| done | ||
|
|
||
| - name: Display Signed JAR Files | ||
| run: | | ||
| echo "Displaying the signed JAR directory:" | ||
| ls -al ${{ runner.temp }}/signed-jars/ | ||
| echo "Listing all files in the signed JAR directory:" | ||
| find ${{ runner.temp }}/signed-jars/ -type f | ||
|
|
||
| - name: Upload Signed JAR Files | ||
| if: ${{ !cancelled() }} | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: signed-jar-files | ||
| path: ${{ runner.temp }}/signed-jars/* | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize JAR processing and signing.
The current implementation works, but it can be improved for better performance, reliability, and security:
read -rto prevent backslash mangling in filenames.Here's an optimized version of the JAR processing logic:
This version uses GNU Parallel for concurrent processing, adds error checking, uses
read -r, and quotes variables for improved security and reliability.