Skip to content
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

Develop #47

Merged
merged 4 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Build release

on:
pull_request:
types:
- closed

jobs:

build-macos:
runs-on: macos-latest
if: github.event.pull_request.merged == true
env:
CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }}
CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }}
CERTIFICATE_CHECKSUM: ${{ secrets.PROD_MACOS_CERTIFICATE_CHECKSUM }}
KEYCHAIN_NAME: "build.keychain"
KEYCHAIN_PATH: "/Users/runner/Library/Keychains/"
KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }}
APPLE_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
NOTARYTOOL_PROFILE: "notarytool-profile"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18.14.0'

- name: Install dependencies
run: npm install

- name: Test ubuntu
if: ${{ matrix.os }} == 'ubuntu-latest'
run: |
echo "I am running only on ${{ matrix.os }}"

- name: Decode Apple Developer certificate
run: |
echo ${{ env.CERTIFICATE }} | base64 --decode > certificate.p12
ls -la certificate*
diff <( printf '%s\n' "${{ env.CERTIFICATE_CHECKSUM }}" ) <( printf '%s\n' "$(md5 -q certificate.p12)")
[ $? -eq 0 ] && (echo "File is identical" && exit 0) || (echo "File is different" && exit 1)

- name: Create keychain storage
run: |
security create-keychain -p "${{ env.KEYCHAIN_PWD }}" ${{env.KEYCHAIN_NAME}}
security default-keychain -s ${{ env.KEYCHAIN_NAME }}
security unlock-keychain -p "${{ env.KEYCHAIN_PWD }}" ${{ env.KEYCHAIN_NAME }}
security import certificate.p12 -k ${{ env.KEYCHAIN_NAME }} -P "${{ env.CERTIFICATE_PWD }}" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${{ env.KEYCHAIN_PWD }}" ${{ env.KEYCHAIN_NAME }}

- name: Create keychain profile for notarytool
run: |
security unlock-keychain -p "${{ env.KEYCHAIN_PWD }}" ${{ env.KEYCHAIN_NAME }}
xcrun notarytool store-credentials ${{ env.NOTARYTOOL_PROFILE }} \
--apple-id ${{ env.APPLE_ID }} \
--team-id ${{ env.APPLE_TEAM_ID }} \
--password "${{ env.APPLE_APP_SPECIFIC_PASSWORD }}" \
--keychain "${{ env.KEYCHAIN_PATH }}${{ env.KEYCHAIN_NAME }}-db"

- name: Build the artifacts and upload them on Github
env:
KEYCHAIN: "${{ env.KEYCHAIN_PATH }}${{ env.KEYCHAIN_NAME }}-db"
KEYCHAIN_PROFILE: ${{ env.NOTARYTOOL_PROFILE }}
GH_TOKEN: ${{ github.token }}
run: |
npm run ship -- --mac --universal

build-windows:
runs-on: windows-latest
if: github.event.pull_request.merged == true

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18.14.0'

- name: Install dependencies
run: npm install

- name: Build the artifacts and upload them on Github
env:
GH_TOKEN: ${{ github.token }}
run: |
npm run ship -- --windows

build-linux:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18.14.0'

- name: Install dependencies
run: npm install

- name: Build the artifacts and upload them on Github
env:
GH_TOKEN: ${{ github.token }}
run: |
npm run ship -- --linux

clean-release:
needs: [build-macos, build-windows, build-linux]
runs-on: ubuntu-latest

steps:
- name: Get the release data
id: releases_data
env:
HOST: "https://api.github.com"
ENDPOINT: "/repos/${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}/releases"
run: |
data=$(
curl -X GET -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${HOST}${ENDPOINT}"
)
data=$(echo "${data}" | jq '.[0] | {name, id, assets: (.assets | map({name, id}))} | tostring')
echo "release_data=${data}" >> $GITHUB_OUTPUT

- name: Read the output
run: |
echo ${{ steps.releases_data.outputs.release_data }} | jq '.'


- name: Filter requested data
id: jq_filter
run: |
blockmaps=$(
echo '${{ steps.releases_data.outputs.release_data }}' | jq -r \
'fromjson | .assets | map(select(.name | endswith(".blockmap"))) | map(.id | tostring) | join(" ")'
)
echo "( ${blockmaps} )"
echo "blockmap_list=( ${blockmaps} )" >> $GITHUB_OUTPUT

- name: Remove the blockmap files
env:
HOST: "https://api.github.com"
ENDPOINT: "/repos/${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}/releases/assets/"
run: |
assets_array="${{ steps.jq_filter.outputs.blockmap_list }}"
assets_array="${assets_array#(}"
assets_array="${assets_array%)}"

# Convert the array string to an actual array
IFS=', ' read -ra assets <<< "$assets_array"

