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

GitHub Actionsのカスタムアクションを作成してMarketplaceで公開した話

yorifuji
November 29, 2023

GitHub Actionsのカスタムアクションを作成してMarketplaceで公開した話

yorifuji

November 29, 2023
Tweet

More Decks by yorifuji

Other Decks in Programming

Transcript

  1. GitHub ActionsͷΧελϜΞΫγϣϯΛ
    ࡞੒ͯ͠MarketplaceͰެ։ͨ͠࿩
    2023.11.30


    YORIFUJI MITSUNORI

    View full-size slide

  2. ࣗݾ঺հ
    • YORIFUJI MITSUNORI


    • @yorifuji on X / GitHub / Zenn


    • ۚ༥ܥελʔτΞοϓͷiOSΤϯδχΞ


    • ݸਓ޲͚౤ࢿΞϓϦʢSwiftʣ΍ۚ༥ػؔ޲͚ͷۀ຿ΞϓϦʢFlutterʣͷ։ൃ


    • લ৬͸௨৴ձࣾͷSIerͰB2BαʔϏεͷ։ൃͳͲ͍Ζ͍Ζʢ10೥ʙʣ


    • Flutterྺ͸2೥ఔ౓ɺFlutterେֶ͸1೥΄Ͳલʹೖձ -> Ұ౓ୀձͯ͠࠶౓Join


    • #ڞಉ։ൃ14_sansen ʹࢀઓͯ͠·͢

    View full-size slide

  3. ϞόΠϧΞϓϦ޲͚ͷओཁͳCIαʔϏε

    View full-size slide

  4. ֤ࣾͷCIαʔϏεͷಛ௃ʢݸਓͷײ૝ʣ
    • Bitrise


    • ࿝ฮɺ҆ఆ͍ͯͯ͠ރΕ͍ͯΔɺAndroid΍iOSωΠςΟϒͷ஌͕ࣝ׆͔ͤΔ


    • Codemagic


    • ޙൃɺFlutterʹಛԽͯ͠ΔʢFlutter SDK͕ΠϯετʔϧࡁΈʣɺ͕ҙ֎ͱ͕݀͋ΔʢރΕ͍ͯͳ͍ʣ


    • GitHub Actions


    • ΦʔϧϚΠςΟɺpublicϦϙδτϦͰͷར༻͸ແྉɺGitHubͱͷ࿈ܞ͕ڧΈ


    • Xcode Cloud


    • Apple७ਖ਼CIɺূ໌ॻ؅ཧ͕ෆཁɺXcode࿈ܞɺ͍҆ɺFlutterʹ͸ෆ޲͖

    View full-size slide

  5. ࠓ೔ͷൃදͰ͸CI/CDʹؔ͢Δৄ͍͠ղઆ͸লུ
    ͍ͯ͠·͢


    աڈͷษڧձಈըʹղઆಈը͕ͨ͘͞Μࡌ͍ͬͯ
    ΔͷͰͦͪΒΛ͝ཡ͍ͩ͘͞

    View full-size slide

  6. About GitHub Actions
    • GitHubʹ౷߹͞ΕͨCIػೳ


    • ଞࣾ੡ͷCI/CDαʔϏεͷαΠϯΞοϓ΍GitHub࿈ܞ͕ෆཁ


    • GitHub্Ͱൃੜ͢ΔΠϕϯτΛτϦΨʔʹϫʔΫϑϩʔʢδϣϒʣΛ࣮ߦͰ͖Δ


    • ྫʣϓϧϦΫΤετ͕࡞੒͞ΕͨΒςετΛ࣮ߦ

    View full-size slide

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

    View full-size slide

  8. ࠓ೔࿩͢ͷ͸ϫʔΫϑϩʔͰ
    ར༻͢ΔΞΫγϣϯͷํ
    name: check
    on: pull_request
    permissions:
    contents: read
    jobs:
    test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: subosito/flutter-action@v2
    - run: flutter pub get
    - run: flutter test

    View full-size slide

  9. ઌ೔ɺࣗ࡞ͷGitHub ActionΛެ։͠·ͨ͠🎉


    https://github.com/marketplace/actions/
    fl
    utter-analyze-commenter

    View full-size slide

  10. Flutterͷ੩తղੳ
    • VSCode΍
    fl
    utter analyzeίϚϯυͰग़ྗ͞ΕΔίϨ


    • Error / Warning / Info ͷ3Ϩϕϧ


    • ඪ४Ͱ͸
    fl
    utter_lintsʹఆٛ͞Εͨϧʔϧʹج͍ͮͯղੳ


    • pedantic_mono΍very_good_analysis͕͓͢͢Ί

    View full-size slide

  11. Flutterͷ੩తղੳͷ݁ՌΛ


    Pull Requestʹίϝϯτ͢Δ


    ΧελϜΞΫγϣϯ

    View full-size slide

  12. ࢖͍ํ͸stepʹ௥Ճ͢Δ
    ͚ͩ
    name: flutter-analyze-commenter example
    on: pull_request
    permissions:
    contents: read
    pull-requests: write
    jobs:
    flutter-analyze:
    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

  13. GitHub Marketplace

    View full-size slide

  14. GitHub Marketplace


    https://github.com/marketplace

    View full-size slide

  15. GitHub Marketplace
    • GitHubެࣜɾOSSɾݸਓ͕࡞੒ͨ͠GitHub Apps΍ΞΫγϣϯ͕ެ։͞
    Ε͍ͯΔ


    • ΞΫγϣϯͰݕࡧ͢Δͱ 20,940 results


    • ඞཁͳ΋ͷ͸େମ͋Δ͕⭐͕গͳ͍ϚΠφʔͳActionΛར༻͢Δͱ͖͸
    ηΩϡϦςΟϦεΫͳͲʹ஫ҙ͕ඞཁ

    View full-size slide

  16. actions/checkout
    • CIͷδϣϒͰϦϙδτϦΛclone͢ΔGitHubެࣜΞΫγϣϯ

    View full-size slide

  17. subosito/
    fl
    utter-action
    • Flutterͷ؀ڥߏஙʢSDKͷΠϯετʔϧʣΛ͢ΔΞΫγϣϯ

    View full-size slide

  18. ࣗ࡞ͷΞΫγϣϯΛMarketplaceʹొ࿥͢Δखॱ
    • खॱ


    • GitHubʹpublic repositoryΛ࡞੒


    • ΞΫγϣϯͷఆٛΛॻ͍ͨaction.ymlΛ࡞੒


    • ΧελϜΞΫγϣϯͷ಺༰Λ࣮૷


    • GitHub ্ͰReleaseΛ࡞੒ͯ͠ެ։


    • ৄ͍͠खॱ͸ͪ͜Β


    • https://docs.github.com/ja/actions/creating-actions/about-custom-actions


    • ॳճʹར༻ن໿΁ͷಉҙ͕ඞཁ


    • https://docs.github.com/en/site-policy/github-terms/github-marketplace-developer-agreement

    View full-size slide

  19. ิ଍ɿ࡞ͬͨΞΫγϣϯΛެ։ͨ͘͠ͳ͍࣌
    • ࣗ෼ͷϦϙδτϦ͚ͩͰ࢖͍͍ͨɺχονͳ༻్ɺetc


    • ͦͷΑ͏ͳ৔߹͸privateϦϙδτϦʹΧελϜΞΫγϣϯΛ࡞੒͢Ε
    ͹OKɺϦϙδτϦΛpublicʹͨ͠ΓMarketplaceʹొ࿥͢Δඞཁ͸ͳ
    ͍


    • CIΛ࣮ߦ͢ΔϦϙδτϦଆ͔ΒΧελϜΞΫγϣϯͷϦϙδτϦʹΞ
    Ϋηε͕Ͱ͖Ε͹ΞΫγϣϯΛར༻Ͱ͖Δ

    View full-size slide

  20. ࣮ࡍͷaction.yml ͷྫ


    ࠨɿΧελϜΞΫγϣϯͷఆٛɺӈɿCIͰݺͼग़͢ίʔυͷྫ
    name: "Flutter Analyze Commenter"
    author: "yorifuji"
    inputs:
    analyze_log:
    description: "Path to the Flutter analyze log"
    required: true
    verbose:
    description: "Enable verbose logging"
    default: false
    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;
    ...
    jobs:
    flutter-analyze:
    runs-on: ubuntu-latest
    steps:
    ...
    - run: flutter analyze --write=flutter_analyze.log
    - uses: yorifuji/flutter-analyze-commenter@v1
    with:
    analyze_log: flutter_analyze.log

    View full-size slide

  21. ΧελϜΞΫγϣϯͷ࣮૷ํ๏
    • Docker ίϯςφʔ ΞΫγϣϯ


    • DockerΛ࢖࣮ͬͯߦ؀ڥΛύοέʔδԽ͢ΔͷͰඞཁͳπʔϧ΍ґଘؔ܎ΛίϯςφͰ؅ཧͰ͖ΔͷͰҰ؏ੑͱ৴པੑΛ୲
    อ͠΍͍͢


    • ͨͩ͠ݱঢ়͸Linuxʢubuntuʣ ͷϥϯφʔͰͷΈར༻Ͱ͖ΔʢmacOS΍Windows͸ར༻ෆՄʣ


    • JavaScript ΞΫγϣϯ


    • Node.jsΛ࢖ͬͯJavaScriptͷίʔυΛ࣮ߦ͢Δ


    • TypeScriptͰͷ։ൃ΋Մೳʢ࠷ऴతʹJavaScript͕ੜ੒Ͱ͖ΔͳΒͳΜͰ΋ྑ͍ʣɺෳࡶͳ࣮૷Λ͢ΔͳΒ͓͢͢Ί


    • ෳ߹ΞΫγϣϯʢComosite Actionʣ


    • ௨ৗͷGitHub ActionsͷJob͔ΒSetpͷҰ෦Λ੾Γग़ͨ͠Πϝʔδ


    • uses: ͕ར༻ՄೳͳͷͰطଘͷΞΫγϣϯ΋ར༻Ͱ͖Δ

    View full-size slide

  22. actions/github-script // hello world
    - uses: actions/github-script@v7
    with:
    script: console.log('Hello, JavaScript')
    // use github rest api
    - uses: actions/github-script@v7
    with:
    script: |
    github.rest.issues.get({
    issue_number: context.issue.number,
    owner: context.repo.owner,
    repo: context.repo.repo,
    })
    // run separate file
    - uses: actions/github-script@v7
    with:
    script: |
    const script = require('./path/to/script.js')
    console.log(script({github, context}))
    // in script.js
    module.exports = ({github, context}) => {
    return 'Hello, JavaScript'
    }
    • GitHub ActionsͰJavaScriptΛ࣮ߦ͢Δ
    ΞΫγϣϯ

    View full-size slide

  23. ࠓճͷΧελϜΞΫγϣϯͷ࣮૷ͷৄࡉ

    fl
    utter analyzeίϚϯυͷग़ྗ಺༰Λղੳ͢Δ


    • --write=
    fi
    lenameΦϓγϣϯΛ࢖͏ͱ੩తղੳͷ಺༰͕parse͠΍
    ͍͢ܗࣜͰϑΝΠϧʹ΋ग़ྗ͞ΕΔ


    • ϑΝΠϧ໊ɺߦ൪߸ɺϝοηʔδͳͲΛऔಘ͢Δ

    View full-size slide

  24. --writeΦϓγϣϯͰग़ྗ͞ΕΔ಺༰ͷྫ
    [error] A value of type 'int' can't be assigned to a variable of type 'String' (/Users/yorifuji/git/
    flutter_analyze_commenter_ci/lib/main.dart:4:20)
    [warning] The value of the local variable 'x' isn't used (/Users/yorifuji/git/
    flutter_analyze_commenter_ci/lib/main.dart:4:16)
    [info] Use 'const' for final variables initialized to a constant value (/Users/yorifuji/git/
    flutter_analyze_commenter_ci/lib/main.dart:4:3)

    View full-size slide

  25. ࠓճͷΧελϜΞΫγϣϯͷ࣮૷ͷৄࡉ
    • GitHubͷPRʹରͯ͠ίϝϯτΛॻ͖ࠐΉ


    • GitHubʹ͸REST API͕༻ҙ͞Ε͍ͯͯGUIͰͰ͖Δ͜ͱ͸େମAPI͔Β΋Ͱ͖Δ


    • APIΛ࢖ͬͯPRͷίʔυͷࠩ෼ʢdiffʣΛऔಘͯ͠ɺ௥Ճ࡟আ͞ΕͨϑΝΠϧ໊΍ߦ൪߸Λऔ
    ಘ͢Δ



    fl
    utter analyzeͷղੳ಺༰ͱdiffͷ಺༰ΛϑΝΠϧ໊ͱߦ൪߸Λݩʹಥ͖߹ΘͤΔͱPRͰࠞ
    ೖͨ͠ίʔυɾܯࠂͱϑΝΠϧ໊ɾߦ൪߸͕ಛఆͰ͖Δ


    • APIΛ࢖ͬͯPRͷ൪߸ɺϑΝΠϧ໊ɺߦ൪߸ɺϝοηʔδͳͲΛࢦఆͯ͠ॻ͖ࠐΈΛߦ


    • PRʹίϝϯτ͕൓ө͞ΕΔ

    View full-size slide

  26. ࠓճͷΧελϜΞΫγϣϯͷ࣮૷ͷৄࡉ
    • ݹ͘ͳͬͨίϝϯτͷ࡟আ


    • PRʹରͯ͠௥Ճʢमਖ਼ʣίϛοτͰ໰୊ͷ͋ͬͨίʔυ͕আڈ͞ΕΔΑ͏ͳέʔε



    fl
    utter analyzeͷ݁Ռ͔Β౰֘Օॴͷग़ྗ͕ফ͑Δ


    • ίϝϯτΛ࡟আ͢Δ࢓༷ʹ͍ͯ͠Δ


    • APIΛ࢖ͬͯPRͷίϝϯτΛશ݅औಘͯ͠ɺ࠷৽ͷanalyzeͷ݁Ռͱ෇͖߹Θͤͯෆཁʹͳͬ
    ͨίϝϯτΛAPIܦ༝Ͱ࡟আ͍ͯ͠Δ


    • ਓ͕ؒॻ͖ࠐΜͩίϝϯτͱ۠ผ͢ΔͨΊʹ༧ΊΞΫγϣϯ͔ΒίϝϯτΛॻ͖ࠐΉࡍʹ
    ඇදࣔͷςΩετΛؚ·͍ͤͯΔʢͷΑ͏ͳςΩετʣ

    View full-size slide

  27. ϦϦʔε࡞ۀ
    • ։ൃ͕ऴΘͬͨΒGitHub্ͰReleaseΛ࡞੒͢Δ
    • ϦϙδτϦʹaction.yml͕ଘࡏ͢ΔͱΞΫγϣϯઐ༻ͷ
    Releaseը໘͕දࣔ͞ΕΔ


    • Marketplace΁ͷpublishΛࢦఆͰ͖Δ


    • ymlهड़಺༰ɺREADMEͷ༗ແ͕νΣοΫ͞ΕΔ


    • Categoryͷઃఆ


    ͳͲ

    View full-size slide

  28. ςετʹ͍ͭͯ
    • ݱঢ়Ͱ͸ςετΛॻ͍͍ͯͳ͍🤯


    • ୅ΘΓʹE2EςετΛ͍ͯ͠Δ



    fl
    utterΞϓϦͷϦϙδτϦͰࠓճ࡞੒ͨ͠ΞΫγϣϯΛؚΉCI͕ظ
    ଴௨Γʹಈ͘͜ͱΛ֬ೝ͍ͯ͠Δ


    • ΧελϜΞΫγϣϯଆͷmain/develop/v1ϒϥϯνʹରͯ͠ubuntu/
    macOS/windowsͷϚτϦοΫεͰE2Eςετ࣮ࢪ

    View full-size slide

  29. ՝୊΍ࠓޙͷ༧ఆ
    • ར༻࣮੷͕গͳ͍ͷͰαΠυϓϩδΣΫτͳͲͰ࢖ͬͯΈ͍ͯͩ͘͞ʢόάใࠂ׻ܴͰ͢ʣ


    • ςετΛॻ͘


    • Pure-JavaScript͔ΒTypeScriptʹҠߦ͍ͨ͠


    • JavaScriptΞΫγϣϯʢnpmʣ΁ͷҠߦ


    • ݱঢ়͸ෳ߹ΞΫγϣϯʴJavaScriptͱ͍͏ߏ੒


    • easyͰ͸͋Δ͕ن໛Λେ͖ͨ͘͠Γ֦ு͢Δࡍʹੜ࢈ੑ͕ྑ͘ͳ͍


    • ΋͏ͪΐͬͱ໘ന͍͜ͱΛ͍ͨ͠


    • ໰୊ͷ͋ΔίʔυΛAI͕ࣗಈతʹमਖ਼ʢఏҊʣͯ͘͠ΕΔͱخ͔ͬͨ͠Γ...ʁ

    View full-size slide

  30. ༨ஊɿ։ൃͨ͠Ϟνϕʔγϣϯ
    • ݩʑ͸Dangerͱ͍͏πʔϧΛ࢖͍ͬͯͨ


    • ϓϧϦΫΤετͷମࡋ΍಺༰ΛνΣοΫ͢Δπʔϧ


    • SwiftΞϓϦͳͲͰ΋࢖ΘΕ͍ͯͯ༗໊ͰރΕ͍ͯΔ


    • ҎԼͷ఺Ͱෆຬ͕͋ͬͨ


    • DangerΛಋೖ͢Δ໨తͷઆ໌͕ඞཁ


    • Ruby੡Ͱ࣮ߦ࣌ʹgemͷΠϯετʔϧ͕ඞཁ


    • ߴػೳ͚ͩͲFlutterͷ੩తղੳͷ໨తͰ͸ΦʔόʔεϖοΫ


    • ΧελϜΞΫγϣϯΛ࡞ͬͯOSSͱͯ͠ެ։ͯ͠Έ͔ͨͬͨ

    View full-size slide

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

    View full-size slide