|
| 1 | +name: CI/CD on macOS systems. |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + pull_request: |
| 9 | + workflow_dispatch: |
| 10 | + # Automatic cron build every 6 months to check if everything still works. |
| 11 | + schedule: |
| 12 | + - cron: "0 0 1 1/6 *" |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: macos-latest |
| 17 | + env: |
| 18 | + LAZBUILD_WITH_PATH: /Applications/Lazarus/lazbuild |
| 19 | + RELEASE_ZIP_FILE: trackereditor_macOS_amd64.zip |
| 20 | + LAZ_OPT: --widgetset=cocoa |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Install Lazarus IDE |
| 26 | + run: brew install --cask lazarus |
| 27 | + |
| 28 | + - name: Build Release version |
| 29 | + # Build trackereditor project (Release mode) |
| 30 | + run: ${{ env.LAZBUILD_WITH_PATH }} --build-all --build-mode=Release ${{ env.LAZ_OPT }} source/project/tracker_editor/trackereditor.lpi |
| 31 | + shell: bash |
| 32 | + |
| 33 | + - name: Move program and icon into macOS .app |
| 34 | + env: |
| 35 | + ICON_FILE: 'metainfo/io.github.gerryferdinandus.bittorrent-tracker-editor.png' |
| 36 | + PROGRAM_NAME_WITH_PATH: 'enduser/trackereditor' |
| 37 | + run: | |
| 38 | + # remove the path |
| 39 | + PROGRAM_NAME_ONLY=$(basename -- "$PROGRAM_NAME_WITH_PATH") |
| 40 | +
|
| 41 | + # ------ Move program to app |
| 42 | + # remove symbolic link in app. Need real program here. |
| 43 | + rm -f "${PROGRAM_NAME_WITH_PATH}.app/Contents/MacOS/${PROGRAM_NAME_ONLY}" |
| 44 | + # copy the program to the app version. |
| 45 | + mv -f "${PROGRAM_NAME_WITH_PATH}" "${PROGRAM_NAME_WITH_PATH}.app/Contents/MacOS" |
| 46 | +
|
| 47 | + # ------ Create icon set and move it into the app |
| 48 | + iconset_folder="temp_folder.iconset" |
| 49 | + rm -rf "${iconset_folder}" |
| 50 | + mkdir -p "${iconset_folder}" |
| 51 | +
|
| 52 | + for s in 16 32 128 256 512; do |
| 53 | + d=$(($s*2)) |
| 54 | + sips -Z $s $ICON_FILE --out "${iconset_folder}/icon_${s}x$s.png" |
| 55 | + sips -Z $d $ICON_FILE --out "${iconset_folder}/icon_${s}[email protected]" |
| 56 | + done |
| 57 | +
|
| 58 | + # create .icns icon file |
| 59 | + iconutil -c icns "${iconset_folder}" -o "iconfile.icns" |
| 60 | + rm -r "${iconset_folder}" |
| 61 | +
|
| 62 | + # move icon file to the app |
| 63 | + mv -f "iconfile.icns" "${PROGRAM_NAME_WITH_PATH}.app/Contents/Resources" |
| 64 | +
|
| 65 | + # add icon to plist xml file CFBundleIconFile = "iconfile" |
| 66 | + plutil -insert CFBundleIconFile -string "iconfile" "${PROGRAM_NAME_WITH_PATH}.app/Contents/Info.plist" |
| 67 | + shell: bash |
| 68 | + |
| 69 | + - name: Codesign macOS app bundle |
| 70 | + # This macOS Codesign step is copied from: |
| 71 | + # https://federicoterzi.com/blog/automatic-code-signing-and-notarization-for-macos-apps-using-github-actions/ |
| 72 | + # This is a bit different from the previous version for Travis-CI build system to build bittorrent tracker editor |
| 73 | + env: |
| 74 | + MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }} |
| 75 | + MACOS_CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }} |
| 76 | + MACOS_CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }} |
| 77 | + MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }} |
| 78 | + MACOS_APP: enduser/trackereditor.app |
| 79 | + run: | |
| 80 | + # Turn our base64-encoded certificate back to a regular .p12 file |
| 81 | + echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12 |
| 82 | +
|
| 83 | + # We need to create a new keychain, otherwise using the certificate will prompt |
| 84 | + # with a UI dialog asking for the certificate password, which we can't |
| 85 | + # use in a headless CI environment |
| 86 | +
|
| 87 | + security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 88 | + security default-keychain -s build.keychain |
| 89 | + security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 90 | + security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign |
| 91 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 92 | +
|
| 93 | + # We finally codesign our app bundle, specifying the Hardened runtime option. |
| 94 | + #/usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" --options runtime "$MACOS_APP" -v |
| 95 | +
|
| 96 | + # sign the app. -sign is the developer cetificate ID |
| 97 | + # Must use --deep to sign all internal content |
| 98 | + /usr/bin/codesign --timestamp --force --options runtime --deep --sign "$MACOS_CERTIFICATE_NAME" "$MACOS_APP" |
| 99 | + shell: bash |
| 100 | + |
| 101 | + - name: Notarize macOS app bundle |
| 102 | + env: |
| 103 | + PROD_MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }} |
| 104 | + PROD_MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }} |
| 105 | + PROD_MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }} |
| 106 | + MACOS_APP: enduser/trackereditor.app |
| 107 | + run: | |
| 108 | + # Store the notarization credentials so that we can prevent a UI password dialog |
| 109 | + # from blocking the CI |
| 110 | +
|
| 111 | + echo "Create keychain profile" |
| 112 | + 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" |
| 113 | +
|
| 114 | + # We can't notarize an app bundle directly, but we need to compress it as an archive. |
| 115 | + # Therefore, we create a zip file containing our app bundle, so that we can send it to the |
| 116 | + # notarization service |
| 117 | +
|
| 118 | + echo "Creating temp notarization archive" |
| 119 | + ditto -c -k --keepParent "$MACOS_APP" "notarization.zip" |
| 120 | +
|
| 121 | + # Here we send the notarization request to the Apple's Notarization service, waiting for the result. |
| 122 | + # This typically takes a few seconds inside a CI environment, but it might take more depending on the App |
| 123 | + # characteristics. Visit the Notarization docs for more information and strategies on how to optimize it if |
| 124 | + # you're curious |
| 125 | +
|
| 126 | + echo "Notarize app" |
| 127 | + xcrun notarytool submit "notarization.zip" --keychain-profile "notarytool-profile" --wait |
| 128 | +
|
| 129 | + # Finally, we need to "attach the staple" to our executable, which will allow our app to be |
| 130 | + # validated by macOS even when an internet connection is not available. |
| 131 | + echo "Attach staple" |
| 132 | + xcrun stapler staple "$MACOS_APP" |
| 133 | +
|
| 134 | + # Remove notarization.zip, otherwise it will also be 'released' to the end user |
| 135 | + rm -f "notarization.zip" |
| 136 | +
|
| 137 | + # zip only the app folder. |
| 138 | + echo "Zip macOS app file" |
| 139 | + /usr/bin/ditto -c -k --keepParent "$MACOS_APP" "${{ env.RELEASE_ZIP_FILE }}" |
| 140 | + shell: bash |
| 141 | + |
| 142 | + - name: Upload Artifact |
| 143 | + uses: actions/upload-artifact@v4 |
| 144 | + with: |
| 145 | + name: artifact-${{ runner.os }} |
| 146 | + path: ${{ env.RELEASE_ZIP_FILE }} |
| 147 | + compression-level: 0 # no compression. Content is already a zip file |
| 148 | + if-no-files-found: error |
| 149 | + |
| 150 | + - name: File release to end user |
| 151 | + uses: softprops/action-gh-release@v2 |
| 152 | + if: startsWith(github.ref, 'refs/tags/') |
| 153 | + with: |
| 154 | + files: ${{ env.RELEASE_ZIP_FILE }} |
0 commit comments