# Iterate over the array elements
echo "Iterating over the assets:"
for asset_id in "${assets[@]}"; do
echo "Deleting asset with ID: $asset_id"
curl -X DELETE -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${HOST}${ENDPOINT}$asset_id"
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist
yarn.lock
.env
notarization-error.log
ci.copy
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ I was inspired by the [mlukasek/M5_NightscoutMon](https://github.com/mlukasek/M5

[![Download for Windows](https://img.shields.io/badge/Download-Windows%20.exe-blue?style=for-the-badge&logo=windows)](https://github.com/kashamalasha/nightscout-widget-electron/releases/download/v0.4.1-beta/Owlet-0.4.1-beta-win.exe)

[![Download for macOS](https://img.shields.io/badge/Download-macOS%20.dmg-blue?style=for-the-badge&logo=apple)](https://github.com/kashamalasha/nightscout-widget-electron/releases/download/v0.4.1-beta/Owlet-0.4.1-beta-mac.dmg)
[![Download for macOS(Apple Silicon)](https://img.shields.io/badge/Download-macOS%20(Apple%20Silicon)%20.dmg-blue?style=for-the-badge&logo=apple)](https://github.com/kashamalasha/nightscout-widget-electron/releases/download/v0.4.1-beta/Owlet-0.4.1-beta-mac-arm64.dmg)

[![Download for macOS(Intel)](https://img.shields.io/badge/Download-macOS%20(Intel)%20.dmg-blue?style=for-the-badge&logo=apple)](https://github.com/kashamalasha/nightscout-widget-electron/releases/download/v0.4.1-beta/Owlet-0.4.1-beta-mac-x64.dmg)

[![Download for Linux](https://img.shields.io/badge/Download-Linux%20.AppImage-blue?style=for-the-badge&logo=linux&logoColor=white)](https://github.com/kashamalasha/nightscout-widget-electron/releases/download/v0.4.1-beta/Owlet-0.4.1-beta-linux.AppImage)

Expand Down
55 changes: 55 additions & 0 deletions build/notarize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fs = require(`fs`);
const path = require(`path`);
const electronNotarize = require(`@electron/notarize`);

module.exports = async function (context) {
let params = {
tool: `notarytool`,
appPath: path.join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`),
};

if (!process.env.GITHUB_ACTIONS) {
const dotenv = require(`dotenv`);
const result = dotenv.config({ path: path.join(__dirname, `.env`) });

params = {
...params,
appBundleId: process.env.APP_ID,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_APP_SPECIFIC_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
};

if (result.error) {
throw result.error;
}
} else {
params = {
...params,
keychain: process.env.KEYCHAIN,
keychainProfile: process.env.KEYCHAIN_PROFILE,
};
}

if (process.platform !== `darwin`) {
return;
}
const prefix = ` •`;

console.log(`${prefix} afterSign hook triggered for notarizing the ${context.packager.appInfo.productFilename}.app`);

if (!fs.existsSync(params.appPath)) {
console.log(`${prefix} !! notarization process was skipped due to File not found`);
return;
}

console.log(`${prefix} notarizing started for the App file at ${params.appPath}`);

try {
await electronNotarize.notarize(params);
} catch (error) {
console.error(error);
}

console.log(`${prefix} notarizing finished successfully for the ${context.packager.appInfo.productFilename}.app`);
};
25 changes: 25 additions & 0 deletions build/remove_blockmaps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Check if an array string is provided as an argument
if [ $# -eq 0 ]; then
echo "Usage: $0 '( \"element1\" \"element2\" ... \"elementN\" )'"
exit 1
fi

# Get the array string argument
array_string="$1"

# Remove leading and trailing spaces and parentheses
array_string="${array_string#(}"
array_string="${array_string%)}"

# Convert the array string to an actual array
IFS=', ' read -ra elements <<< "$array_string"

# Iterate over the array elements
echo "Iterating over the elements:"
for el in "${elements[@]}"; do
echo "$el"
done

# You can perform other operations with the elements here
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const alert = (type, title, message, parentWindow = null) => {
type,
title,
message,
buttons: ['OK'],
buttons: [`OK`],
defaultId: 0,
icon: type,
};
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": {
"appId": "com.burny.owlet.app",
"productName": "Owlet",
"artifactName": "${productName}-${version}-${os}.${ext}",
"artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
"directories": {
"output": "dist"
},
Expand All @@ -33,9 +33,8 @@
"extraFiles": [
"LICENSE"
],
"afterSign": "electron-builder-notarize",
"mac": {
"notarize": true,
"notarize": false,
"hardenedRuntime": true,
"gatekeeperAssess": false,
"icon": "asset/icons/mac/AppIcon.icns",
Expand All @@ -52,6 +51,7 @@
}
]
},
"afterSign": "build/notarize.js",
"win": {
"target": [
"nsis",
Expand Down Expand Up @@ -107,10 +107,11 @@
"electron-updater": "^6.1.1"
},
"devDependencies": {
"@electron/notarize": "^2.1.0",
"ajv": "^8.11.2",
"dotenv": "^16.3.1",
"electron": "^25.2.0",
"electron-builder": "^24.4.0",
"electron-builder-notarize": "^1.5.1",
"eslint": "^8.46.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-node": "^11.1.0",
Expand Down