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

GitHub Actions Deep Dive using PHP / PHPerKaigi 2022

GitHub Actions Deep Dive using PHP / PHPerKaigi 2022

69b93af68320a590f607c296e8edff73?s=128

Ken’ichiro Oyama

April 10, 2022
Tweet

More Decks by Ken’ichiro Oyama

Other Decks in Technology

Transcript

  1. GitHub Actions Deep Dive using PHP খࢁ݈Ұ࿠ / GMO PEPABO

    inc. 2022.4.10 PHPerKaigi 2022 1
  2. ࣗݾ঺հ ٕज़෦ɹٕज़ج൫νʔϜ 2018೥ த్ೖࣾ খࢁ ݈Ұ࿠ Ken’ichiro Oyama গ࣮͠༻తͰখ͞ͳOSSΛॻ͘ͷ͕झຯɻ •

    GitHub : k1LoW • Twitter : @k1LoW 2
  3. ΞδΣϯμ 1. GitHub Actions 2. GitHub ActionsͷΞʔΩςΫνϟ 3. ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions

    4. Action 5. ͓ΘΓʹ 3
  4. octocov 4

  5. • https://github.com/k1LoW/octocov • ίʔυϝτϦΫεπʔϧ…ίʔυΧόϨοδɺCode to Test Ratioɺςετ࣮ߦ࣌ؒ • ଟ਺ͷϓϩάϥϛϯάݴޠͱɺओཁͳΧόϨοδϨϙʔτϑΥʔϚοτʹରԠ •

    GitHub Actionsͷactionͱͯ͠ίʔυϝτϦΫεΛूܭɺP/RίϝϯτɺϨϙʔτ • CLIπʔϧͱͯ͠ίʔυΧόϨοδΛूܭɻදࣔ • ΧόϨοδόοδੜ੒ octocov 5 5 octocov
  6. octocov • octocov͸ίʔυϝτϦΫεΛࢦఆͷσʔλετΞʹอ࣋͢Δ͜ͱ͕Ͱ͖Δ • GitHub ArtifactsɺϩʔΧϧɺGitHubϦϙδτϦɺS3ɺGCSɺBigQuery • σʔλετΞͷ৘ใΛ࢖ͬͯϝτϦΫεͷࠩ෼ΛPRʹίϝϯτ • ผ్octocovΛ

    “CentralϞʔυ” ͱͯ͠ಈ͔͢͜ͱͰσʔλετΞʹ͋Δ֤Ϧϙδτ Ϧ͔Βૹ৴͞ΕͨίʔυϝτϦΫεΛऔಘ͠ɺҰཡදࣔ΍Ұׅͨ͠όοδੜ੒ͳͲ ͕Մೳ ίʔυϝτϦΫεσʔλͷૹ৴ɾऔಘɾ׆༻ 6
  7. GitHub Actions 7

  8. GitHub Actions GitHub Actions makes it easy to automate all

    your software work fl ows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want. https://github.com/features/actions GitHub ActionsΛ࢖༻͢ΔͱɺϫʔϧυΫϥεͷCI/CD؀ڥͰ͢΂ͯͷι ϑτ΢ΣΞϫʔΫϑϩʔΛ؆୯ʹࣗಈԽͰ͖·͢ɻ GitHub͔Β௚઀ίʔ υΛϏϧυɺςετɺσϓϩΠͰ͖ɺίʔυϨϏϡʔɺϒϥϯν؅ཧɺ IssueͷτϦΞʔδΛ๬Μͩ௨Γʹػೳͤ͞·͢ɻ 8
  9. 9 Cons Pros • GitHubϓϥοτϑΥʔϜͱ౷߹͞ Ε͍ͯΔͨΊɺGitHubҎ֎Ͱ͸ ࢖͍ͮΒ͍ • GitHubϦϙδτϦͱ౷߹͞Ε͍ͯ ΔͨΊ͙͢ʹར༻ՄೳɻϦϙδτ

    ϦͷίʔυͷCI/CDʹ࠷ద • GitHub ActionsͷϓϥάΠϯͱ͍ ͑ΔAction౳΋GitHubϦϙδτϦ ʹ͋ΔίʔυΛར༻͢ΔͨΊ͙͢ ʹར༻͕ՄೳʢʮϓϥάΠϯͷΠ ϯετʔϧʯͱ͍͏Α͏ͳεςο ϓ͕ෆཁʣ GitHub ActionsͷPros/Cons GitHub Actions
  10. GitHub ActionsΛཧղ͢ΔͨΊͷྑ͍ϦϑΝϨϯε 10 GitHub Actions • ެࣜυΩϡϝϯτ • https://docs.github.com/ja/actions •

    ඇৗʹΘ͔Γ΍͍͢ͷͰΦεεϝ • ࣌ʑӳޠΑΓ΋৘ใྔ͕গͳ͍৔߹͕͋Δͷͱɺϖʔδ಺ϦϯΫ ͕ޮ͔ͳ͍ͷͰɺՄೳͳΒ https://docs.github.com/en/actions ΋֬ ೝ͍ͯͩ͘͠͞ʢϖʔδ্෦ͷϓϧμ΢ϯͰมߋՄೳͰ͢ʣ
  11. 11 GitHub Actionsͷ ΞʔΩςΫνϟ

  12. • ϫʔΫϑϩʔ ( Workflow ) … A workflow is a

    configurable automated process that will run one or more jobs. • δϣϒ ( Job ) … A job is a set of steps in a workflow that execute on the same runner. • εςοϓ ( Step ) … Jobͷߏ੒ཁૉɻ೚ҙͷॲཧΛ࣮ߦ͢Δ୯Ґɻ 12 GitHub ActionsͷΞʔΩςΫνϟ ίϯϙʔωϯτ : Workflow / Job / Step ※ https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions ΑΓൈਮ
  13. • Πϕϯτ ( Event ) … An event is a

    specific activity in a repository that triggers a workflow run. • ΞΫγϣϯ ( Action ) … An action is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. • ϥϯφʔ ( Runner ) … A runner is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. 13 GitHub ActionsͷΞʔΩςΫνϟ ίϯϙʔωϯτ : Event / Action / Runner ※ https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions ΑΓൈਮ
  14. • GitHub Actions͸EventΛτϦΨʔʹWorkflowΛىಈ͢Δɻ • Workflow͸1ͭ΋͘͠͸ෳ਺ͷJobΛ࣮ߦ͢Δɻ • Job͸1ͭ΋͘͠͸ෳ਺ͷStepͰߏ੒͞Ε͍ͯΔɻ • Step͸೚ҙͷॲཧΛ࣮ߦ͢Δ୯Ґɻ •

    Jobຖʹ1ͭͷRunnerͷ্Ͱ࣮ߦ͞ΕΔɻ • WorkflowͷதͰΑ࣮͘ࢪ͞ΕΔॲཧ͸Actionͱ͍͏1ͭͷॲཧͷ·ͱ·Γͱͯ͠੾Γग़͠ ࠶ར༻Ͱ͖ΔΑ͏ͳ࢓૊Έ͕͋ΔɻAction͸StepͰݺͼग़͢͜ͱͰ࢖༻͢Δɻطʹଟ͘ͷ Action͕GitHubϚʔέοτϓϨΠεͰެ։͞Ε͓ͯΓɺ·ͨ৽͘͠࡞੒͢Δ͜ͱ΋Մೳɻ 14 GitHub ActionsͷΞʔΩςΫνϟ GitHub ActionsͷΞʔΩςΫνϟ
  15. 15 GitHub ActionsͷΞʔΩςΫνϟ GitHub ActionsͷΞʔΩςΫνϟ

  16. • 1YAML = 1Workflow • ԿͷEventΛτϦΨʔʹ͢Δ͔͸ on: ηΫγϣϯͱରԠ • WorkflowʹͿΒԼ͕ΔJob͸

    jobs: ηΫγϣϯͱରԠ • JobʹͿΒԼ͕ΔStep͸ jobs.<job_id>.steps: ηΫγϣϯͱରԠ • ԿͷRunnerͷ্ͰJobΛಈ͔͔͢͸ jobs.<job_id>.runs-on: ηΫγϣϯͱରԠ • Action͸ uses: Ͱݺͼग़ͤ·͢ɻjobs.<job_id>.steps[*].uses: ηΫγϣϯͱରԠ • jobs.<job_id>.uses: Ͱ͸ Reusable Workflow ΋ݺͼग़͠Մೳ 16 GitHub ActionsͷΞʔΩςΫνϟ ֤ίϯϙʔωϯτͱ .github/workflows ʹஔ͘YAMLϑΝΠϧͷؔ܎
  17. 17 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷ GitHub Actions

  18. Re: GitHub Actions GitHub Actions makes it easy to automate

    all your software work fl ows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want. https://github.com/features/actions GitHub ActionsΛ࢖༻͢ΔͱɺϫʔϧυΫϥεͷCI/CD؀ڥͰ͢΂ͯͷι ϑτ΢ΣΞϫʔΫϑϩʔΛ؆୯ʹࣗಈԽͰ͖·͢ɻ GitHub͔Β௚઀ίʔ υΛϏϧυɺςετɺσϓϩΠͰ͖ɺίʔυϨϏϡʔɺϒϥϯν؅ཧɺ IssueͷτϦΞʔδΛر๬Ͳ͓Γʹػೳͤ͞·͢ɻ 18
  19. • GitHub ActionsΛʮCI/CD؀ڥʯͱͯ͠ଊ͑ͨ݁ՌʮΞϓϦέʔγϣϯͷςετͱσ ϓϩΠΛࣗಈԽ͢Δ؀ڥʯͩͱࢥΘΕ͕ͪ • ্هͷΑ͏ͳڱٛͷCI/CD͚ͩͰ͸ͳ͍ • ʮΞϓϦέʔγϣϯͷςετͱσϓϩΠʯ΋ؚΉ޿ٛͷCI/CD΍ϫʔΫϑϩʔࣗಈԽ Λ࣮ݱ͢Δػೳͱͯ͠ΈΔ 19

    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions GitHub Actions͸ϫʔΫϑϩʔΛࣗಈԽͰ͖Δ
  20. • δϣϒʢ= Jobʣͷґଘؔ܎ΛDAGʢ༗޲ඇ८ճάϥϑʣͰදݱͰ͖Δ • λεΫʢ= Step΍Job΍Workflowʣͷ੒൱͕֬ೝͰ͖Δ • ϩά͕Ұఆظؒอଘ͞Ε֬ೝͰ͖Δ 20 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub

    Actions ຊൃදʹ͓͚ΔϫʔΫϑϩʔΤϯδϯͱ͸ ※ https://ja.wikipedia.org/wiki/༗ޮඇ८ճάϥϑ ΑΓ
  21. 21 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • on: • needs: • jobs.<job_id>.needs: •

    if: • jobs.<job_id>.if: • jobs.<job_id>.steps[*].if: • uses: • jobs.<job_id>.steps[*].uses: • jobs.<job_id>.uses: DAGΛ࣮ݱ͢ΔͨΊͷϫʔΫϑϩʔߏจ
  22. on: 22 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • DAGʹ͓͚Δ࢝఺ʢͱͳΔ௖఺ʣʹͳΔߏจ • ίʔυͷPush΍Pull RequestҎ֎ʹ΋Issue΍Projectɺ DiscussionͳͲGitHubϓϥοτϑΥʔϜͷϦϙδτϦʹؔ܎͢Δ

    ཁૉͷ͞·͟·ͳΠϕϯτΛड͚औΕΔ • ఆظ࣮ߦ͕Ͱ͖Δ on.schedule: ͱϫʔΫϑϩʔΛ௚઀࣮ߦͰ͖ Δ repository_dispatch: ΍ workflow_dispatch: ͸རศੑ͕ߴ͍ • GitHubϓϥοτϑΥʔϜؔ܎ͳ͘ϫʔΫϑϩʔΛ࣮ߦͰ͖Δ
  23. 23 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • jobs.<job_id>.needs: • ͦͷJobΛ࣮ߦ͢ΔͨΊʹඞཁͳJobΛྻڍͰ͖Δ • = JobΛ௚ྻʹܨ͛Δ͜ͱ͕Ͱ͖Δߏจ

    • ௨ৗ͸Runnerͷ਺͕ڐ͢ݶΓฒྻ࣮ߦ • = DAGʹ͓͚ΔϑΝϯΠϯɺϑΝϯΞ΢τΛ࣮ݱͰ͖Δߏจ needs:
  24. 24 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • jobs.<job_id>.if: • jobs.<job_id>.steps[*].if: • ͦͷJob΍StepΛ࣮ߦ͢Δ͔Ͳ͏͔ͷ৚݅Λॻ͘͜ͱ͕Ͱ͖ Δ

    • ޙड़͢ΔContextͷ஋ΛExpressionsΛ࢖ͬͯ৚݅ࣜΛॻ ͘ • ৚݅෼ذΛ࡞੒Մೳͳߏจ if:
  25. uses: 25 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • jobs.<job_id>.steps[*].uses: • jobs.<job_id>.uses: • Action΍Reusable

    workflowΛݺͼग़͢ • = ผͷϦϙδτϦʹ·ͰDAGͷൣғΛ޿͛Δߏจ
  26. • Expressions • PHPer͸ςϯϓϨʔτΤϯδϯ಺ͰόΠϯυͨ͠஋ΛࢀরͰ͖ͨΓɺҰ෦ؔ਺ ͕࢖͑ͨΓ͢ΔΞϨΛΠϝʔδ͍ͯͩ͘͠͞ • Context΍؀ڥม਺ΛݺͿͨΊʹ࢖༻ • if: ηΫγϣϯͰ͸৚݅ࣜΛॻͨ͘Ίʹ࢖͏

    • Context • ࠓ࣮ߦ͍ͯ͠ΔWorkflowपลͷίϯςΩετ৘ใΛऔಘͰ͖Δ 26 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions DAGͷ੍ޚΛ͢ΔͨΊͷExpressions, Context
  27. • if: ${{ github.event_name == ‘pull_request’ }} • Event͕pull_requestͩͬͨ৔߹ʹtrueɻҎ߱ͷλεΫΛ࣮ߦ •

    run: echo '${{ toJSON(github) }}’ • “github” ίϯςΩετΛJSONܗࣜͰඪ४ग़ྗʹग़ྗ • if: ${{ always() && contains(needs.*.result, ‘success') }} • ௚લͷJobͷগͳ͘ͱ΋1͕ͭ੒ޭ͍ͯ͠Δ৔߹ʹtrueɻҎ߱ͷJobΛ࣮ߦ 27 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions Example: Expressions, Context
  28. 28 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions Example DAG: fan-in fan-out

  29. 29 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions Example DAG: if-else

  30. • Workflow commands • ඪ४ग़ྗ΁ग़ྗ͢Δ࣌ʹҰఆͷϑΥʔϚοτͰग़ྗ͢Δͱ஋Λอ࣋͢Δ͜ͱ͕Մೳ • run: echo '::set-output name=SELECTED_COLOR::green’

    • SELECTED_COLORͱ͍͏໊લͰ green ͱ͍͏จࣈྻ͕อ࣋͞ΕΔ • ${{ steps.<step_id>.outputs.SELECTED_COLOR }} ͰऔಘՄೳ • Artifacts • δϣϒؒͰσʔλΛڞ༗͢Δ͜ͱ͕Մೳ • جຊతʹ actions/upload-artifactɺactions/download-artifactΛ࢖༻͢Δ 30 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions DAGͷ֤௖఺͔Β࣍ͷ௖఺΁஋Λ౉ͨ͢Ίʹ࢖͑Δػೳ
  31. • ओʹ੒Ռ෺ΛӬଓԽ͢ΔͨΊʹػೳ͢ΔArtifactsͱɺҰ࣌తͳΩϟογϡΛWorkflowؒͰڞ༗ͯ͠WorkflowΛߴ଎Խ ͢ΔͨΊͷCachingͱ͍͏ػೳ͕͋Δ • ͦΕͧΕ actions/(upload/download)-artifactͱactions/cacheͱ͍͏ActionͰػೳ͕ఏڙ͞Ε͍ͯΔɻ • ࣮͸্هͷػೳΛ࣮ݱ͢ΔͨΊͷʮArtifactͷμ΢ϯϩʔυʯҎ֎ͷAPI͸υΩϡϝϯτʹܝࡌ͞Ε͍ͯͳ͍ • Artifacts΋Caching΋GitHub

    ActionsͷRunner্Ͱ࢖͏͜ͱͷΈΛ૝ఆ͍ͯ͠ΔͨΊͩͱࢥΘΕΔ • ࢓૊Έͱͯ͠͸Runner্Ͱ͚ͩఏڙ͞ΕΔ ACTIONS_RUNTIME_TOKEN Λ࢖ͬͯΞοϓϩʔυઌͷҰ࣌URLΛऔ ಘ͠ɺͦͷҰ࣌URLʹରͯ͠Ξοϓϩʔυ͢Δ • https://github.com/actions/toolkit/blob/d1abf7dc74ea38ed6c5552491cdf8b695b813722/packages/cache/ src/internal/cacheHttpClient.ts#L35-L38 • https://github.com/actions/toolkit/blob/d1abf7dc74ea38ed6c5552491cdf8b695b813722/packages/artifact/ src/internal/utils.ts#L215-L219 31 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions ༨ஊ: ArtifactsͱCaching
  32. 32 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • ؀ڥม਺ GITHUB_* • GITHUB_EVENT_PATHʹ͋ΔJSONϑΝΠϧ಺ʹΠϕϯτΛ ϑοΫͨ͠ࡍͷϦΫΤετϖΠϩʔυ͕͋Δ •

    ্هΛ࢖͏͜ͱͰStepͷॲཧ্ͰWorkflowͷίϯςΩετʹ ͦͬͨಈ͖Λ͢Δ͜ͱ͕Ͱ͖Δ Step಺Ͱ͸؀ڥม਺͔ΒGitHub Actionsͷ৘ใΛऔಘՄೳ
  33. 33 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions “GitHub Actions Deep Dive using PHP”

  34. 34 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions • https://github.com/k1LoW/github-script-php • actions/github-scriptͷPHP൛Action • Step಺Ͱ uses:

    Ͱݺͼग़͢͜ͱͰಛʹԿ΋༻ҙͤͣʹPHPεΫϦ ϓτΛॻ͘͜ͱ͕Ͱ͖Δʢsetup-php΋͍Βͳ͍ʣ • طʹೝূࡁΈͷ knpkabs/github-api ͷΫϥΠΞϯτΠϯελϯε ͕ $github ʹηοτࡁΈɻͳͲ actions/github-scriptʹ͍ۙಈ͖ Λ͢Δ • PHPerKaigi2022ͷͨΊʹ࡞Γ·ͨ͠ ೚ҙͷStepͰPHPεΫϦϓτΛ࣮ߦͰ͖ΔAction
  35. 35 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions GITHUB_EVENT_PATHͷJSONΛdumpͯ͠ΈΔ • uses: k1LoW/github-script-php@v0 Ͱݺͼग़͚ͩ͢ • uses:

    actions/checkout@v3 ΋͍Βͳ͍
  36. 36 ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions ͍Ζ͍Ζ৘ใ͕औಘͰ͖Δͷ͕Θ͔Δ

  37. 37 Action

  38. Action 38 An action is a custom application for the

    GitHub Actions platform that performs a complex but frequently repeated task. https://docs.github.com/en/actions/learn-github-actions/ understanding-github-actions Action͸ɺGitHub Actions ϓϥοτϑΥʔϜͷͨΊͷΧελϜ ΞϓϦέʔγϣϯͰɺෳࡶ͕ͩසൟʹ܁Γฦ͞ΕΔλεΫΛ࣮ ߦ͢Δ΋ͷͰ͢ɻ
  39. 39 Action • Runner͸VM͕ͩJobͷ࣮ߦΛऴ͑ΔͨͼʹॳظԽ͞ΕΔ • Provide a clean instance for

    every job execution. • Runner΋VMͷ؀ڥ΋OSSͱͯ͠ެ։͞Ε͍ͯΔ • https://github.com/actions/runner • https://github.com/actions/virtual-environments RunnerʢGitHub-hosted runnersʣ
  40. 40 Action • Jobͷ࣮ߦ؀ڥ͸େ͖͘3௨Γ͋Δ 1. શͯͷStepΛ௚઀Runner্Ͱ࣮ߦ͢Δ 2. શͯͷStepΛ1छྨͷDockerΠϝʔδΛ࢖ͬͨDocker on Runner্ͰVMͷҰ෦σΟϨΫτϦΛϚ΢ϯτͨ͠͏͑Ͱ࣮

    ߦ͢Δ 3. Ұ෦ͷStepΛRunner্ͰɺҰ෦·ͨ͸શͯͷStepΛ1छྨ Ҏ্ͷDockerΠϝʔδΛ࢖ͬͨDocker on Runner্ͰVM ͷҰ෦σΟϨΫτϦΛϚ΢ϯτͨ͠͏͑Ͱ࣮ߦ͢Δ Runner্ͷJobͷ࣮ߦ؀ڥ
  41. • ௨ৗͷJob • શͯͷStep͕ಉ͡؀ڥɻsetup-phpͳͲ΋ɺ౎౓RunnerʹPHPΛΠϯετʔϧ͍ͯ͠ Δ 41 Action 1. શͯͷStepΛ௚઀Runner্Ͱ

  42. • jobs.<job_key>.container: Λࢦఆ͢Δ͜ͱͰ೚ҙͷίϯςφ্ͰJobΛ࣮ߦͰ͖Δ • ࠷ॳ͔Βඞཁͳ΋ͷ͕༻ҙ͞Εͨίϯςφ؀ڥͰ࣮ߦ͕Մೳ 42 Action 2. શͯͷStepΛ1छྨͷDockerΠϝʔδΛ࢖ͬͨDocker on

    Runner্Ͱ
  43. • ϫʔΫϑϩʔߏจ্ʹ͸ͳ͍Job࣮ߦ؀ڥ • …ͷΑ͏ʹݟ͑Δ͕࣮͸ଘࡏ͢Δ 43 Action 3. Ұ෦ͷStepΛRunner্ͰɺҰ෦·ͨ͸શͯͷStepΛ1छྨҎ্ͷDockerΠϝʔδΛ࢖ͬͨDocker on Runner্Ͱ

  44. 44 Action • Actionͷ࣮૷ʹΑͬͯ͸3छྨʹ෼͔ΕΔɻ3छྨͱ΋VM্ʹAction ͷϦϙδτϦ͕Clone͞ΕΔͷ͸ಉ͡ 1. JavaScript action • جຊͷ࣮૷ํ๏ɻJavaScriptͰॲཧΛॻ͘ɻRunner্ʹ͋

    ΔNodeΛ࢖ͬͯͦͷJavaScriptΛ࣮ߦ͢Δ 2. Docker container action • ࢦఆ͞ΕͨDockerfileΛDocker on Runnerͱ࣮ͯ͠ߦ͢Δ 3. Composite action • action.ymlʹهࡌ͞Εͨ steps: ΛॱʹRunner্Ͱ࣮ߦ͢Δ Actionͷछྨ
  45. Action 45 ͲͷλΠϓͷActionͰ΋೚ҙͷDockerΠϝʔδΛ࢖༻Ͱ͖Δ • DockerΛ࢖༻͢ΔActionΛ࢖༻͢Δ͜ͱͰ3ͭ໨ͷJobͷ࣮ߦ؀ڥ ͷύλʔϯΛ࣮ݱ͍ͯ͠Δ • Runnerʹ͸dockerd͕͍Δͷ͔ͩΒͲ͏ͱͰ΋ͳΔɻ 1. JavaScript

    action • JavaScriptͰDockerίϚϯυΛ࣮ߦ͢Ε͹ྑ͍ 2. Docker container action • DockerΠϝʔδΛ؆୯ʹ࢖༻͢ΔActionͱߟ͑ΒΕΔ 3. Composite action • steps: ্ͰDockerίϚϯυΛ࣮ߦ͢Ε͹ྑ͍
  46. 46 Action “GitHub Actions Deep Dive using PHP”

  47. • ͭ·ΓʮPHPͷDockerΠϝʔδΛ࢖͏ʯͱ͍͏͜ͱ • DockerΠϝʔδΛ࢖͏͜ͱͰ೚ҙͷStepͰPHPΛ͔ͭͬͨॲཧΛॻ͘͜ͱ͕Ͱ͖Δ • ͦͷॲཧΛActionͱͯ͠੾Γग़ͯ͠ఏڙ͢Δ 47 Action PHPͰActionΛ࡞Δ

  48. • ੩తղੳπʔϧPhanΛఏڙ͢ΔAction • PhanΛબఆͨ͠ཧ༝ • php-ast͕ඞཁͰ؀ڥߏங͕গ͠໘౗ͳଆ໘͕͋ΔͨΊʢٯʹActionΛ࡞Δϝ Ϧοτ͕͋Γͦ͏ʣ • PHPStanͱPsalmͷAction͸ݟ͔͕ͭͬͨPhan͸ͳ͔ͬͨͨΊ •

    Docker container actionͰ࡞Δ 48 Action phan-actionΛ࡞ͬͯΈΔ
  49. • ActionͷઃఆϑΝΠϧ • ίϯϑΟάϑΝΠϧͷύεͷ೚ҙࢦ ఆͱPhan࣮ߦ࣌ͷexit statusΛແࢹ ͢ΔͨΊͷઃఆΛ௥Ճ Action 49 action.yml

  50. Action • Phan͕Πϯετʔϧ͞Ε͍ͯΔPHP ίϯςφΛ࡞੒͢ΔͨΊͷDockerfile • ͱΓ͋͑ͣPhan͕࣮ߦͰ͖Ε͹͍͍ ͷͰglobalʹΠϯετʔϧ 50 Dockerfile

  51. Action • جຊతʹPhanΛ࣮ߦ͢Δ͚ͩ 51 entrypoint.sh

  52. • https://github.com/k1LoW/phan-action • uses: Ͱݺͼग़͚ͩ͢ͰPhanΛ೚ҙͷ ϓϩδΣΫτʹ࣮ߦՄೳ • Phanͷ؀ڥ͸Dockerίϯςφʹดͯ͡ ͍ΔͷͰPHP5؀ڥͳRunnerͰ΋ద༻ Ͱ͖Δ

    • PHPerKaigi2022ͷͨΊʹ࡞Γ·ͨ͠ Action 52 k1LoW/phan-action
  53. 53 Action ੩తղੳͰ͖ͨ

  54. ͓ΘΓʹ 54

  55. • GitHubϦϙδτϦͷΞϓϦέʔγϣϯίʔυͷCI/CD؀ڥͱͯ͠΋ਃ͠෼ͳ͍͕ɺͦΕ͚ͩ Ͱ͸ͳ͍ • ͞·͟·ͳΠϕϯτͰτϦΨʔͰ͖ΔϫʔΫϑϩʔΤϯδϯͱͯ͠ΈΔͱ׆༻ൣғ͸޿͕Δ • Action΋ඇৗʹ؆୯ʹ࡞ΕΔɻʢ͋ΔҙຯʣPHPͰ΋࡞ΕΔɻ • ࠓճ࿩͍ͤͯͳ͍͜ͱ΋ଟ਺ɻ •

    jobs.<job_id>.services: ΍ ACTIONS_RUNNER_DEBUG ΍ OIDC ΍ ηΩϡϦςΟͳ Ͳ • GitHub Actions͸Ԟ͕ਂ͍ɻGitHub ActionsͰ͓࿩͠͠·͠ΐ͏ɻ 55 ͓ΘΓʹ GitHub Actions͸Ԟ͕ਂ͍
  56. Thank You! Thank You! 56