From e27d129248fbe9c4b00a5aec7011a8628bb975b2 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 19 Jul 2024 15:44:52 +0530 Subject: [PATCH 01/20] cp unsigned apk to a generic name without version number --- .gitlab-ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8af528d99..dc4eb88d2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,12 @@ image: "registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:master" +variables: + PROJECT_ID: "83" # under Settings -> General + APK_PATH: "app/build/outputs/apk/ose/release" + UNSIGNED_APK: "davx5-ose-release-unsigned.apk" + DEV_APK: "Account-manager-dev.apk" + STABLE_APK: "Account-manager-stable.apk" + stages: - update-from-upstream - build @@ -27,6 +34,13 @@ build: stage: build script: - ./gradlew build -x test + - cd app/build/outputs/apk/ose/ + - | + if [[ -d "release" ]]; then + cd "release" + unsigned_build=$(ls *.apk | grep "unsigned") + cp $unsigned_build $UNSIGNED_APK + fi artifacts: paths: - app/build/outputs/apk/ose/ -- GitLab From 4e3c5ff154ac17decfe31fbdb4a0717e3004eb9d Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 19 Jul 2024 18:07:32 +0530 Subject: [PATCH 02/20] gitlab release apks --- .gitlab-ci.yml | 156 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc4eb88d2..1e6e87ffe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ variables: stages: - update-from-upstream - build + - release before_script: - echo email.key=$PEPPER >> local.properties @@ -45,6 +46,161 @@ build: paths: - app/build/outputs/apk/ose/ +generate-apks: + stage: release + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: manual + needs: + - build + before_script: + - apt update && apt install apksigner -y + script: + - cd $APK_PATH + - cp $UNSIGNED_APK $DEV_APK + - cp $UNSIGNED_APK $STABLE_APK + - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_DEV + --ks-pass env:KEYSTORE_PASSWORD $DEV_APK + && echo "Signed DEV" + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_STABLE + --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK + && echo "Signed STABLE" + after_script: + - rm ~/proprietary.keystore.jks + artifacts: + paths: + - $APK_PATH/$UNSIGNED_APK + - $APK_PATH/$DEV_APK + - $APK_PATH/$STABLE_APK + +create-json-files: + stage: release + needs: + - generate-apks + dependencies: + - generate-apks + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: on_success + before_script: + - apt update && apt install jq aapt -y + script: + - pushd $APK_PATH + - | + # Args: filter field_name + # Example: getApkInfo "package:" "versionName" + getApkInfo() { + aapt dump badging $UNSIGNED_APK | grep "$1" | sed -e "s/.*$2'//" -e "s/'.*//" + } + - package_name="$(getApkInfo "package:" " name=")" + - version_name="$(getApkInfo "package:" "versionName=")" + - version_code="$(getApkInfo "package:" "versionCode=")" + - min_sdk="$(getApkInfo "sdkVersion:" "sdkVersion:")" + - application_label="$(getApkInfo "application:" "label=")" + - echo "Package name - $package_name" + - echo "Version name - $version_name" + - echo "Version code - $version_code" + - echo "Minimum SDK - $min_sdk" + - echo "Application label - $application_label" + - | + # Args: file_name key value + # Example: editJson test.json "my_key" "my_value" + editJson() { + tmp=$(mktemp) + file="$1" + key="$2" + value="$3" + { + jq --arg key "$key" --argjson val "$value" '.[$key] = $val' "$file" > "$tmp" 2>/dev/null + } || { + jq --arg key "$key" --arg val "$value" '.[$key] = $val' "$file" > "$tmp" + } && mv "$tmp" "$file" + } + - | + # Generate update info about dev or stable builds. + # Args: file_name apk_download_url + generateJsonFile() { + fileName="$1" + url="$2" + echo "{}" > $fileName + editJson $fileName "name" "$application_label" + editJson $fileName "package_name" "$package_name" + editJson $fileName "version_code" "$version_code" + editJson $fileName "min_sdk" "$min_sdk" + editJson $fileName "version_name" "$version_name" + editJson $fileName "url" "$url" + if [[ -n ${PRIORITY} ]]; then editJson $fileName "priority" "${PRIORITY}"; fi + if [[ -n ${BLACKLISTED_DEVICES} ]]; then editJson $fileName "blacklisted_devices" "${BLACKLISTED_DEVICES}"; fi + if [[ -n ${BLACKLISTED_ANDROID} ]]; then editJson $fileName "blacklisted_android" "${BLACKLISTED_ANDROID}"; fi + } + - generateJsonFile dev.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks" + - generateJsonFile stable.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks" + - popd + - mv $APK_PATH/dev.json . + - mv $APK_PATH/stable.json . + artifacts: + paths: + - dev.json + - stable.json + +create-release: + stage: release + needs: + - generate-apks + - create-json-files + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: on_success + before_script: + - apt update && apt install jq -y + script: + - | + cat > data.json << EOF + { + "tag_name": "$CI_COMMIT_TAG", + "ref": "$CI_COMMIT_TAG", + "assets": { + "links": [ + { + "name": "dev.json", + "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/dev.json?job=create-json-files", + "direct_asset_path": "/json/dev.json", + "link_type": "other" + }, + { + "name": "stable.json", + "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/stable.json?job=create-json-files", + "direct_asset_path": "/json/stable.json", + "link_type": "other" + }, + { + "name": "$DEV_APK", + "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks", + "link_type": "package" + }, + { + "name": "$STABLE_APK", + "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks", + "link_type": "package" + } + ] + } + } + EOF + - compressed_json=$(jq -c . data.json) + - | + curl --data "$compressed_json" \ + --header 'Content-Type: application/json' --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \ + --fail --output "/dev/null" --silent --show-error \ + --request POST https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/releases + .update-from-upstream: stage: update-from-upstream rules: -- GitLab From eb8215f3276ac85473ac8bf69246ec9423446196 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 19 Jul 2024 18:31:08 +0530 Subject: [PATCH 03/20] update version code to test --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 5524d8c21..08caff372 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,7 +19,7 @@ android { defaultConfig { applicationId "foundation.e.accountmanager" - versionCode 403090003 + versionCode 403090004 versionName '4.3.9' buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" -- GitLab From 2488e9ff5995a27a737c0faa3f30e03f7c1c6145 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Tue, 23 Jul 2024 15:08:40 +0530 Subject: [PATCH 04/20] update dav4jvm version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e7341354f..e969706ab 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { commonsText: '1.10.0', // own libraries cert4android: '2bb3898', - dav4jvm: '1ed89c1', + dav4jvm: '1ed89c165d', ical4android: '1.1.2', vcard4android: '1.1.2' ] -- GitLab From 8292bc73fd711d0148e28425d43818626dc566a2 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 01:08:14 +0530 Subject: [PATCH 05/20] revert versionCode and update versionName --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08caff372..0a81972b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { defaultConfig { applicationId "foundation.e.accountmanager" - versionCode 403090004 - versionName '4.3.9' + versionCode 403090003 + versionName '4.3.9+eOS-1.0' buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" -- GitLab From 68df574602b3090897920c4da6fd61df6cd6279a Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 01:20:31 +0530 Subject: [PATCH 06/20] change "blacklist" to "blocked" --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e6e87ffe..a4794341b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -137,8 +137,8 @@ create-json-files: editJson $fileName "version_name" "$version_name" editJson $fileName "url" "$url" if [[ -n ${PRIORITY} ]]; then editJson $fileName "priority" "${PRIORITY}"; fi - if [[ -n ${BLACKLISTED_DEVICES} ]]; then editJson $fileName "blacklisted_devices" "${BLACKLISTED_DEVICES}"; fi - if [[ -n ${BLACKLISTED_ANDROID} ]]; then editJson $fileName "blacklisted_android" "${BLACKLISTED_ANDROID}"; fi + if [[ -n ${BLOCKED_ANDROID} ]]; then editJson $fileName "blocked_android" "${BLOCKED_ANDROID}"; fi + if [[ -n ${BLOCKED_DEVICES} ]]; then editJson $fileName "blocked_devices" "${BLOCKED_DEVICES}"; fi } - generateJsonFile dev.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks" - generateJsonFile stable.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks" -- GitLab From 4ccd8cbbb863ad7e8d6bb496d27e03bce6ae22c6 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 03:35:42 +0530 Subject: [PATCH 07/20] make the create-json-files job "manual" --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a4794341b..d19f30d25 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -88,7 +88,7 @@ create-json-files: - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' - when: on_success + when: manual before_script: - apt update && apt install jq aapt -y script: -- GitLab From 4576e649ce02b7043bccf125e87884a62c3dfd7e Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 03:58:32 +0530 Subject: [PATCH 08/20] make create-json-files the first job of the release stage. --- .gitlab-ci.yml | 72 +++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d19f30d25..4d54a099c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,44 +46,10 @@ build: paths: - app/build/outputs/apk/ose/ -generate-apks: - stage: release - rules: - - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' - when: manual - needs: - - build - before_script: - - apt update && apt install apksigner -y - script: - - cd $APK_PATH - - cp $UNSIGNED_APK $DEV_APK - - cp $UNSIGNED_APK $STABLE_APK - - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_DEV - --ks-pass env:KEYSTORE_PASSWORD $DEV_APK - && echo "Signed DEV" - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_STABLE - --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK - && echo "Signed STABLE" - after_script: - - rm ~/proprietary.keystore.jks - artifacts: - paths: - - $APK_PATH/$UNSIGNED_APK - - $APK_PATH/$DEV_APK - - $APK_PATH/$STABLE_APK - create-json-files: stage: release needs: - - generate-apks + - build dependencies: - generate-apks rules: @@ -150,11 +116,45 @@ create-json-files: - dev.json - stable.json +generate-apks: + stage: release + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: on_success + needs: + - build + before_script: + - apt update && apt install apksigner -y + script: + - cd $APK_PATH + - cp $UNSIGNED_APK $DEV_APK + - cp $UNSIGNED_APK $STABLE_APK + - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_DEV + --ks-pass env:KEYSTORE_PASSWORD $DEV_APK + && echo "Signed DEV" + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_STABLE + --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK + && echo "Signed STABLE" + after_script: + - rm ~/proprietary.keystore.jks + artifacts: + paths: + - $APK_PATH/$UNSIGNED_APK + - $APK_PATH/$DEV_APK + - $APK_PATH/$STABLE_APK + create-release: stage: release needs: - - generate-apks - create-json-files + - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: on_success -- GitLab From 150095735ae177ddccfa65b1b4e25c843fa40a38 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 04:09:22 +0530 Subject: [PATCH 09/20] fix needs and dependencies --- .gitlab-ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4d54a099c..833c2f659 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,10 +48,8 @@ build: create-json-files: stage: release - needs: - - build dependencies: - - generate-apks + - build rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: manual @@ -121,7 +119,7 @@ generate-apks: rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: on_success - needs: + dependencies: - build before_script: - apt update && apt install apksigner -y -- GitLab From 593937f8ed7d9536cc9133b5f78f7086a74b9416 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 05:35:57 +0530 Subject: [PATCH 10/20] change how eOS version is suffixed in versionName --- app/build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0a81972b1..ad55cfcca 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,6 +12,8 @@ plugins { id 'kotlin-parcelize' } +def eOSVersionSuffix = "+eOS-1.0" + // Android configuration android { compileSdk 34 @@ -20,7 +22,7 @@ android { applicationId "foundation.e.accountmanager" versionCode 403090003 - versionName '4.3.9+eOS-1.0' + versionName '4.3.9' buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" @@ -63,7 +65,7 @@ android { productFlavors { ose { dimension "distribution" - versionNameSuffix "-ose" + versionNameSuffix "-ose${eOSVersionSuffix}" } } -- GitLab From 74a0897adb8824de79d03389cb2097fca9094fcf Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 06:36:18 +0530 Subject: [PATCH 11/20] add suggestions from rabbit --- .gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 833c2f659..f85354a93 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -61,7 +61,12 @@ create-json-files: # Args: filter field_name # Example: getApkInfo "package:" "versionName" getApkInfo() { - aapt dump badging $UNSIGNED_APK | grep "$1" | sed -e "s/.*$2'//" -e "s/'.*//" + result=$(aapt dump badging $UNSIGNED_APK | grep "$1" | sed -e "s/.*$2'//" -e "s/'.*//") + if [ $? -ne 0 ]; then + echo "Error: Failed to get APK info for $2" + exit 1 + fi + echo $result } - package_name="$(getApkInfo "package:" " name=")" - version_name="$(getApkInfo "package:" "versionName=")" @@ -85,7 +90,12 @@ create-json-files: jq --arg key "$key" --argjson val "$value" '.[$key] = $val' "$file" > "$tmp" 2>/dev/null } || { jq --arg key "$key" --arg val "$value" '.[$key] = $val' "$file" > "$tmp" - } && mv "$tmp" "$file" + } + if [ $? -ne 0 ]; then + echo "Error: Failed to edit JSON file $file - key: $key - value: $value" + exit 1 + fi + mv "$tmp" "$file" } - | # Generate update info about dev or stable builds. @@ -132,14 +142,24 @@ generate-apks: java -jar /usr/bin/apksigner sign --ks ~/proprietary.keystore.jks --ks-key-alias $KEYSTORE_ALIAS_DEV - --ks-pass env:KEYSTORE_PASSWORD $DEV_APK - && echo "Signed DEV" + --ks-pass env:KEYSTORE_PASSWORD $DEV_APK + - | + if [ $? -ne 0 ]; then + echo "Error: Failed to sign DEV APK" + exit 1 + fi + echo "Signed DEV" - > java -jar /usr/bin/apksigner sign --ks ~/proprietary.keystore.jks --ks-key-alias $KEYSTORE_ALIAS_STABLE - --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK - && echo "Signed STABLE" + --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK + - | + if [ $? -ne 0 ]; then + echo "Error: Failed to sign STABLE APK" + exit 1 + fi + echo "Signed STABLE" after_script: - rm ~/proprietary.keystore.jks artifacts: @@ -194,10 +214,17 @@ create-release: EOF - compressed_json=$(jq -c . data.json) - | - curl --data "$compressed_json" \ + response=$(curl --data "$compressed_json" \ --header 'Content-Type: application/json' --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \ --fail --output "/dev/null" --silent --show-error \ - --request POST https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/releases + --request POST https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/releases) + - | + if [ $? -ne 0 ]; then + echo "Error: Failed to create release" + echo "Response: $response" + exit 1 + fi + echo "Release created successfully" .update-from-upstream: stage: update-from-upstream -- GitLab From b8dff1a6a3bd3bbc1d9796daf6cddfa69cd60c61 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 17:03:26 +0530 Subject: [PATCH 12/20] move generate-apks on top again. create-json-files now depends on generate-apks --- .gitlab-ci.yml | 92 ++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f85354a93..7b29ef14b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,10 +46,56 @@ build: paths: - app/build/outputs/apk/ose/ -create-json-files: +generate-apks: stage: release + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: on_success dependencies: - build + before_script: + - apt update && apt install apksigner -y + script: + - cd $APK_PATH + - cp $UNSIGNED_APK $DEV_APK + - cp $UNSIGNED_APK $STABLE_APK + - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_DEV + --ks-pass env:KEYSTORE_PASSWORD $DEV_APK + - | + if [ $? -ne 0 ]; then + echo "Error: Failed to sign DEV APK" + exit 1 + fi + echo "Signed DEV" + - > + java -jar /usr/bin/apksigner sign + --ks ~/proprietary.keystore.jks + --ks-key-alias $KEYSTORE_ALIAS_STABLE + --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK + - | + if [ $? -ne 0 ]; then + echo "Error: Failed to sign STABLE APK" + exit 1 + fi + echo "Signed STABLE" + after_script: + - rm ~/proprietary.keystore.jks + artifacts: + paths: + - $APK_PATH/$UNSIGNED_APK + - $APK_PATH/$DEV_APK + - $APK_PATH/$STABLE_APK + +create-json-files: + stage: release + dependencies: + - generate-apks + needs: + - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: manual @@ -124,50 +170,6 @@ create-json-files: - dev.json - stable.json -generate-apks: - stage: release - rules: - - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' - when: on_success - dependencies: - - build - before_script: - - apt update && apt install apksigner -y - script: - - cd $APK_PATH - - cp $UNSIGNED_APK $DEV_APK - - cp $UNSIGNED_APK $STABLE_APK - - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_DEV - --ks-pass env:KEYSTORE_PASSWORD $DEV_APK - - | - if [ $? -ne 0 ]; then - echo "Error: Failed to sign DEV APK" - exit 1 - fi - echo "Signed DEV" - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_STABLE - --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK - - | - if [ $? -ne 0 ]; then - echo "Error: Failed to sign STABLE APK" - exit 1 - fi - echo "Signed STABLE" - after_script: - - rm ~/proprietary.keystore.jks - artifacts: - paths: - - $APK_PATH/$UNSIGNED_APK - - $APK_PATH/$DEV_APK - - $APK_PATH/$STABLE_APK - create-release: stage: release needs: -- GitLab From dad9b4f3c4848ccb6f09455dc38636bf2feaedab Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 17:14:46 +0530 Subject: [PATCH 13/20] add size information in jsons --- .gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7b29ef14b..0281d18a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -114,6 +114,16 @@ create-json-files: fi echo $result } + - | + # Args: file + getFileSizeInBytes() { + local file="$1" + if [[ -f $file ]]; then + ls -l $file | awk '{print $5}' + else + echo "0" + fi + } - package_name="$(getApkInfo "package:" " name=")" - version_name="$(getApkInfo "package:" "versionName=")" - version_code="$(getApkInfo "package:" "versionCode=")" @@ -162,6 +172,12 @@ create-json-files: } - generateJsonFile dev.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks" - generateJsonFile stable.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks" + - apk_size_dev="$(getFileSizeInBytes $DEV_APK)" + - echo "File size for - $DEV_APK - $apk_size_dev" + - editJson dev.json "size" "$apk_size_dev" + - apk_size_stable="$(getFileSizeInBytes $STABLE_APK)" + - echo "File size for - $STABLE_APK - $apk_size_stable" + - editJson stable.json "size" "$apk_size_stable" - popd - mv $APK_PATH/dev.json . - mv $APK_PATH/stable.json . -- GitLab From 8cc2605d4379683c80fa0a4e61b6a819484e11ad Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 17:44:16 +0530 Subject: [PATCH 14/20] add support for AUTHOR field --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0281d18a3..d1a3b3ba8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -167,6 +167,7 @@ create-json-files: editJson $fileName "version_name" "$version_name" editJson $fileName "url" "$url" if [[ -n ${PRIORITY} ]]; then editJson $fileName "priority" "${PRIORITY}"; fi + if [[ -n ${AUTHOR} ]]; then editJson $fileName "author" "${AUTHOR}"; fi if [[ -n ${BLOCKED_ANDROID} ]]; then editJson $fileName "blocked_android" "${BLOCKED_ANDROID}"; fi if [[ -n ${BLOCKED_DEVICES} ]]; then editJson $fileName "blocked_devices" "${BLOCKED_DEVICES}"; fi } -- GitLab From e8727e8bb54142f96b46481530e172531a8fa3be Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 18:01:26 +0530 Subject: [PATCH 15/20] add date at the end of version name --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d1a3b3ba8..94c6de7c6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -129,11 +129,13 @@ create-json-files: - version_code="$(getApkInfo "package:" "versionCode=")" - min_sdk="$(getApkInfo "sdkVersion:" "sdkVersion:")" - application_label="$(getApkInfo "application:" "label=")" + - version_name_extension="$(date +"%Y%m%d%H%M")" - echo "Package name - $package_name" - echo "Version name - $version_name" - echo "Version code - $version_code" - echo "Minimum SDK - $min_sdk" - echo "Application label - $application_label" + - echo "Version name extension - $version_name_extension" - | # Args: file_name key value # Example: editJson test.json "my_key" "my_value" @@ -164,7 +166,7 @@ create-json-files: editJson $fileName "package_name" "$package_name" editJson $fileName "version_code" "$version_code" editJson $fileName "min_sdk" "$min_sdk" - editJson $fileName "version_name" "$version_name" + editJson $fileName "version_name" "${version_name}+${version_name_extension}" editJson $fileName "url" "$url" if [[ -n ${PRIORITY} ]]; then editJson $fileName "priority" "${PRIORITY}"; fi if [[ -n ${AUTHOR} ]]; then editJson $fileName "author" "${AUTHOR}"; fi -- GitLab From f13f7aaaac8d65b7815afdd8788943544442b393 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 18:02:53 +0530 Subject: [PATCH 16/20] remove version name suffix --- app/build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ad55cfcca..5524d8c21 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,6 @@ plugins { id 'kotlin-parcelize' } -def eOSVersionSuffix = "+eOS-1.0" - // Android configuration android { compileSdk 34 @@ -65,7 +63,7 @@ android { productFlavors { ose { dimension "distribution" - versionNameSuffix "-ose${eOSVersionSuffix}" + versionNameSuffix "-ose" } } -- GitLab From aa1bb761a217c8524e732d7d1d5386b672a9cd99 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 23:34:47 +0530 Subject: [PATCH 17/20] job to init submodules to get scripts from https://gitlab.e.foundation/e/os/system-apps-gitlab-apk-release.git --- .gitlab-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 94c6de7c6..190b8665d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,6 +46,19 @@ build: paths: - app/build/outputs/apk/ose/ +init_submodules: + stage: release + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: on_success + script: + - | + git submodule add --force \ + https://gitlab.e.foundation/e/os/system-apps-gitlab-apk-release.git systemAppApkRelease + artifacts: + paths: + - systemAppApkRelease/ + generate-apks: stage: release rules: -- GitLab From 406f31d4ce36ab3df780cb9dbd662e2e0ae0d432 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 25 Jul 2024 23:35:35 +0530 Subject: [PATCH 18/20] use scripts from the new submodule --- .gitlab-ci.yml | 168 +++++-------------------------------------------- 1 file changed, 15 insertions(+), 153 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 190b8665d..96bca936a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,39 +64,18 @@ generate-apks: rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: on_success + needs: + - init_submodules + - build dependencies: + - init_submodules - build before_script: - apt update && apt install apksigner -y script: - - cd $APK_PATH - - cp $UNSIGNED_APK $DEV_APK - - cp $UNSIGNED_APK $STABLE_APK - - echo "${KEYSTORE}" | base64 -d > ~/proprietary.keystore.jks - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_DEV - --ks-pass env:KEYSTORE_PASSWORD $DEV_APK - - | - if [ $? -ne 0 ]; then - echo "Error: Failed to sign DEV APK" - exit 1 - fi - echo "Signed DEV" - - > - java -jar /usr/bin/apksigner sign - --ks ~/proprietary.keystore.jks - --ks-key-alias $KEYSTORE_ALIAS_STABLE - --ks-pass env:KEYSTORE_PASSWORD $STABLE_APK - | - if [ $? -ne 0 ]; then - echo "Error: Failed to sign STABLE APK" - exit 1 - fi - echo "Signed STABLE" - after_script: - - rm ~/proprietary.keystore.jks + ./systemAppApkRelease/scripts/generate-apks.sh \ + "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" artifacts: paths: - $APK_PATH/$UNSIGNED_APK @@ -106,8 +85,10 @@ generate-apks: create-json-files: stage: release dependencies: + - init_submodules - generate-apks needs: + - init_submodules - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' @@ -115,88 +96,9 @@ create-json-files: before_script: - apt update && apt install jq aapt -y script: - - pushd $APK_PATH - - | - # Args: filter field_name - # Example: getApkInfo "package:" "versionName" - getApkInfo() { - result=$(aapt dump badging $UNSIGNED_APK | grep "$1" | sed -e "s/.*$2'//" -e "s/'.*//") - if [ $? -ne 0 ]; then - echo "Error: Failed to get APK info for $2" - exit 1 - fi - echo $result - } - | - # Args: file - getFileSizeInBytes() { - local file="$1" - if [[ -f $file ]]; then - ls -l $file | awk '{print $5}' - else - echo "0" - fi - } - - package_name="$(getApkInfo "package:" " name=")" - - version_name="$(getApkInfo "package:" "versionName=")" - - version_code="$(getApkInfo "package:" "versionCode=")" - - min_sdk="$(getApkInfo "sdkVersion:" "sdkVersion:")" - - application_label="$(getApkInfo "application:" "label=")" - - version_name_extension="$(date +"%Y%m%d%H%M")" - - echo "Package name - $package_name" - - echo "Version name - $version_name" - - echo "Version code - $version_code" - - echo "Minimum SDK - $min_sdk" - - echo "Application label - $application_label" - - echo "Version name extension - $version_name_extension" - - | - # Args: file_name key value - # Example: editJson test.json "my_key" "my_value" - editJson() { - tmp=$(mktemp) - file="$1" - key="$2" - value="$3" - { - jq --arg key "$key" --argjson val "$value" '.[$key] = $val' "$file" > "$tmp" 2>/dev/null - } || { - jq --arg key "$key" --arg val "$value" '.[$key] = $val' "$file" > "$tmp" - } - if [ $? -ne 0 ]; then - echo "Error: Failed to edit JSON file $file - key: $key - value: $value" - exit 1 - fi - mv "$tmp" "$file" - } - - | - # Generate update info about dev or stable builds. - # Args: file_name apk_download_url - generateJsonFile() { - fileName="$1" - url="$2" - echo "{}" > $fileName - editJson $fileName "name" "$application_label" - editJson $fileName "package_name" "$package_name" - editJson $fileName "version_code" "$version_code" - editJson $fileName "min_sdk" "$min_sdk" - editJson $fileName "version_name" "${version_name}+${version_name_extension}" - editJson $fileName "url" "$url" - if [[ -n ${PRIORITY} ]]; then editJson $fileName "priority" "${PRIORITY}"; fi - if [[ -n ${AUTHOR} ]]; then editJson $fileName "author" "${AUTHOR}"; fi - if [[ -n ${BLOCKED_ANDROID} ]]; then editJson $fileName "blocked_android" "${BLOCKED_ANDROID}"; fi - if [[ -n ${BLOCKED_DEVICES} ]]; then editJson $fileName "blocked_devices" "${BLOCKED_DEVICES}"; fi - } - - generateJsonFile dev.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks" - - generateJsonFile stable.json "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks" - - apk_size_dev="$(getFileSizeInBytes $DEV_APK)" - - echo "File size for - $DEV_APK - $apk_size_dev" - - editJson dev.json "size" "$apk_size_dev" - - apk_size_stable="$(getFileSizeInBytes $STABLE_APK)" - - echo "File size for - $STABLE_APK - $apk_size_stable" - - editJson stable.json "size" "$apk_size_stable" - - popd - - mv $APK_PATH/dev.json . - - mv $APK_PATH/stable.json . + ./systemAppApkRelease/scripts/create-json-files.sh \ + "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" artifacts: paths: - dev.json @@ -204,7 +106,10 @@ create-json-files: create-release: stage: release + dependencies: + - init_submodules needs: + - init_submodules - create-json-files - generate-apks rules: @@ -214,51 +119,8 @@ create-release: - apt update && apt install jq -y script: - | - cat > data.json << EOF - { - "tag_name": "$CI_COMMIT_TAG", - "ref": "$CI_COMMIT_TAG", - "assets": { - "links": [ - { - "name": "dev.json", - "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/dev.json?job=create-json-files", - "direct_asset_path": "/json/dev.json", - "link_type": "other" - }, - { - "name": "stable.json", - "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/stable.json?job=create-json-files", - "direct_asset_path": "/json/stable.json", - "link_type": "other" - }, - { - "name": "$DEV_APK", - "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$DEV_APK?job=generate-apks", - "link_type": "package" - }, - { - "name": "$STABLE_APK", - "url": "https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/jobs/artifacts/${CI_COMMIT_TAG}/raw/$APK_PATH/$STABLE_APK?job=generate-apks", - "link_type": "package" - } - ] - } - } - EOF - - compressed_json=$(jq -c . data.json) - - | - response=$(curl --data "$compressed_json" \ - --header 'Content-Type: application/json' --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \ - --fail --output "/dev/null" --silent --show-error \ - --request POST https://gitlab.e.foundation/api/v4/projects/$PROJECT_ID/releases) - - | - if [ $? -ne 0 ]; then - echo "Error: Failed to create release" - echo "Response: $response" - exit 1 - fi - echo "Release created successfully" + ./systemAppApkRelease/scripts/create-release.sh \ + "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" .update-from-upstream: stage: update-from-upstream -- GitLab From a7c70f19aa231c0f1bcbcbc5403d31197dfd50d6 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 26 Jul 2024 16:14:08 +0530 Subject: [PATCH 19/20] change repo for submodule --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 96bca936a..01f8c8409 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,10 +54,10 @@ init_submodules: script: - | git submodule add --force \ - https://gitlab.e.foundation/e/os/system-apps-gitlab-apk-release.git systemAppApkRelease + https://gitlab.e.foundation/e/os/system-apps-update-info.git systemAppsUpdateInfo artifacts: paths: - - systemAppApkRelease/ + - systemAppsUpdateInfo/ generate-apks: stage: release @@ -74,7 +74,7 @@ generate-apks: - apt update && apt install apksigner -y script: - | - ./systemAppApkRelease/scripts/generate-apks.sh \ + ./systemAppsUpdateInfo/scripts/generate-apks.sh \ "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" artifacts: paths: @@ -97,7 +97,7 @@ create-json-files: - apt update && apt install jq aapt -y script: - | - ./systemAppApkRelease/scripts/create-json-files.sh \ + ./systemAppsUpdateInfo/scripts/create-json-files.sh \ "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" artifacts: paths: @@ -119,7 +119,7 @@ create-release: - apt update && apt install jq -y script: - | - ./systemAppApkRelease/scripts/create-release.sh \ + ./systemAppsUpdateInfo/scripts/create-release.sh \ "$APK_PATH" "$UNSIGNED_APK" "$DEV_APK" "$STABLE_APK" .update-from-upstream: -- GitLab From 788efb11642ba2b2ec2cfa84dc2668582f6d9b41 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 26 Jul 2024 18:00:38 +0530 Subject: [PATCH 20/20] suggestion --- .gitlab-ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01f8c8409..32977fdd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,11 +37,13 @@ build: - ./gradlew build -x test - cd app/build/outputs/apk/ose/ - | - if [[ -d "release" ]]; then - cd "release" - unsigned_build=$(ls *.apk | grep "unsigned") - cp $unsigned_build $UNSIGNED_APK + if [[ ! -d "release" ]]; then + echo "$APK_PATH does not exist." + exit 1 fi + cd "release" + unsigned_build=$(ls *.apk | grep "unsigned") + cp $unsigned_build $UNSIGNED_APK artifacts: paths: - app/build/outputs/apk/ose/ -- GitLab