Skip to content

Commit

Permalink
Update: Version utils & Github actions (#1072)
Browse files Browse the repository at this point in the history
* github action:
 - custom apk:
   - packet name with git commit id
   - app name with git commit id
 - cached `npm install`
 - update actions versions

* About page:
 - Version based on package.json
 - added git hash to the version if not Stable
 - RELEASE_DATE, GIT_HASH, BUILD_TYPE created at build time from setEnvFile.cjs
 - special BUILD_TYPE for github actions
 - Version modal copy on click
 - removed versionUtils

* expo-clipboard instead of react-native clipboard

* buildRelease Release instead of Debug ^^'
Gihtub Actions => Github Action
  • Loading branch information
error7404 authored May 30, 2024
1 parent e50b6c4 commit aec6c34
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 20 deletions.
62 changes: 55 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,97 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository (Latest)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- name: Cache npm & node modules
uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-cache-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-cache-npm-
- name: Install Dependencies
run: |
npm install
- name: Create .env
run: |
cat > .env << EOF
MYANIMELIST_CLIENT_ID=${{ vars.MYANIMELIST_CLIENT_ID }}
ANILIST_CLIENT_ID=${{ vars.ANILIST_CLIENT_ID }}
GIT_HASH=$(git rev-parse --short HEAD)
RELEASE_DATE=$(date --utc +'%d/%m/%y %I:%M %p %Z')
BUILD_TYPE=Github Action
EOF
- name: Cache Gradle Wrapper
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}

- name: Cache Gradle Dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-caches-
- name: Cache build intermediates
uses: actions/cache@v4
with:
path: |
android/app/build/generated
android/app/build/intermediates
android/app/build/tmp
android/.gradle
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}

- name: Make Gradlew Executable
run: cd android && chmod +x ./gradlew

- name: Build Android Release
run: |
cd android && ./gradlew assembleRelease --no-daemon
mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/LNReader.apk
- name: Set Env
run: |
set -x
echo "COMMIT_COUNT=$(git rev-list --count HEAD)" >> $GITHUB_ENV
echo "COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v1
env:
COMMIT_COUNT: ${{ env.COMMIT_COUNT }}
uses: actions/upload-artifact@v4
with:
name: LNReader-r${{ env.COMMIT_COUNT }}
path: android/app/build/outputs/apk/release/app-release.apk
path: android/app/build/outputs/apk/release/LNReader.apk

