Skip to content

Commit

Permalink
Add Release & Sign Android App
Browse files Browse the repository at this point in the history
- Add version mechanism
- Update docs
- Fix minions default size
  • Loading branch information
haimkastner authored Nov 3, 2021
2 parents 3a4ff7b + 15ff858 commit 4f138f3
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 41 deletions.
82 changes: 81 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ jobs:
- name: Bundle Android APP
env:
REACT_APP_API_URL: '${{ secrets.API_URL_DEMO }}'
REACT_APP_V3_URL: '${{ secrets.V3_URL_APP }}'
REACT_APP_LIGHTWEIGHT_URL: '${{ secrets.LIGHTWEIGHT_URL_APP }}'
CASANET_KEY_STORE: '${{ secrets.CASANET_KEY_STORE }}'
CASANET_KEY_ALIAS: '${{ secrets.CASANET_KEY_ALIAS }}'
CASANET_KEY_PASSWORD: '${{ secrets.CASANET_KEY_PASSWORD }}'
BUILD_PATH: www
run: |
yarn run build
yarn run postbuild
npm i -g cordova
node scripts/decode-key-store.js
cordova platform add android
npm run android
cordova build android --release -- --keystore=casanet-key-store.jks --storePassword=$CASANET_KEY_PASSWORD --alias=$CASANET_KEY_ALIAS --password=$CASANET_KEY_PASSWORD
- uses: actions/upload-artifact@v2
with:
name: android
Expand All @@ -72,3 +81,74 @@ jobs:
with:
name: internal
path: internal

bomb_version:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Update Version Patch
id: target_version
run: |
npm i -g yarn
yarn install --frozen-lockfile
npm run patchversion
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo $PACKAGE_VERSION
echo ::set-output name=version::$PACKAGE_VERSION
- name: Commit and push changes
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Target next version to ${{ steps.target_version.outputs.version }} [ci skip]

