danger-apkstats icon indicating copy to clipboard operation
danger-apkstats copied to clipboard

How to use the report feature

Open afaucogney opened this issue 6 years ago • 1 comments

The report about comparing apks seems to be promissing, but at operationnal level, how do you handle it ?

If you build apk with CI, how can you cache previous apk version, or just the apk on the develop branch you are trying to request merge ?

I know it is case to case situation, but experience is welcome.

afaucogney avatar Dec 18 '18 14:12 afaucogney

Thank you for your interest. :)

For my work, our use case is like below.

  • Apks should be compared with the latest production apk
  • Apks to be compared are close to the production builds as much as possible. e.g. proguard settings
  • Our team is managing the production apks on GitHub Releases

Therefore, we need to download the latest apk from GitHub Releases, so the script is also simple.

#!/usr/bin/env bash

set -o pipefail
set -eu

GITHUB_USERNAME="..."
GITHUB_REPONAME="..."
GITHUB_API_TOKEN_USERNAME="..."
: "${GITHUB_API_TOKEN:=$DANGER_GITHUB_API_TOKEN}"

latest_gh_release() {
    curl -#L -H "Authorization: token $GITHUB_API_TOKEN" "https://api.github.com/repos/$GITHUB_USERNAME/$GITHUB_REPONAME/releases/latest"
}

get_asset_url() {
    cat - | ruby -rjson -e 'puts JSON.parse(STDIN.read)["assets"].select { |j| j["name"].end_with?(".apk") }.map { |j| j["url"] }.first'
}

download_latest_apk() {
    local asset_url=$(latest_gh_release | get_asset_url)

    curl -#Lo "$1" -u "$GITHUB_API_TOKEN_USERNAME:$GITHUB_API_TOKEN" -H 'Accept: application/octet-stream' "$asset_url"
}

# $1 is a filename
download_latest_apk "$1"

If you would like to use CI's cache or download assets from CI, it would be more complex than my usecase.

jmatsu avatar Dec 22 '18 12:12 jmatsu