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

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

    View full-size slide

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

    View full-size slide

  3. ΞδΣϯμ
    1. GitHub Actions


    2. GitHub ActionsͷΞʔΩςΫνϟ


    3. ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions


    4. Action


    5. ͓ΘΓʹ
    3

    View full-size slide

  4. • https://github.com/k1LoW/octocov
    • ίʔυϝτϦΫεπʔϧ…ίʔυΧόϨοδɺCode to Test Ratioɺςετ࣮ߦ࣌ؒ
    • ଟ਺ͷϓϩάϥϛϯάݴޠͱɺओཁͳΧόϨοδϨϙʔτϑΥʔϚοτʹରԠ
    • GitHub Actionsͷactionͱͯ͠ίʔυϝτϦΫεΛूܭɺP/RίϝϯτɺϨϙʔτ
    • CLIπʔϧͱͯ͠ίʔυΧόϨοδΛूܭɻදࣔ
    • ΧόϨοδόοδੜ੒
    octocov
    5
    5
    octocov

    View full-size slide

  5. octocov
    • octocov͸ίʔυϝτϦΫεΛࢦఆͷσʔλετΞʹอ࣋͢Δ͜ͱ͕Ͱ͖Δ
    • GitHub ArtifactsɺϩʔΧϧɺGitHubϦϙδτϦɺS3ɺGCSɺBigQuery
    • σʔλετΞͷ৘ใΛ࢖ͬͯϝτϦΫεͷࠩ෼ΛPRʹίϝϯτ
    • ผ్octocovΛ “CentralϞʔυ” ͱͯ͠ಈ͔͢͜ͱͰσʔλετΞʹ͋Δ֤Ϧϙδτ
    Ϧ͔Βૹ৴͞ΕͨίʔυϝτϦΫεΛऔಘ͠ɺҰཡදࣔ΍Ұׅͨ͠όοδੜ੒ͳͲ
    ͕Մೳ
    ίʔυϝτϦΫεσʔλͷૹ৴ɾऔಘɾ׆༻
    6

    View full-size slide

  6. GitHub Actions
    7

    View full-size slide

  7. 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

    View full-size slide

  8. 9
    Cons
    Pros
    • GitHubϓϥοτϑΥʔϜͱ౷߹͞
    Ε͍ͯΔͨΊɺGitHubҎ֎Ͱ͸
    ࢖͍ͮΒ͍
    • GitHubϦϙδτϦͱ౷߹͞Ε͍ͯ
    ΔͨΊ͙͢ʹར༻ՄೳɻϦϙδτ
    ϦͷίʔυͷCI/CDʹ࠷ద
    • GitHub ActionsͷϓϥάΠϯͱ͍
    ͑ΔAction౳΋GitHubϦϙδτϦ
    ʹ͋ΔίʔυΛར༻͢ΔͨΊ͙͢
    ʹར༻͕ՄೳʢʮϓϥάΠϯͷΠ
    ϯετʔϧʯͱ͍͏Α͏ͳεςο
    ϓ͕ෆཁʣ
    GitHub ActionsͷPros/Cons
    GitHub Actions

    View full-size slide

  9. GitHub ActionsΛཧղ͢ΔͨΊͷྑ͍ϦϑΝϨϯε
    10
    GitHub Actions
    • ެࣜυΩϡϝϯτ
    • https://docs.github.com/ja/actions
    • ඇৗʹΘ͔Γ΍͍͢ͷͰΦεεϝ
    • ࣌ʑӳޠΑΓ΋৘ใྔ͕গͳ͍৔߹͕͋Δͷͱɺϖʔδ಺ϦϯΫ
    ͕ޮ͔ͳ͍ͷͰɺՄೳͳΒ https://docs.github.com/en/actions ΋֬
    ೝ͍ͯͩ͘͠͞ʢϖʔδ্෦ͷϓϧμ΢ϯͰมߋՄೳͰ͢ʣ

    View full-size slide

  10. 11
    GitHub Actionsͷ
    ΞʔΩςΫνϟ

    View full-size slide

  11. • ϫʔΫϑϩʔ ( 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 ΑΓൈਮ


    View full-size slide

  12. • Πϕϯτ ( 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 ΑΓൈਮ


    View full-size slide

  13. • 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ͷΞʔΩςΫνϟ

    View full-size slide

  14. 15
    GitHub ActionsͷΞʔΩςΫνϟ
    GitHub ActionsͷΞʔΩςΫνϟ

    View full-size slide

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

    View full-size slide

  16. 17
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷ
    GitHub Actions

    View full-size slide

  17. 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

    View full-size slide

  18. • GitHub ActionsΛʮCI/CD؀ڥʯͱͯ͠ଊ͑ͨ݁ՌʮΞϓϦέʔγϣϯͷςετͱσ
    ϓϩΠΛࣗಈԽ͢Δ؀ڥʯͩͱࢥΘΕ͕ͪ
    • ্هͷΑ͏ͳڱٛͷCI/CD͚ͩͰ͸ͳ͍
    • ʮΞϓϦέʔγϣϯͷςετͱσϓϩΠʯ΋ؚΉ޿ٛͷCI/CD΍ϫʔΫϑϩʔࣗಈԽ
    Λ࣮ݱ͢Δػೳͱͯ͠ΈΔ
    19
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    GitHub Actions͸ϫʔΫϑϩʔΛࣗಈԽͰ͖Δ

    View full-size slide

  19. • δϣϒʢ= Jobʣͷґଘؔ܎ΛDAGʢ༗޲ඇ८ճάϥϑʣͰදݱͰ͖Δ
    • λεΫʢ= Step΍Job΍Workflowʣͷ੒൱͕֬ೝͰ͖Δ
    • ϩά͕Ұఆظؒอଘ͞Ε֬ೝͰ͖Δ
    20
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    ຊൃදʹ͓͚ΔϫʔΫϑϩʔΤϯδϯͱ͸
    ※ https://ja.wikipedia.org/wiki/༗ޮඇ८ճάϥϑ ΑΓ


    View full-size slide

  20. 21
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • on:
    • needs:
    • jobs..needs:

    • if:
    • jobs..if:

    • jobs..steps[*].if:

    • uses:
    • jobs..steps[*].uses:

    • jobs..uses:
    DAGΛ࣮ݱ͢ΔͨΊͷϫʔΫϑϩʔߏจ

    View full-size slide

  21. on:
    22
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • DAGʹ͓͚Δ࢝఺ʢͱͳΔ௖఺ʣʹͳΔߏจ


    • ίʔυͷPush΍Pull RequestҎ֎ʹ΋Issue΍Projectɺ
    DiscussionͳͲGitHubϓϥοτϑΥʔϜͷϦϙδτϦʹؔ܎͢Δ
    ཁૉͷ͞·͟·ͳΠϕϯτΛड͚औΕΔ


    • ఆظ࣮ߦ͕Ͱ͖Δ on.schedule: ͱϫʔΫϑϩʔΛ௚઀࣮ߦͰ͖
    Δ repository_dispatch: ΍ workflow_dispatch: ͸རศੑ͕ߴ͍


    • GitHubϓϥοτϑΥʔϜؔ܎ͳ͘ϫʔΫϑϩʔΛ࣮ߦͰ͖Δ

    View full-size slide

  22. 23
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • jobs..needs:

    • ͦͷJobΛ࣮ߦ͢ΔͨΊʹඞཁͳJobΛྻڍͰ͖Δ

    • = JobΛ௚ྻʹܨ͛Δ͜ͱ͕Ͱ͖Δߏจ

    • ௨ৗ͸Runnerͷ਺͕ڐ͢ݶΓฒྻ࣮ߦ

    • = DAGʹ͓͚ΔϑΝϯΠϯɺϑΝϯΞ΢τΛ࣮ݱͰ͖Δߏจ
    needs:

    View full-size slide

  23. 24
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • jobs..if:

    • jobs..steps[*].if:

    • ͦͷJob΍StepΛ࣮ߦ͢Δ͔Ͳ͏͔ͷ৚݅Λॻ͘͜ͱ͕Ͱ͖
    Δ

    • ޙड़͢ΔContextͷ஋ΛExpressionsΛ࢖ͬͯ৚݅ࣜΛॻ
    ͘

    • ৚݅෼ذΛ࡞੒Մೳͳߏจ
    if:

    View full-size slide

  24. uses:
    25
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • jobs..steps[*].uses:

    • jobs..uses:

    • Action΍Reusable workflowΛݺͼग़͢


    • = ผͷϦϙδτϦʹ·ͰDAGͷൣғΛ޿͛Δߏจ

    View full-size slide

  25. • Expressions
    • PHPer͸ςϯϓϨʔτΤϯδϯ಺ͰόΠϯυͨ͠஋ΛࢀরͰ͖ͨΓɺҰ෦ؔ਺
    ͕࢖͑ͨΓ͢ΔΞϨΛΠϝʔδ͍ͯͩ͘͠͞
    • Context΍؀ڥม਺ΛݺͿͨΊʹ࢖༻
    • if: ηΫγϣϯͰ͸৚݅ࣜΛॻͨ͘Ίʹ࢖͏
    • Context
    • ࠓ࣮ߦ͍ͯ͠ΔWorkflowपลͷίϯςΩετ৘ใΛऔಘͰ͖Δ
    26
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    DAGͷ੍ޚΛ͢ΔͨΊͷExpressions, Context

    View full-size slide

  26. • 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

    View full-size slide

  27. 28
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    Example DAG: fan-in fan-out

    View full-size slide

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

    View full-size slide

  29. • Workflow commands
    • ඪ४ग़ྗ΁ग़ྗ͢Δ࣌ʹҰఆͷϑΥʔϚοτͰग़ྗ͢Δͱ஋Λอ࣋͢Δ͜ͱ͕Մೳ

    • run: echo '::set-output name=SELECTED_COLOR::green’

    • SELECTED_COLORͱ͍͏໊લͰ green ͱ͍͏จࣈྻ͕อ࣋͞ΕΔ

    • ${{ steps..outputs.SELECTED_COLOR }} ͰऔಘՄೳ

    • Artifacts
    • δϣϒؒͰσʔλΛڞ༗͢Δ͜ͱ͕Մೳ

    • جຊతʹ actions/upload-artifactɺactions/download-artifactΛ࢖༻͢Δ
    30
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    DAGͷ֤௖఺͔Β࣍ͷ௖఺΁஋Λ౉ͨ͢Ίʹ࢖͑Δػೳ

    View full-size slide

  30. • ओʹ੒Ռ෺ΛӬଓԽ͢ΔͨΊʹػೳ͢Δ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

    View full-size slide

  31. 32
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    • ؀ڥม਺ GITHUB_*

    • GITHUB_EVENT_PATHʹ͋ΔJSONϑΝΠϧ಺ʹΠϕϯτΛ
    ϑοΫͨ͠ࡍͷϦΫΤετϖΠϩʔυ͕͋Δ

    • ্هΛ࢖͏͜ͱͰStepͷॲཧ্ͰWorkflowͷίϯςΩετʹ
    ͦͬͨಈ͖Λ͢Δ͜ͱ͕Ͱ͖Δ
    Step಺Ͱ͸؀ڥม਺͔ΒGitHub Actionsͷ৘ใΛऔಘՄೳ

    View full-size slide

  32. 33
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    “GitHub Actions Deep Dive


    using PHP”

    View full-size slide

  33. 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

    View full-size slide

  34. 35
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    GITHUB_EVENT_PATHͷJSONΛdumpͯ͠ΈΔ
    • uses: k1LoW/github-script-php@v0 Ͱݺͼग़͚ͩ͢


    • uses: actions/checkout@v3 ΋͍Βͳ͍

    View full-size slide

  35. 36
    ϫʔΫϑϩʔΤϯδϯͱͯ͠ͷGitHub Actions
    ͍Ζ͍Ζ৘ใ͕औಘͰ͖Δͷ͕Θ͔Δ

    View full-size slide

  36. 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 ϓϥοτϑΥʔϜͷͨΊͷΧελϜ
    ΞϓϦέʔγϣϯͰɺෳࡶ͕ͩසൟʹ܁Γฦ͞ΕΔλεΫΛ࣮
    ߦ͢Δ΋ͷͰ͢ɻ

    View full-size slide

  37. 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ʣ

    View full-size slide

  38. 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ͷ࣮ߦ؀ڥ

    View full-size slide

  39. • ௨ৗͷJob
    • શͯͷStep͕ಉ͡؀ڥɻsetup-phpͳͲ΋ɺ౎౓RunnerʹPHPΛΠϯετʔϧ͍ͯ͠
    Δ
    41
    Action
    1. શͯͷStepΛ௚઀Runner্Ͱ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. 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ͷछྨ

    View full-size slide

  43. 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ίϚϯυΛ࣮ߦ͢Ε͹ྑ͍

    View full-size slide

  44. 46
    Action
    “GitHub Actions Deep Dive


    using PHP”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  47. • ActionͷઃఆϑΝΠϧ
    • ίϯϑΟάϑΝΠϧͷύεͷ೚ҙࢦ
    ఆͱPhan࣮ߦ࣌ͷexit statusΛແࢹ
    ͢ΔͨΊͷઃఆΛ௥Ճ
    Action
    49
    action.yml

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  51. 53
    Action
    ੩తղੳͰ͖ͨ

    View full-size slide

  52. • GitHubϦϙδτϦͷΞϓϦέʔγϣϯίʔυͷCI/CD؀ڥͱͯ͠΋ਃ͠෼ͳ͍͕ɺͦΕ͚ͩ
    Ͱ͸ͳ͍
    • ͞·͟·ͳΠϕϯτͰτϦΨʔͰ͖ΔϫʔΫϑϩʔΤϯδϯͱͯ͠ΈΔͱ׆༻ൣғ͸޿͕Δ
    • Action΋ඇৗʹ؆୯ʹ࡞ΕΔɻʢ͋ΔҙຯʣPHPͰ΋࡞ΕΔɻ
    • ࠓճ࿩͍ͤͯͳ͍͜ͱ΋ଟ਺ɻ
    • jobs..services: ΍ ACTIONS_RUNNER_DEBUG ΍ OIDC ΍ ηΩϡϦςΟͳ
    Ͳ
    • GitHub Actions͸Ԟ͕ਂ͍ɻGitHub ActionsͰ͓࿩͠͠·͠ΐ͏ɻ
    55
    ͓ΘΓʹ
    GitHub Actions͸Ԟ͕ਂ͍

    View full-size slide

  53. Thank You!
    Thank You!
    56

    View full-size slide