refactor: move app-release-template to monorepo

This commit is contained in:
2023-03-14 17:26:49 +01:00
parent fdf7999437
commit 4f91f46af6
28 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
#json_key_file("../../playstore_api_key.json") # Don't Change
package_name ENV["ANDROID_PACKAGE_NAME"] || "de.anyschool.app.droid" # Don't Change

View File

@@ -0,0 +1,99 @@
# This file contains the fastlane.tools configuration for Android
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
require 'json'
require 'base64'
require 'pathname'
default_platform(:android)
current_version_code = 1
playstore_track = "internal"
package_json = JSON.parse(File.read('../../package.json'))
keystorePath = Pathname.getwd.parent + "../../playstore.keystore"
platform :android do
lane :fetch_version_code do
current_version_code = google_play_track_version_codes(
package_name: ENV['ANDROID_PACKAGE_NAME'],
track: playstore_track,
json_key_data: ENV['ANDROID_API_KEY_CONTENT']
).max
end
lane :fetch_highest_version_code do
version_code_candidates = [1]
tracks = ['production', 'beta', 'internal']
tracks.each do |t|
version_code_candidates += google_play_track_version_codes(
package_name: ENV['ANDROID_PACKAGE_NAME'],
track: t,
json_key_data: Base64.decode64(ENV['ANDROID_API_KEY_CONTENT'])
)
end
current_version_code = version_code_candidates.compact.max
puts "Version code chosen for build lane: %d" % [current_version_code + 1]
end
lane :build do
fetch_highest_version_code
android_set_version_name(
version_name: package_json["version"],
)
android_set_version_code(
version_code: current_version_code + 1,
)
gradle(
task: "clean assemble",
build_type: "Release",
print_command: false,
properties: {
"android.injected.signing.store.file" => keystorePath.to_s,
"android.injected.signing.store.password" => ENV['ANDROID_KEYSTORE_PASSWORD'],
"android.injected.signing.key.alias" => ENV['ANDROID_KEYSTORE_KEY_ALIAS'],
"android.injected.signing.key.password" => ENV['ANDROID_KEYSTORE_KEY_PASSWORD']
}
)
end
desc "Submit a new beta build to open beta testing track"
lane :beta do
playstore_track = "beta"
build
upload_to_play_store(
track: playstore_track,
json_key_data: Base64.decode64(ENV['ANDROID_API_KEY_CONTENT']),
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
end
desc "Submit a new version to the Google Play"
lane :release do
playstore_track = "production"
build
upload_to_play_store(
track: playstore_track,
json_key_data: Base64.decode64(ENV['ANDROID_API_KEY_CONTENT']),
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
end
end

View File

@@ -0,0 +1,112 @@
# This file contains the fastlane.tools configuration for iOS
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
require 'json'
require 'base64'
default_platform(:ios)
current_build_number = 1
package_json = JSON.parse(File.read('../../../package.json'))
api_key = app_store_connect_api_key(
key_id: ENV['APPLE_API_KEY_ID'],
issuer_id: ENV['APPLE_API_KEY_ISSUER_ID'],
key_content: "#{Base64.decode64(ENV['APPLE_API_KEY_CONTENT'])}".gsub('\n', '\\n'),
in_house: false
)
platform :ios do
lane :fetch_highest_build_number do
build_number_candidates = [1]
build_number_candidates << latest_testflight_build_number(
version: package_json['version'],
initial_build_number: 1,
app_identifier: ENV['IOS_BUNDLE_IDENTIFIER'],
api_key: api_key
)
build_number_candidates << app_store_build_number(
version: package_json['version'],
initial_build_number: 1,
app_identifier: ENV['IOS_BUNDLE_IDENTIFIER'],
api_key: api_key
)
current_build_number = build_number_candidates.max
end
lane :configure do
set_info_plist_value(
path: "App/Info.plist",
key: "NSLocationAlwaysAndWhenInUseUsageDescription",
value: ENV['LOCATION_USAGE_DESCRIPTION']
)
set_info_plist_value(
path: "App/Info.plist",
key: "NSLocationWhenInUseUsageDescription",
value: ENV['LOCATION_USAGE_DESCRIPTION']
)
set_info_plist_value(
path: "App/Info.plist",
key: "NSCalendarsUsageDescription",
value: ENV['CALENDAR_USAGE_DESCRIPTION']
)
update_url_schemes(
path: "App/Info.plist",
url_schemes: [ENV['APP_URL_SCHEME']]
)
update_code_signing_settings(
use_automatic_signing: true,
path: "App.xcodeproj",
team_id: ENV['TEAM_ID'],
bundle_identifier: ENV['IOS_BUNDLE_IDENTIFIER'],
entitlements_file_path: "App/App.entitlements"
)
increment_version_number(
version_number: package_json['version'],
xcodeproj: "App.xcodeproj"
)
fetch_highest_build_number
increment_build_number(
build_number: current_build_number + 1,
xcodeproj: "App.xcodeproj"
)
end
lane :build do
build_app(workspace: "App.xcworkspace", scheme: "App")
end
desc "Submit a new version to iOS App Store"
lane :release do
configure
build
upload_to_app_store(
skip_metadata: true,
skip_screenshots: true,
api_key: api_key
)
end
desc "Submit a new version to Testflight"
lane :beta do
configure
build
upload_to_testflight(
skip_submission: true,
api_key: api_key
)
end
end

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env sh
. $PWD/app.conf
DEFAULT_APP_URL_SCHEME="de.anyschool.app"
APP_URL_SCHEME="${APP_URL_SCHEME:-$DEFAULT_APP_URL_SCHEME}"
ANDROID_MANIFEST_PATH="app/android/app/src/main/AndroidManifest.xml"
ANDROID_STRINGS_PATH="app/android/app/src/main/res/values/strings.xml"
git -C app checkout -- android/build.gradle
git -C app checkout -- android/gradle/wrapper/gradle-wrapper.properties
git -C app checkout -- android/app/src/main/AndroidManifest.xml
git -C app checkout -- android/app/src/main/res/values/styles.xml
# AndroidManifest.xml
xmlstarlet edit --pf --inplace \
--update "/manifest/@package" --value "$ANDROID_PACKAGE_NAME" \
$ANDROID_MANIFEST_PATH
xmlstarlet edit --pf --inplace \
--update "/manifest/application/activity/@android:name" --value "$ANDROID_PACKAGE_NAME".MainActivity \
$ANDROID_MANIFEST_PATH
# strings.xml
xmlstarlet edit --pf --inplace \
--update "/resources/string[@name='package_name']" --value "$ANDROID_PACKAGE_NAME" \
$ANDROID_STRINGS_PATH
xmlstarlet edit --pf --inplace \
--update "/resources/string[@name='custom_url_scheme']" --value "$APP_URL_SCHEME" \
$ANDROID_STRINGS_PATH
xmlstarlet edit --inplace \
--delete "/resources/string[@name='app_host']" \
--append "/resources/string[@name='custom_url_scheme']" --type elem -n string --value "$APP_LINK_HOST" \
--insert "/resources/string[not(@name)]" --type attr -n name --value "app_host" \
$ANDROID_STRINGS_PATH

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env sh
# get semantical versioning string linke 2.0.0 (if $1 is v2.0.0) or $1
DEFAULT_VERSION="0.0.0"
APP_VERSION="${APP_VERSION:-$DEFAULT_VERSION}"
if echo -n $1 | grep -Eq 'v[0-9]+\.[0-9]+\.[0-9]+'; then
APP_VERSION=$(echo -n "$1" | cut -c 2-);
else
APP_VERSION=$1;
fi
if [ "$APP_VERSION" = "0.0.0" ]; then
echo "Unsupported app version was set!"
return 1
fi
git clone --depth 1 --branch $APP_VERSION https://gitlab.com/openstapps/app.git app

View File

@@ -0,0 +1,59 @@
#!/usr/bin/env sh
. $PWD/app.conf
DEFAULT_APP_ID="de.anyschool.app"
DEFAULT_CONFIG_MODE="WEB"
APP_ID="${APP_ID:-$DEFAULT_APP_ID}"
APP_VERSION=$(jq '.version' app/package.json)
CONFIG_MODE="${CONFIG_MODE:-$DEFAULT_CONFIG_MODE}"
if [ "$CONFIG_MODE" = 'ANDROID' ]; then
APP_ID="$ANDROID_PACKAGE_NAME"
fi
if [ "$CONFIG_MODE" = 'IOS' ]; then
APP_ID="$IOS_BUNDLE_IDENTIFIER"
fi
# ionic config
cat app/ionic.config.json | jq '.name = $newName' --arg newName "$APP_NAME" > tmp.$$.json && mv tmp.$$.json app/ionic.config.json
sed -i -e 's@<title>StApps<\/title>@<title>'"$APP_DISPLAY_NAME"'<\/title>@g' app/src/index.html
ROOT_THEME_DEFINITONS=$(cat app/src/theme/variables.scss | grep -o :root | wc -l)
if [ $ROOT_THEME_DEFINITONS -gt 1 ]; then
#update
echo "SCSS theme has already been set"
else
#insert
cat customizable/theme/variables.scss >> app/src/theme/variables.scss
fi
# capacitor config
awk "/appName:.*,/ && !done { gsub(/appName:.*,/, \"appName: '$APP_NAME',\"); done=1}; 1" app/capacitor.config.ts > tmp.$$.json && mv tmp.$$.json app/capacitor.config.ts
awk "/appId:.*,/ && !done { gsub(/appId:.*,/, \"appId: '$APP_ID',\"); done=1}; 1" app/capacitor.config.ts > tmp.$$.json && mv tmp.$$.json app/capacitor.config.ts
# cordova config
xmlstarlet edit -L --update "/widget/@id" --value "$APP_ID" app/config.xml
xmlstarlet edit -L --update "/widget/@version" --value "$APP_VERSION" app/config.xml
xmlstarlet edit -L -N x="http://www.w3.org/ns/widgets" --update "//x:name" --value "$APP_NAME" app/config.xml
SHORT_EXISTS=$(xmlstarlet sel -N x='http://www.w3.org/ns/widgets' -T -t -v '//x:name[@short]' app/config.xml)
if [ -z "${SHORT_EXISTS:-}" ]; then
#insert
xmlstarlet edit -L -N x="http://www.w3.org/ns/widgets" -s "//x:name" -t attr -n "short" -v "$APP_DISPLAY_NAME" app/config.xml
else
#update
xmlstarlet edit -L -N x="http://www.w3.org/ns/widgets" --update "//x:name[@short]" -v "$APP_DISPLAY_NAME" app/config.xml
fi
# environment config
awk "/backend_url:.*,/ && !done { gsub(/backend_url:.*,/, \"backend_url: '$BACKEND_URL',\"); done=1}; 1" app/src/environments/environment.production.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.production.ts
awk "/backend_version:.*,/ && !done { gsub(/backend_version:.*,/, \"backend_version: '$BACKEND_VERSION',\"); done=1}; 1" app/src/environments/environment.production.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.production.ts
awk "/app_host:.*,/ && !done { gsub(/app_host:.*,/, \"app_host: '$APP_LINK_HOST',\"); done=1}; 1" app/src/environments/environment.production.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.production.ts
awk "/custom_url_scheme:.*,/ && !done { gsub(/custom_url_scheme:.*,/, \"custom_url_scheme: '$APP_URL_SCHEME',\"); done=1}; 1" app/src/environments/environment.production.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.production.ts

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env sh
. $PWD/app.conf
ENTITLEMENTS_FILE="app/ios/App/App/App.entitlements"
INFOPLIST_FILE="app/ios/App/App/Info.plist"
/usr/libexec/PlistBuddy -c "Delete :com.apple.developer.associated-domains string applinks:$APP_LINK_HOST" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.associated-domains array" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.associated-domains:0 string applinks:$APP_LINK_HOST" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Delete :BGTaskSchedulerPermittedIdentifiers string com.transistorsoft.fetch" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :BGTaskSchedulerPermittedIdentifiers array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :BGTaskSchedulerPermittedIdentifiers:0 string com.transistorsoft.fetch" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Delete :UISupportedInterfaceOrientations~iphone array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Delete :UISupportedInterfaceOrientations array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationPortrait\"" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Delete :UISupportedInterfaceOrientations~ipad array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations~ipad array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations~ipad:0 string \"UIInterfaceOrientationPortrait\"" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations~ipad:1 string \"UIInterfaceOrientationPortraitUpsideDown\"" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations~ipad:2 string \"UIInterfaceOrientationLandscapeLeft\"" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations~ipad:3 string \"UIInterfaceOrientationLandscapeRight\"" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Delete :UIViewControllerBasedStatusBarAppearance bool" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UIViewControllerBasedStatusBarAppearance bool" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Set :UIViewControllerBasedStatusBarAppearance NO" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Delete :UIStatusBarStyle string" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :UIStatusBarStyle string" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Set :UIStatusBarStyle UIStatusBarStyleLightContent" $INFOPLIST_FILE
git -C app checkout -- ios/App/App/AppDelegate.swift

View File

@@ -0,0 +1,70 @@
#!/usr/bin/env sh
set -e
SSH_DEPLOY_TARGET=$2
SSH_DEPLOY_TARGET="${SSH_DEPLOY_TARGET:-"missingtarget"}"
SSH_PRIVATE_KEY=$3
SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY:-"missingkey"}"
GOTO_FAIL=false
if [ "$SSH_DEPLOY_TARGET" = "missingtarget" ]; then
echo "SSH target for web deployment job is unset!"
GOTO_FAIL=true
fi
if [ "$SSH_PRIVATE_KEY" = "missingkey" ]; then
echo "SSH key for web deployment job is unset!"
GOTO_FAIL=true
fi
if [ "$GOTO_FAIL" = true ]; then
return 1
fi
TARGET_COMPONENTS=$(echo "$SSH_DEPLOY_TARGET" | tr '@' "\n")
TARGET_COMPONENTS=$(echo "$TARGET_COMPONENTS" | tr ':' "\n")
SSH_DEPLOY_TARGET_USER=$(echo "$TARGET_COMPONENTS" | head -n 1 | tail -n 1)
SSH_DEPLOY_TARGET_HOST=$(echo "$TARGET_COMPONENTS" | head -n 2 | tail -n 1)
SSH_DEPLOY_TARGET_PATH=$(echo "$TARGET_COMPONENTS" | head -n 3 | tail -n 1)
SSH_DEPLOY_TARGET_USER="${SSH_DEPLOY_TARGET_USER:-"missinguser"}"
SSH_DEPLOY_TARGET_HOST="${SSH_DEPLOY_TARGET_HOST:-"missinghost"}"
SSH_DEPLOY_TARGET_PATH="${SSH_DEPLOY_TARGET_PATH:-"missingpath"}"
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
mkdir -p ~/.ssh
chmod 700 ~/.ssh
eval `ssh-agent -s`
echo "$SSH_PRIVATE_KEY" | base64 -d | tr -d '\r' | ssh-add -
## Use ssh-keyscan to scan the keys of your private server.
## You can copy and repeat that command if you have more than
## one server to connect to.
ssh-keyscan $SSH_DEPLOY_TARGET_HOST >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
web() {
scp www.zip "$SSH_DEPLOY_TARGET"
ssh "$SSH_DEPLOY_TARGET_USER@$SSH_DEPLOY_TARGET_HOST" "cd $SSH_DEPLOY_TARGET_PATH && unzip -o www.zip && rm -f www.zip"
}
apk() {
scp app/android/app/build/outputs/apk/release/app-release.apk "$SSH_DEPLOY_TARGET"
}
if declare -f "$1" > /dev/null
then
"$@"
else
echo "'$1' is not a known function name"
exit 1
fi

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env sh
. $PWD/app.conf
# iOS universal link file generation
if [ -z "$TEAM_ID" ] && [ -z "$IOS_BUNDLE_IDENTIFIER" ]
then
echo "Unable to find Apple Team ID and bundle identifier. Skipping apple-app-site-association generation..."
else
file_content=$(cat <<EOF
{
"applinks": {
"details": [
{
"appIDs": [ "${TEAM_ID}.${IOS_BUNDLE_IDENTIFIER}"],
"components": [
{
"/": "/*",
"comment": "Match all links"
}
]
}
]
}
}
EOF
)
echo $file_content > $PWD/app/www/.well-known/apple-app-site-association
fi
# Google Play/Android universal link file generation
KEYTOOL_INFO=$(keytool -list -v -keystore ./playstore.keystore -alias $ANDROID_KEYSTORE_KEY_ALIAS -storepass $ANDROID_KEYSTORE_PASSWORD -keypass $ANDROID_KEYSTORE_KEY_PASSWORD || true)
CERT_FINGERPRINT=$(echo $KEYTOOL_INFO | grep -Po '(?:[a-fA-F0-9]{2}:){31}[a-fA-F0-9]{2}')
if [ -z "$CERT_FINGERPRINT" ]
then
echo "Unable to retrieve Android sigining SHA256 fingerprint. Skipping assetlinks.json generation..."
else
file_content=$(cat <<EOF
[
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "${ANDROID_PACKAGE_NAME}",
"sha256_cert_fingerprints": [
"${CERT_FINGERPRINT}"
]
}
}
]
EOF
)
echo $file_content > $PWD/app/www/.well-known/assetlinks.json
fi