Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GitHub Actionsのカスタムアクションを公開する

yorifuji
December 14, 2023

GitHub Actionsのカスタムアクションを公開する

yorifuji

December 14, 2023
Tweet

More Decks by yorifuji

Other Decks in Programming

Transcript

  1. GitHub ActionsͷΧελϜΞΫγϣϯΛެ։͢Δ
    2023.12.14
    YORIFUJI MITSUNORI

    View full-size slide

  2. ࣗݾ঺հ
    • YORIFUJI MITSUNORI
    • @yorifuji on X / GitHub / Zenn
    • ۚ༥ܥελʔτΞοϓͷiOSΤϯδχΞ

    View full-size slide

  3. ࠓ೔ͷൃද͸ͪ͜ΒͷهࣄΛϕʔεʹͨ͠಺༰ʹͳΓ·͢
    https://zenn.dev/yorifuji/articles/feec2c0294c7f9

    View full-size slide

  4. GitHub Actions
    https://github.co.jp/features/actions

    View full-size slide

  5. GitHub ActionsͰFlutterͷ
    ੩తղੳΛ࣮ߦ͢ΔϫʔΫ
    ϑϩʔͷྫʢyamlϑΝΠ
    ϧʣ
    name: check
    on: pull_request
    permissions:
    contents: read
    jobs:
    analysis:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: subosito/flutter-action@v2
    - run: flutter pub get
    - run: flutter analyze

    View full-size slide

  6. ࠓճ͸ϫʔΫϑϩʔͷ࡞Γ
    ํͰ͸ͳ͘ɺϫʔΫϑϩʔ
    Ͱར༻͢ΔΞΫγϣϯΛ࡞
    ੒͢Δ࿩
    name: check
    on: pull_request
    permissions:
    contents: read
    jobs:
    analysis:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: subosito/flutter-action@v2
    - run: flutter pub get
    - run: flutter analyze

    View full-size slide

  7. ࢲ͕࡞੒ɾެ։ͨ͠ΞΫγϣϯ͸ͪ͜Β☝
    https://github.com/marketplace/actions/
    fl
    utter-analyze-commenter

    View full-size slide

  8. CIʢ੩తղੳʣ͕ࣦഊͨ࣌͠ʹϩάͷ಺༰Λ֬ೝ͢Δͷ͸໘౗

    View full-size slide

  9. Flutterͷιʔείʔυͷ੩తղੳͷ
    ݁ՌΛPull RequestʹϨϏϡʔίϝ
    ϯτͱͯ͠ॻ͖ࠐΉΞΫγϣϯΛ࡞
    ੒͠·ͨ͠

    View full-size slide

  10. ࢖͍ํ͸ϫʔΫϑϩʔʹ
    ΞΫγϣϯΛ௥Ճ͢Δͩ
    ͚
    name: flutter-analyze-commenter example
    on: pull_request
    permissions:
    contents: read
    pull-requests: write
    jobs:
    analysis:
    runs-on: ubuntu-latest
    steps:
    ...
    - run: flutter analyze --write=flutter_analyze.log
    - uses: yorifuji/flutter-analyze-commenter@v1
    if: ${{ !cancelled() }}
    with:
    analyze_log: flutter_analyze.log

    View full-size slide

  11. ݩʑ͸ผͷπʔϧΛར༻͍ͯͨ͠
    • Problem MatchersͱDangerΛ૊Έ߹Θͤͯಉ༷ͷ࡞ۀΛߦͳ͍ͬͯͨ
    • ҎԼͷ఺͕ෆຬ
    • 2ͭπʔϧͰίϝϯτͷϑΥʔϚοτͷڍಈʹҧ͍͕͋Δ
    • ϫʔΫϑϩʔͷଞʹ΋ϑΝΠϧͷ഑ஔͳͲͷηοτΞοϓ͕ඞཁ
    • Danger͸ߴػೳͰଟ༻్Ͱ͋Δ൓໘ɺRubyͷґଘϥΠϒϥϦͷΠϯε
    τʔϧ͕ඞཁɺΦʔόʔεϖοΫʹײ͍ͯͨ͡

    View full-size slide

  12. ࡞੒ͨ͠ΞΫγϣϯ΁ͷ৐Γ׵͑Ͱ࡟আͰ͖ͨϑΝΠϧɾϫʔΫϑϩʔͷهड़

    View full-size slide

  13. ΞΫγϣϯΛ࡞ͬͯެ։͢Δํ๏

    View full-size slide

  14. GitHub Marketplace
    • GitHubެࣜɾOSSͷGitHub Apps΍ΞΫγϣϯ͕ެ։͞Ε͍ͯΔ
    • ୳ͤ͹ඞཁͳ΋ͷ͸େମ͋Δ
    • Ϩϐϡςʔγϣϯʢ⭐ʣ͕গͳ͍ϚΠφʔͳActionΛར༻͢Δͱ͖͸
    ηΩϡϦςΟϦεΫͳͲʹ஫ҙ

    View full-size slide

  15. MarketplaceʹΞΫγϣϯΛొ࿥͢Δखॱ
    • ͜Ε͚ͩ
    • GitHubʹpublic repositoryΛ࡞੒
    • ΞΫγϣϯͷఆٛΛॻ͍ͨaction.ymlΛ࡞੒
    • ΧελϜΞΫγϣϯͷॲཧΛ࣮૷
    • GitHub্ͰReleaseΛ࡞੒ͯ͠ެ։
    • ৄ͍͠खॱ͸ͪ͜Β
    • https://docs.github.com/ja/actions/creating-actions/publishing-actions-in-github-
    marketplace

    View full-size slide

  16. action.yml ͷهड़ྫʢ࣮ࡍͷΞΫγϣϯ͔Βൈਮʣ
    name: "Flutter Analyze Commenter"
    description: "Auto comment on PRs based on Flutter Analyze results"
    inputs:
    analyze_log:
    description: "Path to the Flutter analyze log"
    required: true
    runs:
    using: composite
    steps:
    - uses: actions/github-script@v7
    env:
    ANALYZE_LOG: ${{ inputs.analyze_log }}
    VERBOSE: ${{ inputs.verbose }}
    with:
    script: |
    const analyzeLog = process.env.ANALYZE_LOG;
    ...

    View full-size slide

  17. ΧελϜΞΫγϣϯͷ࣮૷ํ๏
    • Docker ίϯςφʔ ΞΫγϣϯ
    • ίϯςφΛ࢖࣮ͬͯߦ؀ڥΛύοέʔδԽ͢Δํࣜ
    • ඞཁͳπʔϧ΍ґଘؔ܎ΛίϯςφͰ؅ཧͰ͖ΔͷͰҰ؏ੑͱ৴པੑΛ୲อ͠΍͍͢
    • ݱঢ়͸Linuxʢubuntuʣ ͷϥϯφʔͰͷΈར༻Ͱ͖ΔʢmacOS΍Windows͸ར༻ෆՄʣ
    • JavaScript ΞΫγϣϯ
    • Node.jsΛ࢖ͬͯJavaScriptͷίʔυΛ࣮ߦ͢ΔΞΫγϣϯ
    • TypeScriptͰͷ։ൃ΋Մೳʢ࠷ऴతʹJavaScript͕ੜ੒Ͱ͖ΔͳΒͳΜͰ΋ྑ͍ʣɺෳࡶͳ࣮૷Λ͢ΔͳΒ͓͢͢Ί
    • ෳ߹ΞΫγϣϯʢComosite Actionʣ
    • ීஈ࢖͍ͬͯΔϫʔΫϑϩʔ͔ΒॲཧΛ੾Γग़͢Πϝʔδ
    • γΣϧεΫϦϓτͰͷ࣮૷͕جຊ
    • uses: ͕ར༻ՄೳͳͷͰ௨ৗͷΞΫγϣϯ΋ར༻Ͱ͖Δ

    View full-size slide

  18. actions/github-script
    // ྫɿhello world
    - uses: actions/github-script@v7
    with:
    script: console.log('Hello, JavaScript')
    // ྫɿGithubͷREST APIΛ࢖ͬͯIssueΛऔಘ
    - uses: actions/github-script@v7
    with:
    script: |
    github.rest.issues.get({
    issue_number: context.issue.number,
    owner: context.repo.owner,
    repo: context.repo.repo,
    })
    • ෳ߹ΞΫγϣϯͰJavaScriptΛ࢖ͬͨॲ
    ཧΛهड़Ͱ͖ΔΞΫγϣϯ

    View full-size slide

  19. ࡞੒ͨ͠ΧελϜΞΫγϣϯͷ࣮૷ৄࡉ
    • Flutterͷ੩తղੳͷग़ྗ಺༰ʢςΩετʣΛղੳͯ͠ϑΝΠϧ໊ɺߦ൪߸ɺ
    ϝοηʔδʢܯࠂʣͳͲΛऔಘ͢Δ
    • ϑΝΠϧ໊ɾߦ൪߸ɾϝοηʔδΛ΋ͱʹGitHubͷREST APIΛ࢖ͬͯPRʹ
    ରͯ͠ॻ͖ࠐΉ
    • PRʹରͯ͠मਖ਼ʢ௥Ճʣίϛοτ͕ൃੜͨ͠Βݹ͘ͳͬͨʢOutdatedͳʣ
    ίϝϯτΛߋ৽ or ࡟আ
    • PR͔ΒίϝϯτΛશ݅औಘͯ͠࠷৽ͷ੩తղੳͷ݁Ռͱಥ߹

    View full-size slide

  20. ϦϦʔε࡞ۀ
    • ։ൃ͕ऴΘͬͨΒGitHub্ͰReleaseΛ
    ࡞੒͢Δ
    • ϦϙδτϦͷτοϓʹaction.yml͕ଘࡏ
    ͢ΔͱΞΫγϣϯઐ༻ͷReleaseը໘͕
    දࣔ͞ΕΔ
    • Marketplace΁ͷpublishΛࢦఆͰ͖Δ
    • ymlهड़಺༰ɺREADMEͷνΣοΫ

    View full-size slide

  21. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide