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

効果的な静的解析の CI導入パターンを求めて / Great static analysis with CI

効果的な静的解析の CI導入パターンを求めて / Great static analysis with CI

Yuichi Sugiyama

December 11, 2020
Tweet

More Decks by Yuichi Sugiyama

Other Decks in Technology

Transcript

  1. ޮՌతͳ੩తղੳͷ
    CIಋೖύλʔϯΛٻΊͯ
    PHPConference 2020
    αΠϘ΢ζגࣜձࣾɹਿࢁ ༞Ұ
    @oogFranz
    #phpcon #track2

    View full-size slide

  2. Whoami
    • ਿࢁ ༞Ұ @oogFranz
    • αΠϘ΢ζ6೥໨ΤϯδχΞ
    • େاۀ޲͚άϧʔϓ΢ΣΞGaroon࡞ͬͯΔ
    • ෳۀδϟζϛϡʔδγϟϯ@MASHݭָஂ
    • ϦϞʔτϫʔΫͷӨڹͰ඘͕ੜ͑ͨ

    View full-size slide

  3. MASH meets GHIBLI JAZZ
    • https://youtu.be/ZEtTwGen3fI
    • δϒϦۂͷδϓγʔδϟζΞϨϯδCD
    • ੋඇ͓ങ͍ٻΊ͍ͩ͘͞ʂ

    View full-size slide

  4. αΠϘ΢ζ Garoon ͷද޲͖આ໌
    • େن໛޲͚ͷάϧʔϓ΢ΣΞ
    • ੜ࢈ੑɾνʔϜϫʔΫ޲্ͷࢧԉ

    View full-size slide

  5. αΠϘ΢ζ Garoon ͷཪଆઆ໌
    • PHPͱMySQLͰͰ͖ͯΔWebΞϓϦέʔγϣϯ
    • ։ൃ19೥໨
    • PHP͸ 4͔Β7.4ʹʢPHP 8.0Ҡߦ΋ਐΊͯͧ͘ʂʣ
    • PHPͷίʔυ͸180ສߦ͘Β͍

    View full-size slide

  6. αΠϘ΢ζ Garoon ͷཪଆઆ໌
    • PHPͱMySQLͰͰ͖ͯΔWebΞϓϦέʔγϣϯ
    • ։ൃ19೥໨
    • PHP͸ 4͔Β7.4ʹʢPHP 8.0Ҡߦ΋ਐΊͯͧ͘ʂʣ
    • PHPͷίʔυ͸180ສߦ͘Β͍

    ͳ͔ͳ͔ϨΨγʔʂ

    View full-size slide

  7. ϨΨγʔʹཱͪ޲͔͓͏ʂ
    ϨΨγʔίʔυΛ៉ྷʹͯ͠΍Δʂ
    ·ͣ͸طଘ࣮૷ΛΑ͘ಡΜͰΈΑ͏ʂ

    View full-size slide

  8. খੴʹͭ·ͣ͘
    ܕએݴ΋ PHPDoc΋ͳͯ͘ίʔυ͕௥͑ͳ͍ɻɻɻ
    Ҿ਺ʹΑͬͯ͸յΕΔϝιου͕͋Δɻɻɻ
    ͜͜ͷίʔυͣͬͱಡΜͰ͚ͨͲɺ
    ͦ΋ͦ΋୭΋ݺͼग़ͯ͠ͳ͍ɻɻɻʁ

    View full-size slide

  9. খੴʹͭ·ͣ͘
    ܕએݴ΋ PHPDoc΋ͳͯ͘ίʔυ͕௥͑ͳ͍ɻɻɻ
    Ҿ਺ʹΑͬͯ͸յΕΔϝιου͕͋Δɻɻɻ
    ͜͜ͷίʔυͣͬͱಡΜͰ͚ͨͲɺ
    ͦ΋ͦ΋୭΋ݺͼग़ͯ͠ͳ͍ɻɻɻʁ

    ຊ࣭తͳ໰୊ʢઃܭͳͲʣʹͨͲΓண͘લʹɺ
    খ͞ͳ໰୊͕ؾʹͳͬͯίʔυϦʔσΟϯά͕ਐ·ͳ͍

    View full-size slide

  10. ϨΨγʔʹཱͪ޲͔͏ɺͦͷؒʹ΋
    • ৽͍͠ίʔυ͕ͲΜͲΜ૿͍͑ͯ͘
    • طଘίʔυΛ౿ऻ͞ΕΔͷͰɺ
    ͭ·͖ͮ΍͍͢ίʔυ͕૿͑Δ
    • ϝϯόʔʹΑͬͯεΩϧࠩ΋͋Δ

    View full-size slide

  11. ϨΨγʔʹཱͪ޲͔͏ɺͦͷؒʹ΋
    • ৽͍͠ίʔυ͕ͲΜͲΜ૿͍͑ͯ͘
    • طଘίʔυΛ౿ऻ͞ΕΔͷͰɺ
    ͭ·͖ͮ΍͍͢ίʔυ͕૿͑Δ
    • ϝϯόʔʹΑͬͯεΩϧࠩ΋͋Δ

    খੴ͕૿͑ͳ͍Α͏ʹɺͤΊͯ৽نίʔυ͸៉ྷʹ͍ͨ͠

    View full-size slide

  12. খੴΛ·ͣर͏ɾখੴΛ૿΍͞ͳ͍
    • খ͍͞໰୊͕ଟ͍ͱখ͍͞໰୊Ͱؾ͕ࢄΔ
    • খ͍͞໰୊Λ͋Β͔͡ΊݮΒ͢ɾ૿΍͞ͳ͍
    ͜ͱͰΑΓॏେͳ໰୊ʹऔΓ૊Έ΍͘͢ͳΔ

    View full-size slide

  13. খੴΛ·ͣर͏ɾখੴΛ૿΍͞ͳ͍
    • খ͍͞໰୊͕ଟ͍ͱখ͍͞໰୊Ͱؾ͕ࢄΔ
    • খ͍͞໰୊Λ͋Β͔͡ΊݮΒ͢ɾ૿΍͞ͳ͍
    ͜ͱͰΑΓॏେͳ໰୊ʹऔΓ૊Έ΍͘͢ͳΔ
    ੩తղੳπʔϧΛ$*ʹ૊ΈೖΕΑ͏ʂ

    View full-size slide

  14. ࠓ೔ͷͬ͘͟Γ࿩
    • ੩తղੳͷ CI ΛΑ͘͢Δ࿩
    • CIࢹ఺த৺
    • ੩తղੳࣗମΛΑ͘͢Δ࿩΋աڈʹ͠·ͨ͠

    https://speakerdeck.com/oogfranz/how-to-make-your-static-analysis-strong

    View full-size slide

  15. ੩తղੳͱ͸ʁ
    • ίʔυΛ࣮ߦͤͣʹߦ͏ݕূ
    • ͭ·͖ͮͦ͏ͳখੴΛissueͱͯ͠ݟ͚ͭͯ͘ΕΔ
    • όάʹͳΓͦ͏ͳίʔυɺո͍͠ίʔυͷݕ஌
    • ʢ͍͍ͩͨʣૣ͍
    • ʢ͍͍ͩͨʣࣗಈԽ͕͠΍͍͢

    View full-size slide

  16. ͲΜͳখੴɾissueΛݟ͚ͭͯ͘ΕΔʁ
    • ܕͷෆ੔߹
    • ଘࡏ͠ͳ͍ϝιουͷݺͼग़͠
    • ഑ྻͰͳ͍஋ʢboolean, nullͳͲʣ΁ͷ഑ྻΞΫηε
    • ෆཁίʔυ

    View full-size slide


  17. ੲͷPHPʹ͋Γ͕ͪɺࣦഊͨ͠Βfalse

    View full-size slide


  18. ੲͷPHPʹ͋Γ͕ͪɺࣦഊͨ͠Βfalse
    falseʹͳ͍ͬͯΔͱɺҙਤͤͣ΍ΒΕΔ

    View full-size slide


  19. ੲͷPHPʹ͋Γ͕ͪɺࣦഊͨ͠Βfalse
    falseʹͳ͍ͬͯΔͱɺҙਤͤͣ΍ΒΕΔ
    ੩తղੳπʔϧ͕ڭ͑ͯ͘ΕΔʂ

    View full-size slide

  20. ςετ͕ͳ͍ϨΨγʔͰ΋
    • ੩తղੳπʔϧ͸ςετίʔυ͕ͳͯ͘΋ಋೖՄೳ
    • ϓϩμΫτʹʢ΄΅ʣΑΒͣɺಋೖՄೳ
    • ϨΨγʔϓϩμΫτ͸ԟʑʹͯ͠ςετίʔυ͕ͳ͍
    • ςετίʔυ͕ͳͯ͘΋όά΍໰୊Λݟ͚ͭΒΕΔ

    View full-size slide

  21. ςετ͕ͳ͍ϨΨγʔͰ΋
    • ੩తղੳπʔϧ͸ςετίʔυ͕ͳͯ͘΋ಋೖՄೳ
    • ϓϩμΫτʹʢ΄΅ʣΑΒͣɺಋೖՄೳ
    • ϨΨγʔϓϩμΫτ͸ԟʑʹͯ͠ςετίʔυ͕ͳ͍
    • ςετίʔυ͕ͳͯ͘΋όά΍໰୊Λݟ͚ͭΒΕΔ

    ੩తղੳπʔϧΛ$*ʹಋೖ͠Α͏ʂ

    View full-size slide

  22. Q. CIಋೖ͕ͳͥେࣄ͔ʁ

    View full-size slide

  23. Q. CIಋೖ͕ͳͥେࣄ͔ʁ
    • શϝϯόʔ͕࠷௿ݶͷΫΥϦςΟͰίʔυΛॻ͚Δ
    • ϑΟʔυόοΫϧʔϓ͕୹͘ͳΔ

    View full-size slide

  24. ϑΟʔυόοΫϧʔϓͱ͸ʁ
    • ΤϯδχΞɾϓϩμΫτͷԿΒ͔ͷ׆ಈʹɺ
    ϑΟʔυόοΫΛಘͯɺ੡඼ʹ൓ө͢ΔαΠΫϧ
    • e.g.
    • ੡඼ΛϦϦʔεͯ͠ސ٬ͷ൓ԠΛݟΔ
    • ॻ͍ͨίʔυΛϚχϡΞϧςετ͢Δ
    • ίʔυϨϏϡʔΛ͢Δ

    View full-size slide

  25. ϑΟʔυόοΫϧʔϓͷ֊૚
    IUUQTXXXBHJMFDPOOFDUJPODPNBSUJDMFVTJOHGFFECBDLMPPQTCPPTUEFWFMPQNFOUMJGFDZDMFTΑΓҾ༻

    View full-size slide

  26. ϑΟʔυόοΫϧʔϓͷ௕͞
    • ϑΟʔυόοΫ͸ૣ͚Ε͹ૣ͍΄Ͳྑ͍
    • ੩తղੳͷCI͸΋ͬͱ΋୹͍ϧʔϓͰ
    ϑΟʔυόοΫΛಘΒΕΔ
    • ίϛοτ୯ҐͰ੩తղੳͷ݁ՌΛϑΟʔυόοΫ͠Α͏

    View full-size slide

  27. ϑΟʔυόοΫͷ࣭
    • ͙͢ʹϑΟʔυόοΫ͕དྷΔͷͰϑΟʔυόοΫͷ࣭͕େࣄ
    • ཧղɺमਖ਼͸༰қʹ
    • ݟա͝͞Εͳ͍Α͏ʹ
    • ա৒ʹͳΒͳ͍Α͏ʹ
    • Ͱ΋ෆ଍͠ͳ͍Α͏ʹ

    View full-size slide

  28. ϑΟʔυόοΫͷ࣭
    • ͙͢ʹϑΟʔυόοΫ͕དྷΔͷͰϑΟʔυόοΫͷ࣭͕େࣄ
    • ཧղɺमਖ਼͸༰қʹ
    • ݟա͝͞Εͳ͍Α͏ʹ
    • ա৒ʹͳΒͳ͍Α͏ʹ
    • Ͱ΋ෆ଍͠ͳ͍Α͏ʹ

    $*ಋೖ͢Δ͚ͩͰ΋Ғ͍͕ɺ
    ϑΟʔυόοΫΛҙࣝͯ͠ಋೖ͠Α͏ʂ

    View full-size slide

  29. Psalm
    • https://psalm.dev/
    • ʢͨͿΜʣαʔϜ /sάːm, sɑ:lm/ ͱൃԻ͢Δ
    • ࢍඒՎɺ੟Վɺࢻฤͱݴ͏ҙຯ
    • vimeo͕։ൃ
    • ઃఆϑΝΠϧ͸XML

    View full-size slide

  30. ਘৗ͡Όͳ͍issue਺

    View full-size slide

  31. ਘৗ͡Όͳ͍issue਺

    ղੳ݁ՌΛॖখදࣔͨ͠΋ͷʢҰ෦ʣ

    View full-size slide

  32. Phan
    • https://github.com/phan/phan
    • ʢͨͿΜʣϑΝϯ(/fan/)ͱൃԻ͢Δ
    • ར༻ʹphp-astͷ֦ு͕ඞཁ
    • ઃఆϑΝΠϧ͸PHPϑΝΠϧ
    • Etsyࣾͷ։ൃ͕ݩ

    View full-size slide

  33. ਘৗ͡Όͳ͍issue਺

    View full-size slide

  34. ਘৗ͡Όͳ͍issue਺
    ղੳ݁ՌΛॖখදࣔͨ͠΋ͷʢҰ෦ʣ

    View full-size slide

  35. ਘৗ͡Όͳ͍issue਺
    • ͦΕ·Ͱ੩తղੳͰอޢ͞Ε͍ͯͳ͍ίʔυ͸
    جຊతʹແ਺ͷissue͕ใࠂ͞ΕΔ
    • ·ͱ΋ʹऔΓ߹͏ͱ৺͕ંΕΔ

    View full-size slide

  36. ਘৗ͡Όͳ͍issue਺
    • ͦΕ·Ͱ੩తղੳͰอޢ͞Ε͍ͯͳ͍ίʔυ͸
    جຊతʹແ਺ͷissue͕ใࠂ͞ΕΔ
    • ·ͱ΋ʹऔΓ߹͏ͱ৺͕ંΕΔ

    େྔͷJTTVFΛ͍ͳͭͭ͠ɺ
    ੩తղੳͷϝϦοτΛಘΔ࢓૊Έ͕ඞཁ

    View full-size slide

  37. େྔͷissueʹཱͪ޲͔͏
    • ੩తղੳπʔϧʹ͸ಛఆͷissueΛແࢹ͢Δɺ
    ઃఆʢignore, suppressʣ͕༻ҙ͞Ε͍ͯΔ
    • ͜ΕΛར༻ͯ͠ΈΔ

    View full-size slide

  38. Psalm

    https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#config-suppression

    View full-size slide

  39. Psalm

    https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#config-suppression
    type="suppress"Ͱ ཈੍
    ϑΝΠϧ΍σΟϨΫτϦͱ͍ͬͨ୯ҐͰࢦఆՄೳ

    View full-size slide

  40. Phan

    suppress_issue_typesͰࢦఆ

    View full-size slide

  41. PHPStan
    • https://github.com/phpstan/phpstan
    • ݱঢ়ͰҰ൪ਓؾͷ੩తղੳπʔϧ
    • ઃఆϑΝΠϧ͸.neonͱ͍͏yamlͷΑ͏ͳϑΝΠϧ
    • pro൛͕͋ΔʢओʹWeb UIʣ

    View full-size slide

  42. PHPStan

    ΤϥʔϝοηʔδΛਖ਼نදݱͰࢦఆ
    ϑΝΠϧɾσΟϨΫτϦͰର৅Λࢦఆ

    View full-size slide

  43. ͻͱ·ͣsuppress
    • ੩తղੳͷCIΛಋೖ͢Δ͜ͱΛ࠷༏ઌ͢ΔͳΒ͋Γ
    • ͙͢ʹ࣏ͤͳ͍ΤϥʔΛ͢΂ͯಥͬࠐΊ͹ɺ
    CIͰΤϥʔʹͳΒͳ͘ͳΔ

    View full-size slide

  44. suppressͷ໰୊఺
    • suppressͷϧʔϧ͸େຯ͔ɺෳࡶʹͳΔɻ
    • େຯͳઃఆ͸ɺϓϩμΫτશମʹద༻͞ΕΔͨΊɺ
    ৽نͷίʔυͷ੩తղੳ͕ऑ·ͬͯ͠·͏
    • ෳࡶͳϧʔϧ͸ద༻ൣғͷमਖ਼ͳͲ͕ඇৗʹେม

    View full-size slide

  45. suppressϧʔϧͷϝϯςφϯε
    • suppress͞ΕΔൣғ͸গͳ͍ͨ͘͠
    • suppressͷϧʔϧ͸γϯϓϧʹ͍ͨ͠
    ʢର৅ϑΝΠϧɺσΟϨΫτϦɺͳͲʣ

    View full-size slide

  46. suppressϧʔϧͷϝϯςφϯε
    • suppress͞ΕΔൣғ͸গͳ͍ͨ͘͠
    • suppressͷϧʔϧ͸γϯϓϧʹ͍ͨ͠
    ʢର৅ϑΝΠϧɺσΟϨΫτϦɺͳͲʣ

    ࣗಈͰTVQQSFTTϧʔϧ͕ߋ৽͞ΕΔͱخ͍͠

    View full-size slide

  47. suppressϧʔϧͷϝϯςφϯε
    • suppress͞ΕΔൣғ͸গͳ͍ͨ͘͠
    • suppressͷϧʔϧ͸γϯϓϧʹ͍ͨ͠
    ʢର৅ϑΝΠϧɺσΟϨΫτϦɺͳͲʣ

    ࣗಈͰTVQQSFTTϧʔϧ͕ߋ৽͞ΕΔͱخ͍͠
    ੩తղੳπʔϧͷCBTFMJOF
    $*πʔϧͷΩϟογϡ
    ͷ૊Έ߹ΘͤͰղܾʂ

    View full-size slide

  48. baselineͷಋೖ
    • baseline:
    suppress ruleΛࣗಈੜ੒͢Δػೳ
    • طଘͷissueΛه࿥͠ɺ੩తղੳ࣌ʹ͸
    ه࿥͞ΕͨissueΛແࢹ͢Δ


    $ vendor/bin/psalm --save-baseline baseline.xml
    $ vendor/bin/phan --save-baseline baseline.php
    $ vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.neon

    View full-size slide

  49. CIͷΩϟογϡ
    • GitHub Actions, CircleCIͱ͍ͬͨCIπʔϧʹ͸
    աڈͷδϣϒ΍ଞͷδϣϒͷσʔλΛΩϟογϡ͠ɺ
    ࠶ར༻͢Δ࢓૊Έ͕͋Δ
    • ΩʔͱϑΝΠϧΛࢦఆͯ͠อଘ
    • ΩʔΛ෦෼Ұகͯ͠औಘͤ͞Δ͜ͱͰɺ
    աڈͷδϣϒͷσʔλΛར༻Ͱ͖Δ

    View full-size slide

  50. উखʹڧ͘ͳΔ੩తղੳ
    1. ίϛοτͷͨͼʹɺbaselineΛར༻ͯ͠
    ੩తղੳΛ࣮ߦ͢Δ
    2. issue͕ͳ͚Ε͹ɺbaselineΛߋ৽͢Δ
    3. ࣍ͷίϛοτͰ͸৽͍͠baselineΛར༻ͯ͠ɺ
    ੩తղੳΛߦ͏

    View full-size slide

  51. উखʹڧ͘ͳΔ੩తղੳͷྫ
    • CircleCI + Phan ͷྫ
    • ଞͷCIπʔϧʢGitHub ActionsͳͲʣ΍
    ଞͷ੩తղੳπʔϧʢPHPStan, PsalmͳͲʣͰ΋
    Ԡ༻Մೳʢͷ͸ͣʣ

    View full-size slide

  52. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi

    View full-size slide

  53. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    CIʢCircleCIʣͷΩϟογϡ͔Β
    baselineΛऔಘ

    View full-size slide

  54. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    ։ൃதϒϥϯνʹbaseline͕
    ͋Ε͹ͦΕΛར༻

    View full-size slide

  55. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    ։ൃதϒϥϯνʹbaseline͕
    ͳ͚Ε͹developϒϥϯνΛར༻

    View full-size slide

  56. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    ੩తղੳΛ࣮ߦʢ͜͜Ͱ͸Phanʣ

    View full-size slide

  57. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    baseline͕ݟ͔ͭΒͳ͍࣌͸Skip

    View full-size slide

  58. baselineΛར༻ͯ͠੩తղੳ

    phan-load-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - restore_cache:
    name: Restore baseline
    keys:
    - v1-phan-baseline-{{ .BRANCH }}-
    - v1-phan-baseline-develop-
    - run:
    name: Phan
    command: |
    if [[ -f ~/phan_baseline.php ]]; then
    phan ./ --load-baseline ~/phan_baseline.php
    fi
    Ωϟογϡʹอଘ͞Ε͍ͯͨbaselineΛ
    ར༻ͯ͠੩తղੳΛ࣮ߦ

    View full-size slide

  59. baselineΛߋ৽͢Δ

    phan-save-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - run:
    name: Save Phan baseline
    command: |
    set +e
    phan ./ --save-baseline ~/phan_baseline.php
    exit 0
    - save_cache:
    key: v1-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php

    View full-size slide

  60. phan-save-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - run:
    name: Save Phan baseline
    command: |
    set +e
    phan ./ --save-baseline ~/phan_baseline.php
    exit 0
    - save_cache:
    key: v1-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php
    baselineΛߋ৽͢Δ

    baselineΛ࡞੒

    View full-size slide

  61. phan-save-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - run:
    name: Save Phan baseline
    command: |
    set +e
    phan ./ --save-baseline ~/phan_baseline.php
    exit 0
    - save_cache:
    key: v1-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php
    baselineΛߋ৽͢Δ

    ੩తղੳπʔϧʹΑͬͯ͸issue͕ଘࡏ͢Δ
    ͱऴྃίʔυ͕1Λฦ͢ͷͰέΞ͕ඞཁ

    View full-size slide

  62. phan-save-baseline:
    docker:
    - image: docker-registory.cybozu.private/phan:X.Y.Z
    steps:
    - checkout
    - run:
    name: Save Phan baseline
    command: |
    set +e
    phan ./ --save-baseline ~/phan_baseline.php
    exit 0
    - save_cache:
    key: v1-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php
    baselineΛߋ৽͢Δ

    baselineΛΩϟογϡʹอଘ

    View full-size slide

  63. baselineͷϦηοτ
    • ੩తղੳπʔϧͷόʔδϣϯΞοϓͳͲͰ
    baselineΛϦηοτ͍͕ͨ࣌͋͠Δ
    • ΩϟογϡͷΩʔ໊Λมߋ͢Δ

    - save_cache:
    key: v1-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php
    - save_cache:
    key: v2-phan-baseline-{{ .BRANCH }}-{{ .Revision }}
    paths: ~/phan_baseline.php
    ΩϟογϡΩʔ໊Λߋ৽͢Δ

    View full-size slide

  64. ੩తղੳ͕উखʹڧ͘ͳΔʂ

    View full-size slide

  65. ΋ͬͱ੩తղੳΛΑ͍ͨ͘͠ʂ

    View full-size slide

  66. • ϑΟʔυόοΫΛվળ͢Δ

    ͞ΒʹνʔϜͷ੩తղੳମݧΛΑ͘͢ΔTips
    ཧղ༰қʹ͢Δ
    ϑΟʔυόοΫΛૣ͘͢Δ
    ݎ࿚ʹ͢Δ

    View full-size slide

  67. • ϑΟʔυόοΫΛվળ͢Δ

    ͞ΒʹνʔϜͷ੩తղੳମݧΛΑ͘͢ΔTips
    ཧղ༰қʹ͢Δ
    ϑΟʔυόοΫΛૣ͘͢Δ
    ݎ࿚ʹ͢Δ

    View full-size slide

  68. ੩తղੳʹ͔͔Δ࣌ؒΛ୹͘͢Δ
    • CIͰ஗͍ͱ͜ΖʢϘτϧωοΫʣΛվળ͢Δ
    • ϑΟʔυόοΫϧʔϓ͸ૣ͚Ε͹ૣ͍΄Ͳྑ͍
    • GaroonͰ͸
    • git clone
    • ੩తղੳͷ࣮ߦ
    • ͕஗͔ͬͨ

    View full-size slide

  69. git cloneΛૣ͘͢Δ
    • ௕͘։ൃ͍ͯ͠ΔϓϩμΫτͰ͸git clone͕஗͍
    • →shallow cloneΛ͢Δʢ࠷৽ίϛοτ͚ͩऔಘ͢Δʣ
    • Garoonͩͱ໿6ഒૣ͘ͳΔʢ25.2 ඵ → 4.0 ඵʣ

    $ git clone --depth=1 --branch ${CIRCLE_BRANCH} \
    --single-branch ${CIRCLE_REPOSITORY_URL}

    View full-size slide

  70. ੩తղੳʹ͔͔Δ࣌ؒΛ୹͘͢Δ
    • ࠩ෼ͷ͋ͬͨϑΝΠϧ͚ͩ੩తղੳΛ͔͚Δ
    • →shallow cloneΛ͍ͯ͠Δͱ git diff ͕Ͱ͖ͳ͍
    • ผͷํ๏ͰdiffΛऔಘ͢Δ
    • →GitHub ͷϓϧϦΫऔಘ APIΛ࢖͏

    View full-size slide

  71. ϓϧϦΫऔಘ GitHub API

    $curl -H "Authorization: token ${GITHUB_API_TOKEN}" \
    -H 'Accept: application/vnd.github.v3.diff' \

    https://github.dev.cybozu.co.jp/api/v3/repos/garoon/garoon/pulls/14386
    diff --git a/source/page/master/sample.php b/source/page/master/sample.php
    index b644b6edbf5..03624413a6a 100644
    --- a/source/page/master/sample.php
    +++ b/source/page/master/sample.php
    @@ -1,3 +1,4 @@
    +echo "diff test"

    View full-size slide

  72. ϓϧϦΫऔಘ GitHub API

    $curl -H "Authorization: token ${GITHUB_API_TOKEN}" \
    -H 'Accept: application/vnd.github.v3.diff' \

    https://github.dev.cybozu.co.jp/api/v3/repos/garoon/garoon/pulls/14386
    diff --git a/source/page/master/sample.php b/source/page/master/sample.php
    index b644b6edbf5..03624413a6a 100644
    --- a/source/page/master/sample.php
    +++ b/source/page/master/sample.php
    @@ -1,3 +1,4 @@
    +echo "diff test"
    media typeͷࢦఆͰdiff͕औΕΔ
    https://docs.github.com/en/free-pro-team@latest/rest/overview/media-types#commits-commit-comparison-and-pull-requests

    View full-size slide


  73. $curl -H "Authorization: token ${GITHUB_API_TOKEN}" \
    -H 'Accept: application/vnd.github.v3.diff' \

    https://github.dev.cybozu.co.jp/api/v3/repos/garoon/garoon/pulls/14386
    diff --git a/source/page/master/sample.php b/source/page/master/sample.php
    index b644b6edbf5..03624413a6a 100644
    --- a/source/page/master/sample.php
    +++ b/source/page/master/sample.php
    @@ -1,3 +1,4 @@
    +echo "diff test"
    ࡶʹ +++ ͱϑΝΠϧ֦ுࢠΛgrep͢Ε͹ɺ
    ੩తղੳର৅ͷϑΝΠϧ͕औಘͰ͖Δ
    https://docs.github.com/en/free-pro-team@latest/rest/overview/media-types#commits-commit-comparison-and-pull-requests
    ϓϧϦΫऔಘ GitHub API

    View full-size slide

  74. ੩తղੳʹ͔͔Δ࣌ؒΛ୹͘͢Δ
    • Phan͸ͦ΋ͦ΋ಛఆϑΝΠϧͷΈͷ෼ੳ͕Ͱ͖ͳ͍
    • Psalm͸cacheDirectoryΛࢦఆͯ͠ɺ
    ࣮ߦ݁ՌΛΩϟογϡɺ--diff ΦϓγϣϯΛ࢖͏ํ͕ྑͦ͞͏
    • PHPStan΍PHP Code Sniffer (ίʔσΟϯάن໿ͷνΣοΫ
    πʔϧ)Ͱ༗ޮ

    View full-size slide

  75. • ϑΟʔυόοΫΛվળ͢Δ

    ͞ΒʹνʔϜͷ੩తղੳମݧΛΑ͘͢ΔTips
    ཧղ༰қʹ͢Δ
    ϑΟʔυόοΫΛૣ͘͢Δ
    ݎ࿚ʹ͢Δ

    View full-size slide

  76. ൃੜͨ͠issueΛΘ͔Γ΍͘͢͢Δ
    • CIʹΤϥʔϝοηʔδΛಡΈʹ͍͘ͷ͸ΊΜͲ͍͘͞

    View full-size slide

  77. reviewdog

    • issueͷग़ͨͱ͜ΖʹࣗಈͰίϝϯτΛ͚ͭͯ͘ΕΔ
    https://github.com/reviewdog/reviewdog

    View full-size slide

  78. reviewdog

    • issueͷग़ͨͱ͜ΖʹࣗಈͰίϝϯτΛ͚ͭͯ͘ΕΔ
    https://github.com/reviewdog/reviewdog
    GitHub EnterpriseͰ͸API token͕ඞཁ
    APIൃߦऀͷΞΠίϯ͕ग़ΔͷͰ
    νʔϜϝϯόʔ͔ΒݏΘΕ΍͍͢

    View full-size slide

  79. botΞΧ΢ϯτ
    • ਓʹ௚઀ౖΒΕΔΑΓ͸ɺbotʹౖΒΕΔํ͕·ͩϚγ
    • botΞΧ΢ϯτΛ࡞ͬͯӡ༻͍ͯ͠Δ
    • GitHubͩͱɺreviewdogͷΞΠίϯ͕ॻ͖ࠐΜͰ͘ΕΔͷͰ҆৺

    View full-size slide

  80. • ϑΟʔυόοΫΛվળ͢Δ

    ͞ΒʹνʔϜͷ੩తղੳମݧΛΑ͘͢ΔTips
    ཧղ༰қʹ͢Δ
    ϑΟʔυόοΫΛૣ͘͢Δ
    ݎ࿚ʹ͢Δ

    View full-size slide

  81. issueΛϝΠϯϒϥϯνʹऔΓࠐ·ͳ͍
    • GitHub ͷ Branch protection rulesΛ͔ͭ͏

    View full-size slide

  82. issueΛϝΠϯϒϥϯνʹऔΓࠐ·ͳ͍
    • GitHub ͷ Branch protection rulesΛ͔ͭ͏

    CIͷνΣοΫΛϚʔδલʹඞਢʹ͢Δ

    View full-size slide

  83. issueΛϝΠϯϒϥϯνʹऔΓࠐ·ͳ͍
    • GitHub ͷ Branch protection rulesΛ͔ͭ͏

    ඞਢͷCIδϣϒΛબͿ

    View full-size slide

  84. issueΛϝΠϯϒϥϯνʹऔΓࠐ·ͳ͍
    • GitHub ͷ Branch protection rulesΛ͔ͭ͏

    ඞਢͷCIδϣϒΛબͿ

    View full-size slide

  85. issueΛϝΠϯϒϥϯνʹऔΓࠐ·ͳ͍
    • GitHub ͷ Branch protection rulesΛ͔ͭ͏

    ඞਢͷCIδϣϒΛબͿ
    $*͕௨Βͳ͍ͱϚʔδͰ͖ͳ͍ʂ

    View full-size slide

  86. ·ͱΊ
    • ੩తղੳͷCIಋೖͰϨΨγʔʹཱͪ޲͔͓͏ʂ
    • ϑΟʔυόοΫϧʔϓΛҙࣝͯ͠ɺCIΛಋೖ͠Α͏ʂ
    • baselineͰ੩తղੳͷϝϯςφϯείετΛԼ͛Α͏ʂ
    • খٕΛͨ͘͞Μ࢖ͬͯɺ੩తղੳͷମݧΛΑ͘͠Α͏ʂ

    View full-size slide