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

はてなにおけるGitHub Actions活用事例 / GitHub Actions in H...

papix
January 26, 2021

はてなにおけるGitHub Actions活用事例 / GitHub Actions in Hatena

papix

January 26, 2021
Tweet

More Decks by papix

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • papix (id:papix / @__papix__) • גࣜձࣾ͸ͯͳ WebΞϓϦέʔγϣϯΤϯδχΞ (2017೥ʙ)

    • ϒϩάMediaνʔϜ → ϚϯΨνʔϜ • Ұൠࣾஂ๏ਓJapan Perl Associationཧࣄ • ϒϩά: https://papix.hatena(blog.(com|jp)|diary.jp)
  2. GigaViewer • ࣾ಺Ͱ։ൃ͍ͯ͠ΔϚϯΨϏϡʔϫ • ϒϥ΢βͰອըΛಡΉͨΊͷػೳΛఏڙ • Ϗϡʔϫ / τοϓϖʔδ /

    ݕࡧը໘ / ؅ཧը໘ ... • ग़൛༷ࣾ޲͚ʹఏڙ • 11ࣾ / 13ͷαΠτͰ࠾༻
  3. GitHub.comԽͱGitHub Actionsͷొ৔ • ͦͷࠒ, GitHub EnterpriseΛGitHub.comʹஔ͖׵͑Δಈ͖͕͋ͬͨ • ͦͷྲྀΕͷதͰ, GitHub Actions΋ొ৔͖ͯͨ͠

    • ň͜Ε͸࢖͏͔͠ͳ͍!!!ʼn • ...ͱ͍͏͜ͱͰ, ࠷େͷωοΫͩͬͨňςετʼnͷGitHub ActionsԽ 
 ͔ΒऔΓ૊Ή͜ͱʹͨ͠
  4. GitHub Actions • GitHub͕ఏڙ͢ΔCI/CD؀ڥ • Linux, macOS, Windows؀ڥʹରԠ • GitHub

    ActionsͰͷॲཧ͸ϫʔΫϑϩʔΛॻ͘ࣄͰఆٛ • ϦϙδτϦͷ .github/work f l ow σΟϨΫτϦʹYAMLͰهड़
  5. ։ൃ؀ڥͷDockerԽ • ࠷ॳʹ։ൃ؀ڥΛDockerԽ͓͖ͯ͠·͠ΐ͏ • ࣗ෼ͷPCͰςετ͕DockerͰ׬݁͢Ε͹, GitHub ActionsͰ΋ 
 ςετ͸ͪΌΜͱಈ͘͸ͣ! •

    docker-compose.yml ʹඞཁͳϛυϧ΢ΣΞͳͲͷఆٛΛॻ͍ͯ, 
 docker-compose run ͰςετΛ࣮ߦͰ͖ΔΑ͏ʹ͢Δ
  6. ECR͔Β pull͢Δྫ name: tes t on : pull_request : jobs

    : test : - uses: actions/[email protected]. 4 - name: Configure AWS Credential s uses: aws-actions/configure-aws- [email protected]. 5 with: .. . - name: Login to Amazon EC R uses: aws-actions/[email protected]. 1 - name: Pull from EC R run: docker pull ...
  7. self-hosted runner • self-hosted runner͸جຊతʹىಈͬ͠ͺͳ͠ • = ॲཧΛ͍ͯ͠ͳͯ͘΋ίετ͕͔͔Δ • self-hosted

    runner 1୆ʹ͖ͭ1ͭͷॲཧ͔͠ग़དྷͳ͍ • ෳ਺ͷॲཧΛ͚ͨ͠Ε͹, ෳ਺୆ͷself-hosted runner͕ඞཁ
  8. AWS CodeBuild • AWS CodeBuildͳΒ, vCPU 32, ϝϞϦ144GBͷ؀ڥ͕͋Δ! • self-hosted

    runnerͱҧ͍, ౎౓࣮ߦ/౎౓՝ۚ • ͨͩ, ňGitHub Actions͔ΒAWS CodeBuildΛىಈʼn͸Ͳ͏ͳͷ͔? • ͩͬͨΒňJenkins͔ΒAWS CodeBuildΛىಈʼnͰ΋ྑ͘ͳ͍? • ߋʹݴ͑͹ňAWS CodePipelineʼnͰྑ͘ͳ͍???
  9. ϏϧυϚτϦοΫεͷ׆༻ • GitHub Actionsʹ͸ňϏϧυϚτϦοΫεʼnͱ͍͏֓೦͕͋Δ • ຊདྷ͸, Perlͷ5.32ܥ, 5.30ܥ, 5.28ܥ... ͷΑ͏ʹ,

    ෳ਺ͷ؀ڥͰಉ࣌ ʹςετΛ࣮ߦ͢ΔͨΊͷ΋ͷ • ͜ΕΛ࢖ͬͯ, ςετΛ16෼ׂ࣮ͯ͠ߦ͢Δ!!! • ίετ͸౰વ16ഒ͕ͩ, ͦͷ෼ૉૣ͘ऴΘΔͷͰे෼ʹϖΠ͢Δ
  10. ϏϧυϚτϦοΫεͷ׆༻ • ϏϧυϚτϦοΫεͱͯ͠࿈൪Λࢦఆ • = ࿈൪ͷ਺͚ͩςετΛ෼ׂ࣮ͯ͠ߦ͢Δ • ྫ͑͹1͔Β16·Ͱͷ࿈൪ͳΒ, 16෼ׂ •

    f i ndΛ࢖ͬͯςετର৅ͷҰཡΛऔಘ → splitͰ෼ׂ → ࣮ߦ • ஫ҙ఺ͱͯ͠, ςετΛ෼ׂ͢Δ݁Ռ͸ႈ౳Ͱͳ͚Ε͹ͳΒͳ͍
  11. ϫʔΫϑϩʔͷ ༷ࢠ jobs : test : strategy : # ෼ׂͨ͠ςετͷ͏ͪ,

    1͕ͭίέͯ΋ଞͷશͯΛcancel͠ͳ͍Α͏ʹ͢Δ fail-fast: fals e matrix : test_id: ["01", "02", "03"] # ࿈൪Λࢦఆ steps : ... ॾʑͷ४උ .. . # findͱsplitΛ࢖ͬͯ, ςετର৅ͱͳΔϑΝΠϧ໊͕ॻ͔Εͨ # test01, test02, test03 ͱ͍͏ϑΝΠϧΛ࡞੒ - name: Split tests into chunk s run: | find t -name "*.t" -not -type d > test_files.tx t split -n r/${{ strategy.job-total }} \ --numeric-suffixes=1 \ --elide-empty-files test_files.txt tes t # ↑Ͱ࡞ͬͨ test01, test02, test03ͷ͍ͣΕ͔Λର৅ͱͯ͠ # ςετΛ࣮ߦ͢Δ - name: tes t run: | docker-compose run --rm --no-deps app \ carton exec -- prove < test${{ matrix.test_id }} ※ 3෼ׂͷྫ
  12. ϫʔΫϑϩʔͷ ༷ࢠ jobs : prepare : runs-on: ubuntu-20.0 4 steps

    : - uses: actions/[email protected]. 4 - name: Configure AWS Credential s uses: aws-actions/configure-aws- [email protected]. 5 with: .. . # path-to-cache ͱ͍͏ϑΝΠϧΛ # Ωϟογϡ͢Δྫ - uses: papix/[email protected]. 3 env: .. . with : bucket: ${{ env.cache-bucket } } key: ${{ hashFiles('path-to-cache') } } path: path-to-cach e
  13. ϫʔΫϑϩʔͷ ༷ࢠ jobs : prepare : ... prepareͷॲཧ .. .

    test : needs: prepare # needs Ͱ prepare ʹґଘ͢Δ͜ͱΛఆٛ strategy : fail-fast: fals e matrix : id: ["01", "02", "03" ] steps : ... ςετͷॲཧ ...
  14. ͜͏ͯ͠... • ϒϩάͷςετ͸push͔ͯ͠Β7ʙ10෼Ͱऴྃ͢ΔΑ͏ʹͳΓ·ͨ͠ • ͔͠΋, GitHub Actionsͷδϣϒ͸εέʔϧ͢ΔͷͰ, ෳ਺ͷpush͕ ͋ͬͯ΋ৗʹಉ࣌ʹ૸ͬͯ͘ΕΔ! •

    ΄΅ϝϯςφϯεϑϦʔͰ, ։ൃମݧ͕େ෯ʹ޲্!!! • Jenkins࣌୅ͱൺ΂Δͱ, ࢼࢉͰ͸ίετ΋໿2/3ʹͳΓ·ͨ͠ • ※ ແྉ࿮Λߟྀ͠ͳ͍৔߹
  15. σϝϦοτ • ϫʔΫϑϩʔ΍actionͷσόοά͕೉͍͠ • JenkinsͷΑ͏ʹ, ࣮ࡍʹαʔόʔʹೖͬͯڍಈΛݟΔ... ͱ͍͏ͷ͕ ೉͍͠ • σόοάϩΪϯάΛݩʹ,

    ϩά͔Βௐࠪ͢Δඞཁ͕͋Δ • tmuxͷηογϣϯΛੜ΍͢tmateͱaction-tmateΛ࢖ͬͯ 
 SSH઀ଓ͢Δ͜ͱ͸Մೳ͕ͩ...
  16. Linter/Formatter + reviewdog • reviewdog • https://github.com/reviewdog/reviewdog • GitHubͳͲͷίʔυʹίϝϯτΛ࢒͢͜ͱ͕Ͱ͖Δ •

    Linterͷ݁ՌΛ౉͢ͱ, ܯࠂΛग़ͯ͘͠ΕΔ • ྫ rubocop: https://github.com/reviewdog/action-rubocop • work f l ow commandͰΞϊςʔγϣϯΛ෇͚Δํ๏΋͋Γ·͢
  17. Perl::Critic + reviewdog • ৄ͘͠͸... • ňreviewdog x perlcritic x

    Jenkins Ͱ࠷ߴͷ GitHub ϨϏϡʔϥΠ ϑʼn • https://tech.mirrativ.stream/entry/reviewdog-perlcritic-jenkins-for-github-reviewing
  18. GitHub ActionsͰ Perl::CriticΛ࢖͏ name: criti c on : pull_request :

    critic : runs-on: ubuntu-lates t steps : - uses: actions/[email protected]. 4 - name: Setup reviewdo g uses: reviewdog/[email protected]. 2 - name: Criticiz e run: | perlcritic --profile .perlcriticrc --verbose '%f:%l:%c:**%m**, near <code>%r</code>.<br>(Ref: [%p] (https://metacpan.org/pod/Perl::Critic::Policy::%p))\n' lib t | reviewdog -efm=%f:%l:%c:%m -name=perlcritic -reporter=github-pr-review
  19. misspell + reviewdog • misspell: https://github.com/client9/misspell • GoͰॻ͔Εͨ, ϛεεϖϧΛൃݟͯ͘͠ΕΔπʔϧ •

    ίʔυதͷtypoΛڭ͑ͯ͘ΕΔ • reviewdog/action-misspell • Pull Requestʹࣗಈతʹίϝϯτͯ͘͠ΕΔ
  20. GitHub ActionsͰ misspellΛ࢖͏ name: misspel l on : pull_request :

    jobs : misspell : runs-on: ubuntu-lates t steps : - uses: actions/[email protected]. 4 - name: misspel l uses: reviewdog/[email protected]. 0 with : reporter: 'github-pr-review '
  21. ϥϕϧͷ ࣗಈνΣοΫ name: label-chec k on : pull_request : jobs

    : check-labels : runs-on: ubuntu-lates t steps : - uses: danielchabr/pr-labels-checker@v2. 2 with : hasSome: Өڹ͋Γ,Өڹͳ͠