Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Android の CI(GitHub Actions)の改善で、最近やったこと

Android の CI(GitHub Actions)の改善で、最近やったこと

YUMEMI.grow Mobile #1 ( https://yumemi.connpass.com/event/272491/ ) の資料

Hiroyuki Kusu

March 07, 2023
Tweet

More Decks by Hiroyuki Kusu

Other Decks in Technology

Transcript

  1. 

  2. 

  3.  - uses: actions/checkout@v 3 - uses: actions/setup-java@v 2 with

    : java-version: 1 1 distribution: 'zulu ' - run: ./gradlew assembleDebu g - uses: hkusu/s3-upload-action@v 2 id: uploa d with : aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID } } aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY } } aws-region: 'ap-northeast-1 ' aws-bucket: ${{ secrets.AWS_BUCKET } } file-path: './app/build/outputs/apk/debug/app-debug.apk ' output-file-url: 'true ' content-type: 'application/vnd.android.package-archive ' output-qr-url: ‘true ' public: 'true ' - ... ͋ͱ͸ϚʔΫμ΢ϯܗࣜͷը૾ϦϯΫ ![QR](${{ steps.upload.outputs.qr-url }}) Λίϝϯτ͢Ε͹OK ※ ͋Β͔͡Ί Amazon S3 ͷ bucket Λͻͱͭ༻ҙ͓ͯ͘͠ඞཁ͕͋Γ·͢ apkϑΝΠϧμ΢ϯϩʔυ༻ͷHTTPϨεϙϯεϔομ
  4.  • ϨϏϡΞʔ͕खݩͷ࣮ػͰଈ࠲ʹಈ࡞ΛݟΔ͜ͱ͕Ͱ͖Δ • खݩͰίʔυΛνΣοΫΞ΢τͯ͠Ϗϧυ͢Δख͕ؒͳ͍ • Slack ΍ϝʔϧͰͷ URL ͷ௨஌ͱҧ͍ɺͲͷϓϧϦΫΤετͷͲͷίϛοτ

    ʹରͯ͠Ϗϧυ͞ΕͨΞϓϦͳͷ͔෼͔Γ΍͍͢ • ͨͩ public ͳ URL Ͱ͋ΔͷͰར༻γʔϯʹ͍ͭͯ͸஫ҙ • ར༻͢Δ৔߹Ͱ΋ URL ʹ༗ޮظݶ͸ઃ͚͓͍ͯͨํ͕Α͍ • S3 ͷϥΠϑαΠΫϧͷઃఆͰɺҰఆظؒͰ apk ϑΝΠϧΛࣗಈ࡟আ • ·ͨ͸ S3 ͷ Presigned URL Λར༻ʢ͜ͷ Action ͷΦϓγϣϯͰར༻Մʣ • ༗ޮظݶ͕੾Εͯ΋ϫʔΫϑϩʔΛ࠶࣮ߦ͢Ε͹ QR ίʔυ͸࠶ੜ੒͞ΕΔ
  5.  • runner Λز͔ͭ࡞ͬͯ group ʹͿΒԼ͛Δ • ୯ମͷ runner ΋εέʔϧ͢Δ͕ɺ͍·ݱࡏ

    ͸εέʔϧʹ͕͔͔࣌ؒΔҝɺrunner Λͨ ͘͞Μ࡞Δ͜ͱͰෳ਺ϫʔΫϑϩʔɾδϣϒ ͔Βͷಉ࣌ར༻ʹඋ͑Δ
  6.  jobs : hoge : env : GRADLE_OPTS: ‘-Dorg.gradle.parallel=true -Dorg.gradle.jvmargs=-Xmx5120m

    ' runs-on : group: android-ci-ubuntu-22.0 4 steps : ... ࡞੒ͨ͠άϧʔϓΛࢦఆ • ؀ڥม਺ GRADLE_OPTS Ͱ Gradle ͷΦϓγϣϯΛࢦఆ • Φϓγϣϯ͸ϓϩδΣΫτͷ Gradle ϑΝΠϧͰఆٛͯ͠΋Α͍͕ɺϩʔΧϧ։ൃͱ CI Ͱ෼͚ͨํ͕Αͦ͞͏ͳͷͰɺ͜ͷΑ͏ʹ؀ڥม਺Ͱࢦఆ͢Δͷ͕ศར • parallel ʹ͢Δ͜ͱͰɺlarger runners ͷ CPU ίΞΛ࠷େݶɺ׆༻ͤ͞Δ • larger runners ͸ϝϞϦ΋ଟ͘ੵΜͰ͍ΔͷͰɺ5G Λࢦఆʢ΋ͬͱଟͯ͘΋Α͍͔΋ʣ
  7.  • ࠓճͷྫͰ͸ 8 core ͷ runner Λར༻͍ͯ͠Δ͕ 4 core

    Ͱ΋े෼͔΋͠Ε ͳ͍ʢ࠷େ͸ 64 coreʣ • larger runers ͸ core ਺ʹൺྫͨ͠՝ֹۚͱͳΔ͕ɺେ఍ͷ Gradle λεΫ ͸ core ਺Λ 2 ഒʹ͔ͨ͠Βͱ͍ͬͯ଎౓͕ 1/2 ʹͳΔ༁Ͱ͸ͳ͍ • ίεύͱ͍͏ҙຯͰ͸Α͘ͳ͍ • ྫ͑͹ϓϧϦΫ࣌ͷϫʔΫϑϩʔͳͲɺ଎౓Λ༏ઌ͍ͨ͠৔߹ͷΈར༻ ͢Δͷ͕Αͦ͞͏ • larger runners ͸ແྉ࿮ͷର৅֎ͳͷͰ஫ҙ
  8.  jobs : hoge : env : GRADLE_OPTS: ‘-Dorg.gradle.daemon=false -Dorg.gradle.caching=true

    ' runs-on: ubuntu-22.0 4 steps : - uses: actions/checkout@v 3 - uses: actions/setup-java@v 2 with : java-version: 1 1 distribution: 'zulu ' - uses: actions/cache@v 3 with : path: | ~/.gradle/cache s ~/.gradle/wrappe r ~/.android/build-cach e key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle- wrapper.properties', '**/buildSrc/**/*.kt', '**/libs.versions.toml') } } restore-keys: ${{ runner.os }}-gradle - - ... Gradle ͷϏϧυΩϟογϡΛ༗ޮԽ actions/caches Λར༻͢Δࡍ͸σʔϞϯΛແޮԽ͓ͯ͘͜͠ͱ ͍ͭͰʹ Android ͷϏϧυΩϟογϡ΋ར༻ Gradle ͷϏϧυΩϟογϡ͸ґଘϥΠϒϥϦͷΩϟογϡͱڞʹ ͜ͷσΟϨΫτϦ഑Լʹؚ·ΕΔ
  9.  • CI ͰޮՌΛಘΔͷ͸೉͍͠ʁฐࣾͰ͸େ͖ͳޮՌ͸ײ͡ΒΕͳ͔ͬͨ • ಉ͡ίʔυ͔ͭಉ͡ Gradle λεΫΛ୯७ʹ࠶࣮ߦ͢Δ৔໘Ͱ͸͔ͨ͠ʹ଎͍ • ͨͩ

    CI Ͱ͸Ωϟογϡͨ࣌͠఺ͱར༻͢Δ࣌఺Ͱίʔυ͕มԽ͍ͯ͠Δ͜ͱ͕ຆͲ • ࣮ߦ͍ͨ͠ Gradle λεΫຖ·ͨ͸શ෦ೖΓͷΩϟογϡΛ༻ҙ͓ͯ͘͠ͷ͕೉͍͠ • GitHub Ͱ͸Ωϟογϡ͸τʔλϧ 10 G ·Ͱͱ͍͏੍ݶ΋͋Δ • ϩʔΧϧ։ൃ࣌ͱҧ͍ɺ։ൃͰੵΈ্͕ͬͨΩϟογϡ͕ར༻Ͱ͖Δ༁Ͱ͸ͳ͍ • ͱ͸͍͑େ͖ͳσϝϦοτ͸ແ͍ͷͰɺؾ࣋ͪఔ౓ʹಋೖ͓͍ͯͯ͠΋Αͦ͞͏ • σϝϦοτ͸ΩϟογϡαΠζ͕গ͠େ͖͘ͳΔ͙Β͍ʁ • Ұճ໨ͷ Gradle λεΫͰ͋ͬͯ΋ɺλεΫ࣮ߦதͷ੒Ռ෺ͷ࠶ར༻͕ߦΘΕΔ