release:
needs: bomb_version
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/download-artifact@master
with:
name: android
path: android
- name: Get the version
id: get_version
run: |
echo ::set-output name=version::$(node -p "require('./package.json').version")
echo ::set-output name=title::$(git log -1 --pretty=%B | sed -n '1p')
body=$(git log -1 --pretty=%B | sed 1d)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.title }}
body: ${{ steps.get_version.outputs.body }}
draft: false
prerelease: false
- name: Upload Release Asset - Android APP
id: upload-release-asset-android-app
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./android/release/app-release.apk
asset_name: casanet.apk
asset_content_type: application/octet-stream
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/platforms
/plugins
/www/*
/build/*
*.jks

# Generated API
generated
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

### A new react based modern hybrid dashboard for web & mobile.

## ✨✨✨ [Live Demo Dashboard](https://demo.dashboard.casanet.casa/) ✨✨✨

![Screenshot](./assets/capture/desktop-capture.gif)
<img src="./assets/capture/app1.jpg" alt="app1-dashboard"
title="lite-dashboard screenshot" width="270" height="580" />
Expand All @@ -18,9 +20,9 @@ The dashboard design to fully support the following features:
* Desktop, tablet, mobile and mobile app all fully supported.
* Multi-language with fully RTL support (using [i18n](https://react.i18next.com/)).

🚧🚧🚧 🛠 UNDER CONSTRUCTION 🛠 🚧🚧🚧
#### 💾 backward computability 💾

The new dashboard not fully implemented, you can still use the [v3 dashboard](https://github.com/casanet/frontend-v3) (should be server in `CASANET-URL/v3` URL).
You can still use the [v3 dashboard](https://github.com/casanet/frontend-v3) (should be server in `CASANET-URL/v3` URL).

## DEVELOPMENT

Expand All @@ -38,6 +40,6 @@ To build the mobile app using [cordova](https://cordova.apache.org/) first make

* `npm i -g cordova` - To install the cordova on the machine.
* `cordova platform add android` - Add the resources of cordova for Android.
* `yarn run cordova:android` - To build the app APK.
* `yarn run cordova:android` - To build & run the android app.

In order to debug app in realtime, connect the device to the PC, and open debug-mode, then go to `chrome://inspect/#devices` page.
44 changes: 22 additions & 22 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version="1.0" encoding="utf-8"?>
<widget id="casa.casanet.dashboard" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>casanet</name>
<description>
Cadasnet IoT control dashboard
Cadasnet IoT Control Dashboard
</description>
<author email="[email protected]" href="https://github.com/haimkastner">
Haim Kastner
Haim Kastner
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<content src="index.html"/>
<access origin="*"/>
<allow-intent href="*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
<application android:usesCleartextTraffic="true"/>
</edit-config>
<allow-intent href="market:*" />
<icon density="ldpi" src="assets/icons/android/mipmap-hdpi/ic_launcher.png" />
<icon density="hdpi" src="assets/icons/android/mipmap-hdpi/ic_launcher.png" />
<icon density="mdpi" src="assets/icons/android/mipmap-mdpi/ic_launcher.png" />
<icon density="xhdpi" src="assets/icons/android/mipmap-xhdpi/ic_launcher.png" />
<icon density="xxhdpi" src="assets/icons/android/mipmap-xxhdpi/ic_launcher.png" />
<icon density="xxxhdpi" src="assets/icons/android/mipmap-xxxhdpi/ic_launcher.png" />
<allow-intent href="market:*"/>
<icon density="ldpi" src="assets/icons/android/mipmap-hdpi/ic_launcher.png"/>
<icon density="hdpi" src="assets/icons/android/mipmap-hdpi/ic_launcher.png"/>
<icon density="mdpi" src="assets/icons/android/mipmap-mdpi/ic_launcher.png"/>
<icon density="xhdpi" src="assets/icons/android/mipmap-xhdpi/ic_launcher.png"/>
<icon density="xxhdpi" src="assets/icons/android/mipmap-xxhdpi/ic_launcher.png"/>
<icon density="xxxhdpi" src="assets/icons/android/mipmap-xxxhdpi/ic_launcher.png"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
</widget>
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "react-scripts test",
"eject": "react-scripts eject",
"android": "cordova build",
"android:release": "cordova build --release android",
"patchversion": "npm version --no-git-tag-version patch && node scripts/sync-cordova-version.js",
"cordova": "npm run build && cordova run",
"cordova:android": "npm run build && cordova run android"
},
Expand Down Expand Up @@ -92,6 +92,7 @@
"node-fetch": "^3.0.0",
"react-scripts": "4.0.3",
"sass": "^1.39.0",
"typescript": "^4.1.2"
"typescript": "^4.1.2",
"xml-js": "^1.6.11"
}
}
6 changes: 6 additions & 0 deletions scripts/decode-key-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fse from 'fs-extra';

// Get the store from environment variable as BASE64 string
const casanetKeyStoreBuffer = Buffer.from(process.env.CASANET_KEY_STORE, 'base64');
// Save it as binary file
fse.writeFileSync('casanet-key-store.jks', casanetKeyStoreBuffer);
18 changes: 18 additions & 0 deletions scripts/sync-cordova-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fse from 'fs-extra';
import path from 'path';
import xmlParser from 'xml-js';

const PACKAGE_JSON = path.join('package.json');
const CORDOVA_CONFIG_XML = path.join('config.xml');

const packageJson = fse.readJSONSync(PACKAGE_JSON);

const cordovaConfiguration = xmlParser.xml2js(fse.readFileSync(CORDOVA_CONFIG_XML));

cordovaConfiguration.elements[0].attributes.version = packageJson.version;

const xml = xmlParser.js2xml(cordovaConfiguration, {
spaces: ' '
});

fse.writeFileSync(path.join(CORDOVA_CONFIG_XML), xml)
19 changes: 10 additions & 9 deletions src/components/settings/generalSettings/ServerVersion.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Grid, IconButton, makeStyles, Typography, useTheme } from "@material-ui/core";
import { useTranslation } from "react-i18next";
import { SettingItem } from "../../../pages/dashboard-pages/Settings";
import { DEFAULT_FONT_RATION, SERVER_REPO_URL } from "../../../infrastructure/consts";
import { DASHBOARD_REPO_URL, DEFAULT_FONT_RATION, SERVER_REPO_URL } from "../../../infrastructure/consts";
import { ThemeTooltip } from "../../global/ThemeTooltip";
import { sessionManager } from "../../../infrastructure/session-manager";
import { ApiFacade } from "../../../infrastructure/generated/proxies/api-proxies";
Expand All @@ -21,6 +21,7 @@ import CircularProgress from "@mui/material/CircularProgress";
import { AlertDialog } from "../../AlertDialog";
import { useData } from "../../../hooks/useData";
import { livelinessCheck } from "../../../services/liveliness.service";
import { envFacade } from "../../../infrastructure/env-facade";

const useStyles = makeStyles((theme) => ({
iconBadge: {
Expand Down Expand Up @@ -148,7 +149,7 @@ export function ServerVersion() {
setUpdating(false);
}

return <SettingItem title={t('dashboard.settings.general.update.server.version')} >
return <SettingItem title={t('dashboard.settings.general.update.version')} >
<Grid
style={{ width: '100%' }}
container
Expand All @@ -175,27 +176,27 @@ export function ServerVersion() {
alignItems="center"
>
<div>
{t('dashboard.settings.general.update.version')}
{t('dashboard.settings.general.update.server.version')}
</div>
{versionData?.version && <div style={{ display: 'flex' }}>
<Typography>{versionData?.version}</Typography>
<VersionSourceLink link={`${SERVER_REPO_URL}/releases/tag/${versionData?.version}`} tip={t('dashboard.settings.general.update.version.link.tip', { version: versionData?.version })} />
</div>}
</Grid>
<Grid
style={{ width: '100%' }}
style={{ maxWidth: '100%' }}
container
direction="row"
justifyContent="space-between"
alignItems="center"
>
<div>
{t('dashboard.settings.general.update.commit')}
{t('Front version')}
</div>
<div style={{ display: 'flex' }}>
<Typography>{envFacade.bundleVersion}</Typography>
<VersionSourceLink link={`${DASHBOARD_REPO_URL}/releases/tag/${envFacade.bundleVersion}`} tip={t('dashboard.settings.general.update.version.link.tip', { version: versionData?.version })} />
</div>
{versionData?.commitHash && <div style={{ display: 'flex' }}>
<Typography>{versionData?.commitHash}</Typography>
<VersionSourceLink link={`${SERVER_REPO_URL}/tree/${versionData?.commitHash}`} tip={t('dashboard.settings.general.update.commit.link.tip')} />
</div>}
</Grid>
{!newVersion && <Grid
style={{ width: '100%' }}
Expand Down
5 changes: 5 additions & 0 deletions src/infrastructure/env-facade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getLocalStorageItem, LocalStorageKey, setLocalStorageItem } from "./local-storage";
import { Platform } from "./symbols/global";
import packageJson from "../../package.json";

class EnvFacade {

Expand Down Expand Up @@ -74,6 +75,10 @@ class EnvFacade {
public get isMobileApp(): boolean {
return this.platform !== 'Browser';
}

public get bundleVersion(): string {
return packageJson.version;
}
}

export const envFacade = new EnvFacade();
31 changes: 28 additions & 3 deletions src/pages/dashboard-pages/Minions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,41 @@ const defaultHeight = 240;
// The max/min ration (in %) to change from the default size
const maxRation = 100;
const minRation = 25;
const defaultRation = 40;

const mobileDefaultRation = 75;
const desktopDefaultRation = 60;
const wideDesktopDefaultRation = 70;
const veryWideDesktopDefaultRation = 90;

function getMinionsCardRationRation(desktopMode: boolean, wideDesktopMode: boolean, veryWideDesktopMode: boolean): number {

const savedRation = getLocalStorageItem<number>(LocalStorageKey.MinionsCardRatio, { itemType: 'number' });
// If size saved, return it
if (savedRation) {
return savedRation;
}
if (veryWideDesktopMode) {
return veryWideDesktopDefaultRation;
}
if (wideDesktopMode) {
return wideDesktopDefaultRation;
}
if (desktopMode) {
return desktopDefaultRation;
}
return mobileDefaultRation;
}

export default function Minions(props: DashboardPageInjectProps) {
const { t } = useTranslation();
const { id } = useParams<{ id: string }>();
const location = useLocation();
const desktopMode = useMediaQuery((theme: Theme) => theme.breakpoints.up('sm'));
const wideDesktopMode = useMediaQuery((theme: Theme) => theme.breakpoints.up('md'));
const veryWideDesktopMode = useMediaQuery((theme: Theme) => theme.breakpoints.up('lg'));
const [minions, loading] = useData(minionsService, []);

const [sizeRatio, setSizeRatio] = useState<number>(getLocalStorageItem<number>(LocalStorageKey.MinionsCardRatio, { itemType: 'number' }) || defaultRation);
const [sizeRatio, setSizeRatio] = useState<number>(getMinionsCardRationRation(desktopMode, wideDesktopMode, veryWideDesktopMode));
const [filteredMinions, setFilteredMinion] = useState<Minion[]>([]);

useEffect(() => {
Expand Down Expand Up @@ -105,7 +130,7 @@ export default function Minions(props: DashboardPageInjectProps) {
SideInfo = <MinionFullInfo minion={selectedMinion} />;
}
if (showCreateMinion) {
SideInfo = <CreateMinion />;
SideInfo = <CreateMinion />;
}

return <PageLayout
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10679,7 +10679,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.4.tgz#74b6d33c9ae1e001510f179a91168588f1aedaa9"
integrity sha1-dLbTPJrh4AFRDxeakRaFiPGu2qk=

sax@~1.2.4:
sax@^1.2.4, sax@~1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
Expand Down Expand Up @@ -12519,6 +12519,13 @@ ws@^7.4.6:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.4.tgz#56bfa20b167427e138a7795de68d134fe92e21f9"
integrity sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==

xml-js@^1.6.11:
version "1.6.11"
resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9"
integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==
dependencies:
sax "^1.2.4"

xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
Expand Down

0 comments on commit 4f138f3

Please sign in to comment.