コードで学ぶGitHub Actions(beta) / learn github actions beta with code

7e62d3d04b8053778b6d03f3b19cd289?s=47 Shinichi Matsumoto
October 17, 2019
72

コードで学ぶGitHub Actions(beta) / learn github actions beta with code

7e62d3d04b8053778b6d03f3b19cd289?s=128

Shinichi Matsumoto

October 17, 2019
Tweet

Transcript

  1. ίʔυͰֶͿ GitHub Actions (beta) 2019-10-17 ฏ੒.rb #9 দຊ ਅҰ (@matt59649858)

  2. ࣗݾ঺հ • দຊਅҰ • GitHub: matt-note • Twitter: @matt59649858 •

    ໌೔ɺ౦ژʹҾͬӽ͢༧ఆɻ ITษڧձ༻ͷ ໊ࢗδΣωϨʔλʔΛ ࡞Γ·ͨ͠ɻ →
  3. ࠓ೔͓࿩͢͠Δ͜ͱ 1. GitHub Actionsͷ֓ཁ 2. RubyϦϙδτϦͰGitHub ActionsΛֶͿ

  4. 1. GitHub Actionsͷ֓ཁ

  5. GitHub Actionsͱ͸ • GitHubͷCI/CDػೳʢޙड़͠·͢ʣɻ • 2019೥11݄13೔ʹਖ਼ࣜ൛ΛϦϦʔεʢถࠃ࣌ؒʣɻ • publicϦϙδτϦ͸׬શແྉɻ • 1ϦϙδτϦ౰ͨΓ20ฒྻ·ͰδϣϒΛ࣮ߦͰ͖Δɻ

  6. CI (ܧଓతΠϯςάϨʔγϣϯ)ͱ͸ • ։ൃऀ͕ίʔυΛมߋɾίϛοτͯ͠ϦϙδτϦʹ ϓογϡͨ࣌͠ʹɺࣗಈԽͨ͠ϏϧυͱςετΛ࣮ߦ ͢Διϑτ΢ΣΞ։ൃख๏ɻ → GitHubͰ׬݁͢Δ Α͏ʹͳͬͨɻ

  7. CD (ܧଓతσϦόϦʔ)ͱ͸ • ܧଓతΠϯςάϨʔγϣϯ(CI)Λ֦ுͨ͠ख๏Ͱɺ Ϗϧυ΍ςετ͚ͩͰͳ͘ɺϦϦʔεϓϩηεશମΛ ࣗಈԽ͢Δɻ

  8. ฒྻͱ͸ • ಉ࣌ʹෳ਺ͷδϣϒΛ࣮ߦ͢Δɻ • ॲཧ͕࣌ؒ୹͘ͳΔɻ

  9. 20ฒྻɺຊ౰ʹͯ͘͢͝ɺ શ෦ԣʹฒ΂Ε͹ ͙͢ऴΘΔͱ͍͏ঢ়ଶ —— @hsbt

  10. 2. RubyϦϙδτϦͰ GitHub ActionsΛֶͿ

  11. RubyϦϙδτϦ • ruby/rubyϦϙδτϦͰɹɹɹɹɹɹɹɹɹɹɹ GitHub Actions͕ಋೖ͞Ε͍ͯΔɻ

  12. .github/workflows • .github/workflows σΟϨΫτϦʹɹɹɹɹɹɹɹɹ ϫʔΫϑϩʔΛهड़ͨ͠YAMLϑΝΠϧΛ࡞੒ɾίϛο τͯ͠ϓογϡ͢Δ͚ͩͰGitHub Actions͕ಈ࡞͢Δɻ

  13. ϫʔΫϑϩʔͱ͸ • ࣗಈԽͨ͠ॲཧͷ͜ͱɻ • Ϗϧυ΍ςετͳͲΛߦ͏ɻ

  14. ubuntu.yml (8ߦ໨·Ͱ) • name • on

  15. name • ϫʔΫϑϩʔͷ໊લΛઃఆ͢Δɻ

  16. on • Ͳ͏͍͏࣌ʹϫʔΫϑϩʔΛ࣮ߦ͢Δ͔ઃఆ͢Δɻ

  17. on matzbotʹΑͬͯmasterϒϥϯν͕ push͞ΕͨͷͰɺϫʔΫϑϩʔΛ࣮ߦɻ XrXr͞Μ͔Βpull_request͕͋ͬͨͷͰ ϫʔΫϑϩʔΛ࣮ߦɻ ↓ ↓

  18. ubuntu.yml (20ߦ໨·Ͱ) • ͋ͱ͸jobsΛઃఆ͢Δ͚ͩɻ →

  19. jobs • ࣗಈԽ͍ͨ͠δϣϒΛ·ͱΊͯઃఆ͢Δɻ

  20. jobs.<job_id> • jobsͷԼͷ֊૚Ͱɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹ ֤δϣϒͷIDΛจࣈྻܕͰઃఆ͢Δɻ ←δϣϒͷ࣮ߦ݁Ռ͸ ɹjob_idͰදࣔ͞ΕΔɻ ← job_id͸latest

  21. jobs.<job_id>.runs-on • δϣϒΛ࣮ߦ͢ΔԾ૝؀ڥͷछྨΛઃఆ͢Δɻ ↑ ubuntu-latest؀ڥͰδϣϒΛ࣮ߦ͢Δɻ

  22. jobs.<job_id>.steps • ࣗಈԽ͍ͨ͠ॲཧΛॱ൪ʹઃఆ͍ͯ͘͠ɻ

  23. jobs.<job_id>.steps.run • Ծ૝؀ڥͷγΣϧͰ࣮ߦ͢ΔॲཧΛઃఆ͢Δɻ →

  24. jobs.<job_id>.steps.name • εςοϓͰදࣔ͢Δ໊લΛઃఆ͢Δɻ →

  25. jobs.<job_id>.steps.env • Ծ૝؀ڥͰεςοϓ͕࢖͏؀ڥม਺ΛઃఆͰ͖Δɻ →

  26. ${{ toJson() }} • ${{ }} Ͱಈతʹ஋Λઃఆ͢Δɻ • toJson͸GitHub Actionsʹ૊Έࠐ·Ε͍ͯΔσόοά༻

    ͷؔ਺ɻίϯςΩετͷ৘ใΛσόοά͢ΔͨΊʹ࢖ ͏ɻ
  27. githubίϯςΩετσʔλ • ϫʔΫϑϩʔ࣮ߦ࣌ͷ৘ใ͸ίϯςΩετʹอ࣋͞Ε ΔɻgithubίϯςΩετσʔλ͸؀ڥม਺ͰಡΈऔΔ ͜ͱ͕Ͱ͖Δɻ

  28. job.<job_id>.steps.if • ಛఆͷ৚݅Λຬͨ͢ͱ͖͚ͩεςοϓΛ࣮ߦ͢ΔΑ͏ʹ ઃఆͰ͖Δɻ push͕͋ͬͯδϣϒͷ࣮ߦʹࣦഊͨ࣌͠ʹ͚ͩ githubίϯςΩετσʔλΛදࣔͯ͠σόοά͢Δɻ ↓

  29. jobs.<job_id>.steps.uses • δϣϒͰεςοϓͷҰ෦ͱ࣮ͯ͠ߦ͞ΕΔΞΫγϣϯΛ ઃఆ͢Δɻ ↓ GitHubͷpublicϦϙδτϦΛࢦఆͯ͠ɺ ఆٛ͞Ε͍ͯΔΞΫγϣϯΛ࣮ߦ͢Δɻ

  30. Jobs.<job_id>.steps.with • ΞΫγϣϯʹ౉͢ೖྗ஋Λઃఆ͢Δɻ ↓ slackʹ௨஌͢ΔΞΫγϣϯΛ࣮ߦ͢Δ࣌ʹɺ payloadͷ஋Λ౉͢ɻ

  31. ͓·͚ RailsΞϓϦͰGitHub ActionsΛ ࢖ͬͨྫ https://github.com/matt-note/it-benkyoukai-meishi-generator/blob/master/.github/ workflows/rails-ci.yml https://github.com/matt-note/it-benkyoukai-meishi-generator/actions

  32. ͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ

  33. ࢀߟURL • https://github.blog/2019-08-01-why-you-need-to-be-at-github-universe-2019/ • ιϑτ։ൃʹ͓͢͢ΊͷCI(ܧଓతΠϯςάϨʔγϣϯ)πʔϧͱ͸ʢhttps://persol-tech-s.co.jp/ hatalabo/it_engineer/309.htmlʣ • CD(ܧଓతσϦόϦʔ)ͱ͸ʢhttps://cloudbees.techmatrix.jp/devops/cd/ʣ • ฒߦॲཧɺฒྻॲཧͷ͋Ε͜Εʢhttps://qiita.com/Kohei909Otsuka/items/

    26be74de803d195b37bdʣ • GitHub Actions ͕ϩʔϯν͞ΕͨͷͰϚΠάϨʔτͯ͠Δ ʢhttps://www.hsbt.org/diary/ 20190811.htmlʣ • RubyϦϙδτϦ ʢhttps://github.com/ruby/rubyʣ • ৽ GitHub Actions ೖ໳ (https://www.kaizenprogrammer.com/entry/2019/08/18/205010) • GitHub ActionsͷϫʔΫϑϩʔߏจ (https://help.github.com/ja/articles/workflow-syntax-for-github- actions) • GitHub Actions ͷίϯςΩετ͓Αͼࣜͷߏจ (https://help.github.com/ja/articles/contexts-and- expression-syntax-for-github-actions)