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. ࣗݾ঺հ • YORIFUJI MITSUNORI • @yorifuji on X / GitHub

    / Zenn • ۚ༥ܥελʔτΞοϓͷiOSΤϯδχΞ • ݸਓ޲͚౤ࢿΞϓϦʢSwiftʣ΍ۚ༥ػؔ޲͚ͷۀ຿ΞϓϦʢFlutterʣͷ։ൃ • લ৬͸௨৴ձࣾͷSIerͰB2BαʔϏεͷ։ൃͳͲ͍Ζ͍Ζʢ10೥ʙʣ • Flutterྺ͸2೥ఔ౓ɺFlutterେֶ͸1೥΄Ͳલʹೖձ -> Ұ౓ୀձͯ͠࠶౓Join • #ڞಉ։ൃ14_sansen ʹࢀઓͯ͠·͢
  2. ֤ࣾͷCIαʔϏεͷಛ௃ʢݸਓͷײ૝ʣ • Bitrise • ࿝ฮɺ҆ఆ͍ͯͯ͠ރΕ͍ͯΔɺAndroid΍iOSωΠςΟϒͷ஌͕ࣝ׆͔ͤΔ • Codemagic • ޙൃɺFlutterʹಛԽͯ͠ΔʢFlutter SDK͕ΠϯετʔϧࡁΈʣɺ͕ҙ֎ͱ͕݀͋ΔʢރΕ͍ͯͳ͍ʣ

    • GitHub Actions • ΦʔϧϚΠςΟɺpublicϦϙδτϦͰͷར༻͸ແྉɺGitHubͱͷ࿈ܞ͕ڧΈ • Xcode Cloud • Apple७ਖ਼CIɺূ໌ॻ؅ཧ͕ෆཁɺXcode࿈ܞɺ͍҆ɺFlutterʹ͸ෆ޲͖
  3. 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
  4. ࠓ೔࿩͢ͷ͸ϫʔΫϑϩʔͰ ར༻͢ΔΞΫγϣϯͷํ 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
  5. Flutterͷ੩తղੳ • VSCode΍ fl utter analyzeίϚϯυͰग़ྗ͞ΕΔίϨ • Error / Warning

    / Info ͷ3Ϩϕϧ • ඪ४Ͱ͸ fl utter_lintsʹఆٛ͞Εͨϧʔϧʹج͍ͮͯղੳ • pedantic_mono΍very_good_analysis͕͓͢͢Ί
  6. ࢖͍ํ͸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
  7. GitHub Marketplace • GitHubެࣜɾOSSɾݸਓ͕࡞੒ͨ͠GitHub Apps΍ΞΫγϣϯ͕ެ։͞ Ε͍ͯΔ • ΞΫγϣϯͰݕࡧ͢Δͱ 20,940 results

    • ඞཁͳ΋ͷ͸େମ͋Δ͕⭐͕গͳ͍ϚΠφʔͳActionΛར༻͢Δͱ͖͸ ηΩϡϦςΟϦεΫͳͲʹ஫ҙ͕ඞཁ
  8. ࣗ࡞ͷΞΫγϣϯΛ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
  9. ࣮ࡍͷ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
  10. ΧελϜΞΫγϣϯͷ࣮૷ํ๏ • Docker ίϯςφʔ ΞΫγϣϯ • DockerΛ࢖࣮ͬͯߦ؀ڥΛύοέʔδԽ͢ΔͷͰඞཁͳπʔϧ΍ґଘؔ܎ΛίϯςφͰ؅ཧͰ͖ΔͷͰҰ؏ੑͱ৴པੑΛ୲ อ͠΍͍͢ • ͨͩ͠ݱঢ়͸Linuxʢubuntuʣ

    ͷϥϯφʔͰͷΈར༻Ͱ͖ΔʢmacOS΍Windows͸ར༻ෆՄʣ • JavaScript ΞΫγϣϯ • Node.jsΛ࢖ͬͯJavaScriptͷίʔυΛ࣮ߦ͢Δ • TypeScriptͰͷ։ൃ΋Մೳʢ࠷ऴతʹJavaScript͕ੜ੒Ͱ͖ΔͳΒͳΜͰ΋ྑ͍ʣɺෳࡶͳ࣮૷Λ͢ΔͳΒ͓͢͢Ί • ෳ߹ΞΫγϣϯʢComosite Actionʣ • ௨ৗͷGitHub ActionsͷJob͔ΒSetpͷҰ෦Λ੾Γग़ͨ͠Πϝʔδ • uses: ͕ར༻ՄೳͳͷͰطଘͷΞΫγϣϯ΋ར༻Ͱ͖Δ
  11. 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Λ࣮ߦ͢Δ ΞΫγϣϯ
  12. --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)
  13. ࠓճͷΧελϜΞΫγϣϯͷ࣮૷ͷৄࡉ • GitHubͷPRʹରͯ͠ίϝϯτΛॻ͖ࠐΉ • GitHubʹ͸REST API͕༻ҙ͞Ε͍ͯͯGUIͰͰ͖Δ͜ͱ͸େମAPI͔Β΋Ͱ͖Δ • APIΛ࢖ͬͯPRͷίʔυͷࠩ෼ʢdiffʣΛऔಘͯ͠ɺ௥Ճ࡟আ͞ΕͨϑΝΠϧ໊΍ߦ൪߸Λऔ ಘ͢Δ •

    fl utter analyzeͷղੳ಺༰ͱdiffͷ಺༰ΛϑΝΠϧ໊ͱߦ൪߸Λݩʹಥ͖߹ΘͤΔͱPRͰࠞ ೖͨ͠ίʔυɾܯࠂͱϑΝΠϧ໊ɾߦ൪߸͕ಛఆͰ͖Δ • APIΛ࢖ͬͯPRͷ൪߸ɺϑΝΠϧ໊ɺߦ൪߸ɺϝοηʔδͳͲΛࢦఆͯ͠ॻ͖ࠐΈΛߦ • PRʹίϝϯτ͕൓ө͞ΕΔ
  14. ࠓճͷΧελϜΞΫγϣϯͷ࣮૷ͷৄࡉ • ݹ͘ͳͬͨίϝϯτͷ࡟আ • PRʹରͯ͠௥Ճʢमਖ਼ʣίϛοτͰ໰୊ͷ͋ͬͨίʔυ͕আڈ͞ΕΔΑ͏ͳέʔε • fl utter analyzeͷ݁Ռ͔Β౰֘Օॴͷग़ྗ͕ফ͑Δ •

    ίϝϯτΛ࡟আ͢Δ࢓༷ʹ͍ͯ͠Δ • APIΛ࢖ͬͯPRͷίϝϯτΛશ݅औಘͯ͠ɺ࠷৽ͷanalyzeͷ݁Ռͱ෇͖߹Θͤͯෆཁʹͳͬ ͨίϝϯτΛAPIܦ༝Ͱ࡟আ͍ͯ͠Δ • ਓ͕ؒॻ͖ࠐΜͩίϝϯτͱ۠ผ͢ΔͨΊʹ༧ΊΞΫγϣϯ͔ΒίϝϯτΛॻ͖ࠐΉࡍʹ ඇදࣔͷςΩετΛؚ·͍ͤͯΔʢ<!--- hogefuga --->ͷΑ͏ͳςΩετʣ
  15. ՝୊΍ࠓޙͷ༧ఆ • ར༻࣮੷͕গͳ͍ͷͰαΠυϓϩδΣΫτͳͲͰ࢖ͬͯΈ͍ͯͩ͘͞ʢόάใࠂ׻ܴͰ͢ʣ • ςετΛॻ͘ • Pure-JavaScript͔ΒTypeScriptʹҠߦ͍ͨ͠ • JavaScriptΞΫγϣϯʢnpmʣ΁ͷҠߦ •

    ݱঢ়͸ෳ߹ΞΫγϣϯʴJavaScriptͱ͍͏ߏ੒ • easyͰ͸͋Δ͕ن໛Λେ͖ͨ͘͠Γ֦ு͢Δࡍʹੜ࢈ੑ͕ྑ͘ͳ͍ • ΋͏ͪΐͬͱ໘ന͍͜ͱΛ͍ͨ͠ • ໰୊ͷ͋ΔίʔυΛAI͕ࣗಈతʹमਖ਼ʢఏҊʣͯ͘͠ΕΔͱخ͔ͬͨ͠Γ...ʁ
  16. ༨ஊɿ։ൃͨ͠Ϟνϕʔγϣϯ • ݩʑ͸Dangerͱ͍͏πʔϧΛ࢖͍ͬͯͨ • ϓϧϦΫΤετͷମࡋ΍಺༰ΛνΣοΫ͢Δπʔϧ • SwiftΞϓϦͳͲͰ΋࢖ΘΕ͍ͯͯ༗໊ͰރΕ͍ͯΔ • ҎԼͷ఺Ͱෆຬ͕͋ͬͨ •

    DangerΛಋೖ͢Δ໨తͷઆ໌͕ඞཁ • Ruby੡Ͱ࣮ߦ࣌ʹgemͷΠϯετʔϧ͕ඞཁ • ߴػೳ͚ͩͲFlutterͷ੩తղੳͷ໨తͰ͸ΦʔόʔεϖοΫ • ΧελϜΞΫγϣϯΛ࡞ͬͯOSSͱͯ͠ެ։ͯ͠Έ͔ͨͬͨ