Skip to content

Update GitHub Actions #79

Update GitHub Actions

Update GitHub Actions #79

Workflow file for this run

name: mac
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [published]
env:
ARTIFACTORY_ACCESS_TOKEN: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
build_dir: "Build/Release"
package: EphysSocket-mac
jobs:
check-semver:
runs-on: ubuntu-22.04
if: github.event_name != 'release'
steps:
- name: Checkout current version
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find previous release
id: previous-release
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "RELEASE_NAME=$(gh release list -L 1 --json tagName -q .[0].tagName)" >> $GITHUB_OUTPUT
- name: Verify release name
id: verify-release
if: steps.previous-release.outputs.RELEASE_NAME == ''
run: |
echo "No previous releases found. Skipping the semver check."
exit 0
- name: Checkout last release version
if: steps.previous-release.outputs.RELEASE_NAME != ''
uses: actions/checkout@v4
with:
ref: ${{ steps.previous-release.outputs.RELEASE_NAME }}
path: last-release
sparse-checkout: |
Source/OpenEphysLib.cpp
sparse-checkout-cone-mode: false
- name: Extract Versions
if: steps.previous-release.outputs.RELEASE_NAME != ''
id: extract-versions
run: |
echo "CURRENT_VERSION=$(cat ./Source/OpenEphysLib.cpp | grep -w -e 'info->libVersion' | grep -Eo "[0-9]+.[0-9]+.[0-9]+")" >> $GITHUB_OUTPUT
echo "PREVIOUS_VERSION=$(cat ./last-release/Source/OpenEphysLib.cpp | grep -w -e 'info->libVersion' | grep -Eo "[0-9]+.[0-9]+.[0-9]+")" >> $GITHUB_OUTPUT
- name: Setup Python
if: steps.previous-release.outputs.RELEASE_NAME != ''
uses: actions/setup-python@v5
with:
python-version: "3.10.12"
- name: Install semver
if: steps.previous-release.outputs.RELEASE_NAME != ''
run: python -m pip install semver
- name: Compare Versions
if: steps.previous-release.outputs.RELEASE_NAME != ''
run: |
version_current=${{ steps.extract-versions.outputs.CURRENT_VERSION }}
version_release=${{ steps.extract-versions.outputs.PREVIOUS_VERSION }}
echo "Current Version: $version_current"
echo "Release Version: $version_release"
if [ ! $(python -c "import semver; print(semver.compare(\"$version_current\", \"$version_release\"))") == 1 ]; then
echo "::error title=Invalid version number::Version number must be increased"
exit 1
fi
build-mac:
needs: [check-semver]
if: always() && !failure() && !cancelled()
runs-on: [macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: setup
run: |
cd ../..
git clone https://github.com/open-ephys/plugin-GUI.git --branch main
cd plugin-GUI/Build && cmake -G "Xcode" ..
- name: build
id: build
run: |
cd Build
cmake -G "Xcode" ..
xcodebuild -configuration Release
- name: Collect artifact
uses: actions/upload-artifact@v4
if: steps.build.outcome == 'success' && always()
with:
name: Artifact
if-no-files-found: error
path: |
$build_dir
deploy-mac:
needs: [build-mac]
runs-on: macos-latest
if: github.event_name == 'release' && always() && !failure() && !cancelled()
steps:
- name: Download build folder
uses: actions/download-artifact@v4
with:
name: Artifact
path: $build_dir
- name: deploy
env:
MACOS_CERTIFICATE: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
MACOS_CERTIFICATE_PWD: ${{ secrets.BUILD_CERTIFICATE_PWD }}
MACOS_CERTIFICATE_NAME: ${{ secrets.BUILD_CERTIFICATE_NAME }}
MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
PROD_MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }}
PROD_MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
PROD_MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
run: |
plugin_api=$(grep -rnw ../../plugin-GUI/Source -e '#define PLUGIN_API_VER' | grep -Eo "[0-9]*" | tail -1)
tag=$(grep -w Source/OpenEphysLib.cpp -e 'info->libVersion' | grep -Eo "[0-9]+.[0-9]+.[0-9]+")
new_plugin_ver=$tag-API$plugin_api
mkdir plugins
cp -r $build_dir/*.bundle plugins
# Turn our base64-encoded certificate back to a regular .p12 file
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
# We need to create a new keychain, otherwise using the certificate will prompt
# with a UI dialog asking for the certificate password, which we can't
# use in a headless CI environment
security create-keychain -p $MACOS_CI_KEYCHAIN_PWD build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p $MACOS_CI_KEYCHAIN_PWD build.keychain
security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PWD -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CI_KEYCHAIN_PWD build.keychain
/usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" -v plugins/ephys-socket.bundle --deep --strict --timestamp --options=runtime
/usr/bin/codesign -dv --verbose=4 plugins/ephys-socket.bundle
# Store the notarization credentials so that we can prevent a UI password dialog from blocking the CI
echo "Create keychain profile"
xcrun notarytool store-credentials "notarytool-profile" --apple-id "$PROD_MACOS_NOTARIZATION_APPLE_ID" --team-id "$PROD_MACOS_NOTARIZATION_TEAM_ID" --password "$PROD_MACOS_NOTARIZATION_PWD"
# We can't notarize an app bundle directly, but we need to compress it as an archive.
# Therefore, we create a zip file containing our app bundle, so that we can send it to the
# notarization service
echo "Creating temp notarization archive"
/usr/bin/ditto -c -k --sequesterRsrc --keepParent plugins/ephys-socket.bundle ephys-socket.zip
# Here we send the notarization request to the Apple's Notarization service, waiting for the result.
# This typically takes a few seconds inside a CI environment, but it might take more depending on the App
# characteristics. Visit the Notarization docs for more information and strategies on how to optimize it if
# you're curious
echo "Notarize app"
xcrun notarytool submit "ephys-socket.zip" --keychain-profile "notarytool-profile" --wait
# Finally, we need to "attach the staple" to our executable, which will allow our app to be
# validated by macOS even when an internet connection is not available.
echo "Attach staple"
rm -r plugins/*
/usr/bin/ditto -x -k ephys-socket.zip plugins
xcrun stapler staple plugins/ephys-socket.bundle
spctl -vvv --assess --type exec plugins/ephys-socket.bundle
zipfile=${package}_${new_plugin_ver}.zip
/usr/bin/ditto -c -k --sequesterRsrc --keepParent plugins $zipfile
curl -H "X-JFrog-Art-Api:$ARTIFACTORY_ACCESS_TOKEN" -T $zipfile "https://openephys.jfrog.io/artifactory/EphysSocket-plugin/mac/$zipfile"