Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

GitHub composite actions

GitHub composite actions

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

Hiroyuki Kusu

March 13, 2024
Tweet

More Decks by Hiroyuki Kusu

Other Decks in Technology

Transcript

  1.  composite actions ? • GitHub custom actions ͷ࡞Γํͷ1ͭ •

    ଞʹ͸ Docker container actions ͱ JavaScript actions ͕͋Δ • ෳ਺ͷ step Λ 1ͭͷ action ʹ·ͱΊΒΕΔ • ެ։͞Ε͍ͯΔطଘͷ action ΋ར༻Ͱ͖Δ • ීஈ GitHub Actions ͷϫʔΫϑϩʔͷ YAML Λॻ͘ײ֮Ͱ࡞ΕΔ • ϩδοΫ෦෼͸ओʹ Shell script Ͱॻ͘͜ͱʹͳΔ • େ͖ͳػೳͷ։ൃʹ͸޲͔ͳͦ͏ uses: actions/setup-java@v4 custom actions ͷར༻ྫ
  2.  name: "Setup Java - Gradle" description: "A GitHub Action

    that sets up a Java and Gradle environment." author: "YUMEMI Inc." branding: icon: "box" color: "blue" inputs: java-version: description: "Java version to use." required: false default: "17" // ... kotlin-compiler-report: description: "Whether to apply Kotlin compiler Problem Matchers." required: false default: "true" runs: using: "composite" steps: - name: Setup Java uses: actions/setup-java@v4 with: distribution: ${{ inputs.java-distribution }} java-version: ${{ inputs.java-version }} - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: cache-disabled: ${{ inputs.cache-disabled }} cache-read-only: ${{ inputs.cache-read-only }} gradle-home-cache-cleanup: ${{ inputs.gradle-home-cache-cleanup }} add-job-summary: ${{ inputs.gradle-build-report }} - name: Setup Problem Matchers if: inputs.kotlin-compiler-report != 'false' uses: yumemi-inc/problem-matchers/kotlin-gradle@v1 composite action ͷத਎ͷྫ https://github.com/yumemi-inc/setup-java-gradle action.yml ͱͯ͠ϦϙδτϦʹอଘ͢Ε͹ ผϦϙδτϦͷϫʔΫϑϩʔ͔Β uses Ͱ ར༻Ͱ͖ΔʢಉҰϦϙδτϦͷϫʔΫϑ ϩʔ͔Βར༻͢Δͷ΋Մʣ
  3.  ͜Ε·Ͱࢲ͕࡞੒ͨ͠ composite action • Ұൠެ։Ͱ͖Δ΋ͷ͸ࣾͷ public ϦϙδτϦʹஔ͍ͯ͋Δ • ಺੡Խࢧԉͱ͍͏ۀ຿ͷੑ্࣭ɺࣾ֎ͷ

    GitHub organization Ͱ΋ར༻ Ͱ͖ΔΑ͏ʹ • GitHub Marketplace Ͱ΋ެ։ • Marketplace Ͱެ։͠ͳͯ͘΋ར༻Ͱ͖Δ͕ɺͰ͖Δ͚ͩ෯޿͍ਓʹ ࢖ͬͯ΋Β͏ҝʹ • ୯७ʹ OSS తͳߩݙͷ໨త • ͱ͸͍͑Ұൠެ։Ͱ͖ͳ͍΋ͷ΍ࣾ಺͚ͩͰ࢖͏΋ͷ͸ private ϦϙδτϦͰ
  4.  Gradle Dependency Diff Report • 1ͭͷϥΠϒϥϦͷόʔδϣϯΛม͑ͨΒҶͮΔࣜʹผͷϥΠϒϥϦͷόʔ δϣϯ΋มΘͬͯ͠·͏ • Renovate

    ΍ Dependabot ͸લऀͷ1ͭͷϥΠϒϥϦͷ͜ͱҎ֎͸ڭ͑ͯ ͘Εͳ͍ • ͳͷͰϥΠϒϥϦͷґଘؔ܎ͷมԽΛ Job Summaries ΁Ϩϙʔτ͢Δ action Λ࡞ͬͨ • ϨϏϡʔ࣌ʹ׆༻
  5.  Comment Pull Request • ϓϧϦΫ΁ίϝϯτΛ౤ߘ͢Δ action • աڈͷίϝϯτΛফͨ͠ΓӅͨ͠ΓͰ͖Δ •

    ςετ݁ՌͷϨϙʔτ౤ߘͳͲɺ࠷ޙͷίϛοτʹର͢Δ CI ͷ݁ՌͷΈ ʹؔ৺͕͋ΔΑ͏ͳέʔεͰར༻
  6.  Path Filter • ઌఔͷ Changed Files ͸ɺGitHub API Λར༻͍ͯ͠Δ͜ͱʹΑΔ੍໿͕

    ͋ͬͨʢREADME ʹ΋ͦͷࢫΛهࡌࡁΈʣͷͰɺগ͠ػೳΛল͖ͭͭ GitHub API Λར༻͠ͳ͍ํࣜͰ࣮૷͠௚ͨ͠ • ͍ͣΕল͍ͨػೳΛऔΓࠐΜͰɺ͜ͷ Path Filter ʹ̍ຊԽ͢Δ༧ఆ
  7.  Problem Matchers for Kotlin - Gradle • Kotlin ίϯύΠϧ࣌ͷϫʔχϯά/ΤϥʔΛ

    annotation ͱͯ͠ϓϧϦΫͷม ߋϑΝΠϧλϒͱ Job Summaries ΁දࣔ • Kotlin 1.7 Ҏલͱ 1.8 Ҏ߱ͷ྆ϑΥʔϚοτʹରԠ • GitHub ͷ੍໿ʹΑΓɺannotation ͷ਺ʹ͸ݶΓ͕͋Δ
  8. Setup Java - Gradle • Gradle λεΫ࣮ߦલͷ֤छηοτΞοϓΛ 1 step Ͱॻ͚ΔΑ͏ʹͨ͠΋ͷ

    • ಺෦Ͱ࢖༻͍ͯ͠Δ gradle/gradle-build-action Λͦͷ··Կ΋ߟ͑ͣ࢖͏ ͱσϑΥϧτϒϥϯνʹແҙຯʹΩϟογϡ͕େྔʹ࡞੒͞ΕͨΓɺٯʹϓ ϧϦΫͰΩϟογϡ͕Ұ੾ hit ͠ͳ͔ͬͨΓ͢ΔͷͰɺΩϟγϡ࡞੒͸جຊ ͸ off ͷܗͰϥοϓ͠ɺREADME ͰΩϟγϡͷӡ༻ʹ͍ͭͯิ଍ͨ͠ 
  9. ॴײ΍ Tips ͳͲ • σϑΥϧτͰར༻Ͱ͖Δ jq ΍ GitHub CLI ͕ศར

    • GitHub CLI ͸ GraphQL ΋ୟ͚Δ • Ҏલ͸؆୯ͳ custom action Ͱ΋ JavaScriptʢJavaScript actionsʣͰ࡞ͬ ͍͕ͯͨɺఆظతʹ Node.js ͷόʔδϣϯ΍੬ऑੑͷ͋ΔϥΠϒϥϦͷߋ ৽͕ඞཁͩͬͨͷͰɺͦͷख͕ؒͳ͍ • ͨͩෳࡶͳ΋ͷΛ࡞Ζ͏ͱ͢Δͱ Shell script ྗ͕໰ΘΕΔ͔΋ʁ 
  10. JavaScript ΍طଘͷ npm ͷύοέʔδΛ࢖͍͍ͨ৔߹ • actions/github-script action Λར༻ͯ͠ JavaScript ͕ॻ͚Δ

    • npm ͷύοέʔδΛར༻͢Δྫ͸ɺઌ΄Ͳ঺հͨ͠ Path Filterʢyumemi- inc/path- fi lterʣͷίʔυதʹ͋Γ·͢ • @vercel/ncc Ͱόϯυϧͨ͠΋ͷΛ require() ͰಡΈࠐΜͰ͍Δ 
  11. ̏ͭͷ runner OS ͷߟྀ • GitHub-hosted runner ͷ OS ͸̏ͭʢUbuntuɺmacOSɺWindowsʣ͋Δ

    • Shell script Λ Bash Ͱॻ͘ݶΓ͸ɺಉ͡ॻ͖ํͰ͍͍ͩͨΑ͍͕ɺԼهͷ ҧ͍͕͋Δ͜ͱʹ஫ҙ • Windows OS ͷվߦίʔυ • OS ʹΑͬͯଘࡏ͠ͳ͍ɾڍಈ͕ҟͳΔίϚϯυ͕͋Δ • ։ൃ࣌ͷ CI Λ̏ͭͷ OS Ͱճ͢ͱΑ͍ • public ϦϙδτϦͳΒແྉͳͷͰ࣌ؒΛؾʹͤͣճͤΔ