- name: Build Custom APK
env:
COMMIT_COUNT: ${{ env.COMMIT_COUNT }}
COMMIT_ID: ${{ env.COMMIT_ID }}
run: |
sed -i 's/LNReader/LNReader-r${{ env.COMMIT_COUNT }}(${{ env.COMMIT_ID }})/g' android/app/src/main/res/values/strings.xml
cd android && ./gradlew assembleRelease --no-daemon -PcustomAppId=com.rajarsheechatterjee.LNReader.commit_${{ env.COMMIT_ID }}
mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/LNReader-r${{ env.COMMIT_COUNT }}\(${{ env.COMMIT_ID }}\)-customID.apk
- name: Upload Custom APK
env:
COMMIT_COUNT: ${{ env.COMMIT_COUNT }}
COMMIT_ID: ${{ env.COMMIT_ID }}
uses: actions/upload-artifact@v4
with:
name: LNReader-r${{ env.COMMIT_COUNT }}(${{ env.COMMIT_ID }})-customID
path: android/app/build/outputs/apk/release/LNReader-r${{ env.COMMIT_COUNT }}(${{ env.COMMIT_ID }})-customID.apk
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ android {
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.rajarsheechatterjee.LNReader"
defaultConfig {
applicationId 'com.rajarsheechatterjee.LNReader'
applicationId project.hasProperty('customAppId') ? project.getProperty('customAppId') : 'com.rajarsheechatterjee.LNReader'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
// Generated version code. Supports versions up to 1024.1024.2048
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rajarsheechatterjee.LNReader">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Internet -->
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
3 changes: 3 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
declare module '@env' {
export const MYANIMELIST_CLIENT_ID: string;
export const ANILIST_CLIENT_ID: string;
export const GIT_HASH: string;
export const RELEASE_DATE: string;
export const BUILD_TYPE: 'Debug' | 'Release' | 'Beta' | 'Github Action';
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "2.0.0",
"private": true,
"scripts": {
"android": "react-native run-android --active-arch-only",
"android": "npm run prestart && react-native run-android --active-arch-only",
"ios": "react-native run-ios",
"prestart": "node scripts/setEnvFile.cjs Debug",
"start": "react-native start",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"prettier": "prettier --write \"./src/**/*.{js,jsx,ts,tsx}\"",
"buildRelease": "cd android && ./gradlew clean && ./gradlew assembleRelease",
"buildRelease": "node scripts/setEnvFile.cjs Release && cd android && ./gradlew clean && ./gradlew assembleRelease",
"open": "open ./android/app/build/outputs/apk/release/",
"strings": "node scripts/stringTypes.cjs",
"prepare": "husky install"
Expand Down
23 changes: 23 additions & 0 deletions scripts/setEnvFile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const { execSync } = require('child_process');

const formattedDate = new Date().getTime();

const commitHash = execSync('git rev-parse --short HEAD').toString().trim();

const buildType = process.argv[2] || 'Beta';

let data =
`BUILD_TYPE=${buildType}` +
os.EOL +
`GIT_HASH=${commitHash}` +
os.EOL +
`RELEASE_DATE=${formattedDate}`;

fs.writeFile(path.join(__dirname, '..', '.env'), data, 'utf8', err => {
if (err) {
console.log(err);
}
});
4 changes: 2 additions & 2 deletions src/hooks/common/githubUpdateChecker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { appVersion } from '../../utils/versionUtils';
import { version } from '../../../package.json';
import { newer } from '@utils/compareVersion';

interface GithubUpdate {
Expand Down Expand Up @@ -29,7 +29,7 @@ export const useGithubUpdateChecker = (): GithubUpdate => {
};

const isNewVersion = (versionTag: string) => {
let currentVersion = `${appVersion}`;
let currentVersion = `${version}`;
const regex = /[^\\d.]/;

let newVersion = versionTag.replace(regex, '');
Expand Down
25 changes: 22 additions & 3 deletions src/screens/more/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ import * as Linking from 'expo-linking';
import { getString } from '@strings/translations';
import { ScreenContainer } from '@components/Common';
import { MoreHeader } from './components/MoreHeader';
import { appVersion, releaseDate } from '@utils/versionUtils';
import { useTheme } from '@hooks/persisted';
import { List } from '@components';
import { AboutScreenProps } from '@navigators/types';
import { GIT_HASH, RELEASE_DATE, BUILD_TYPE } from '@env';
import * as Clipboard from 'expo-clipboard';
import { version } from '../../../package.json';

const AboutScreen = ({ navigation }: AboutScreenProps) => {
const theme = useTheme();

function getBuildName() {
if (!GIT_HASH || !RELEASE_DATE || !BUILD_TYPE) {
return `Custom build ${version}`;
} else {
const localDateTime = isNaN(Number(RELEASE_DATE))
? RELEASE_DATE
: new Date(Number(RELEASE_DATE)).toLocaleString();
if (BUILD_TYPE === 'Release') {
return `${BUILD_TYPE} ${version} (${localDateTime})`;
}
return `${BUILD_TYPE} ${version} (${localDateTime}) Commit: ${GIT_HASH}`;
}
}

return (
<ScreenContainer theme={theme}>
<MoreHeader
Expand All @@ -26,14 +42,17 @@ const AboutScreen = ({ navigation }: AboutScreenProps) => {
<List.Section>
<List.Item
title={getString('aboutScreen.version')}
description={`Stable ${appVersion} (${releaseDate})`}
description={getBuildName()}
theme={theme}
onPress={() => {
Clipboard.setStringAsync(getBuildName());
}}
/>
<List.Item
title={getString('aboutScreen.whatsNew')}
onPress={() =>
Linking.openURL(
`https://github.com/LNReader/lnreader/releases/tag/v${appVersion}`,
`https://github.com/LNReader/lnreader/releases/tag/v${version}`,
)
}
theme={theme}
Expand Down
4 changes: 2 additions & 2 deletions src/services/backup/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TRACKER } from '@hooks/persisted/useTracker';
import { LAST_UPDATE_TIME } from '@hooks/persisted/useUpdates';
import { BACKGROUND_ACTION } from '@services/constants';
import { MMKVStorage } from '@utils/mmkv/mmkv';
import { appVersion } from '@utils/versionUtils';
import { version } from '../../../package.json';
import {
_restoreNovelAndChapters,
getAllNovels,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const prepareBackupData = async (cacheDirPath: string) => {
// version
await TextFile.writeFile(
cacheDirPath + '/' + BackupEntryName.VERSION,
JSON.stringify({ version: appVersion }),
JSON.stringify({ version: version }),
);

// novels
Expand Down
2 changes: 0 additions & 2 deletions src/utils/versionUtils.ts

This file was deleted.

0 comments on commit aec6c34

Please sign in to comment.