$30 off During Our Annual Pro Sale. View Details »

はてなブログ作成から投稿までをGitHub Actionsで自動化する

M-Yamashita
November 02, 2022

はてなブログ作成から投稿までをGitHub Actionsで自動化する

【LT満員御礼!】自動化大好きエンジニアLT会 - vol.9の登壇資料です。
https://rakus.connpass.com/event/259685/

M-Yamashita

November 02, 2022
Tweet

More Decks by M-Yamashita

Other Decks in Programming

Transcript

  1. 2022-11-02 ࣗಈԽେ޷͖ΤϯδχΞLTձ - vol.9 ͸ͯͳϒϩά࡞੒͔Β౤ߘ·ͰΛ GitHub ActionsͰࣗಈԽ͢Δ M-Yamashita

  2. • ࢁԼ խਓ • όοΫΤϯυΤϯδχΞ • ॴଐ: גࣜձࣾΞΠΩϡʔϒυγεςϜζ • GitHub

    Actions ͕޷͖ • GitHub: @M-Yamashita01 • Twitter: @M_Yamashii ࣗݾ঺հ
  3. • ຖ݄ͷৼΓฦΓΛ͸ͯͳϒϩάʹࣥචத എܠ

  4. ϒϩά࡞੒ͷաఔͰຖճൃੜ͢Δ୯७࡞ۀ

  5. ੵ΋ΔετϨε

  6. • ৽ن౤ߘ࣌͸ɺաڈͷϒϩάͷ߲໨Λίϐϖͯ͠৽͘͠จষΛهࡌ • VSCode্ͰจষΛtextlintͰνΣοΫ͠ɺ͸ͯͳϒϩάʹసه • VSCodeͱ͸ͯͳϒϩάͷߦ͖དྷ͕ਏ͍ ࠔͬͨ͜ͱ

  7. Ͳ͏ͳͬͨΒخ͍͠ʁ

  8. Ͳ͏ͳͬͨΒخ͍͠ʁ • จষΛॻ͘πʔϧ͸VSCode͚ͩʹ͍ͨ͠ • ͸ͯͳϒϩάΛ৮ΒͣʹVSCodeͱGitHubͰԼॻ͖͔Βެ։·Ͱ׬͍݁ͤͨ͞ • ։ൃͱಉ͡Α͏ʹGitHub্ͷϒϥϯν࡞੒΍Pull RequestͰ͸ͯͳϒϩάͷ
 ࡞੒ɺߋ৽Λ͍ͨ͠

  9. ԿΛ૊Έ߹ΘͤΔ͔ʁ

  10. GitHubͷΠϕϯττϦΨʔʹ͸ GitHub Actions͕૬ੑ͕ྑ͍

  11. ໰୊͸ ͸ͯͳϒϩάͷૢ࡞

  12. ͸ͯͳϒϩάAtomPub https://developer.hatena.ne.jp/ja/documents/blog/apis/atom

  13. ͸ͯͳϒϩάAtomPub ϒϩάͷࢀরɺ࡞੒ɺެ։ɺ࡟আΛ REST APIͰՄೳ

  14. ͜ͷREST APIΛ࢖͏OSS͸ͳ͍͔ʁ

  15. blogsync

  16. • ͸ͯͳBlog༻ͷCLIΫϥΠΞϯτ blogsync https://github.com/x-motemen/blogsync

  17. ࢖͑ͦ͏ʂ

  18. ϫʔΫϑϩʔΛ࡞ΔͨΊʹ blogsyncͷ࢓༷Λཧղ͢Δ

  19. ཧղ͢Δ࢓༷͸ ϒϩάͷϑΥʔϚοτɺ౤ߘํ๏ɺߋ৽ํ๏ͷ3ͭ

  20. ϒϩάͷϑΥʔϚοτ

  21. blogsyncͷ࢓༷ʢϒϩάͷϑΥʔϚοτʣ

  22. ϒϩάͷ౤ߘํ๏

  23. blogsyncͷ࢓༷ʢϒϩάͷ౤ߘʣ

  24. blogsyncͷ࢓༷ʢϒϩάͷ౤ߘʣ

  25. • ΤϯτϦ౤ߘ͸ඪ४ೖྗ͔Β΋ड͚औΕΔ • Լॻ͖ͷςϯϓϨʔτΛdraft.mdͱ͓ͯ͘͜͠ͱͰɺҎԼίϚϯυͰ؆୯ʹϒ ϩάΛ࡞੒Ͱ͖Δ • $ blogsync post --draft

    xxx.hatenablog.com < draft.md blogsyncͷ࢓༷ʢϒϩάͷ౤ߘʣ
  26. • blogsync post ίϚϯυΛ࣮ߦ͢ΔͱɺҎԼϑΝΠϧύεʹԼॻ͖ϒϩά͕
 ग़དྷ্͕Δ • project_root/xxx.hatenablog.com/entry/yyyy/mm/dd/hhmmss.md • ྫɿ2022/01/02 03:04:05ʹίϚϯυΛ࣮ߦͨ͠৔߹ͷϒϩάͷϑΝΠϧύε

    • project_root/xxx.hatenablog.com/entry/2022/01/02/030405.md blogsyncͷ࢓༷ʢϒϩάͷ౤ߘʣ
  27. ϒϩάͷߋ৽ํ๏

  28. blogsyncͷ࢓༷ʢϒϩάͷߋ৽ʣ

  29. • PushίϚϯυͰ͸ͯͳϒϩάͷԼॻ͖Λߋ৽Ͱ͖Δ • ͨͩ͠ߋ৽ޙͷهࣄ͸جຊతʹ৽͘͠࡞੒͞Εͯ͠·͏ blogsyncͷ࢓༷ʢϒϩάͷߋ৽ʣ

  30. Ͳ͏͍͏͜ͱʁ

  31. • ϒϩάͷϑΝΠϧύε • project_root/xxx.hatenablog.com/entry/2022/01/02/030405.md • ͜ͷϒϩάΛฤू͠ɺཌ೔blogsync push͢Δͱɺಉ͡಺༰Λ࣋ͭ৽͍͠ϒϩ ά͕ग़དྷ্͕Δ • project_root/xxx.hatenablog.com/entry/2022/01/02/030405.md

    • project_root/xxx.hatenablog.com/entry/2022/01/03/040506.md blogsyncͷ࢓༷ʢϒϩάͷߋ৽ʣ
  32. ϫʔΫϑϩʔΛ࡞Δ্Ͱ ஌͓ͬͯ͘΂͖blogsyncͷ࢓༷͸͜͜·Ͱ

  33. ϫʔΫϑϩʔΛ࡞Δ

  34. ϫʔΫϑϩʔ • ࠔͬͨ͜ͱ΍ཧ૝ܗΛݩʹɺҎԼ3ͭͷϫʔΫϑϩʔΛ࡞੒ • ϒϥϯν࡞੒࣌ʹ͸ͯͳϒϩάͷԼॻ͖Λ࡞੒ • Pull Request࣌ʹ͸ͯͳϒϩά্ͷԼॻ͖Λߋ৽ • ϥϕϧઃఆ࣌ʹϒϩάΛެ։

  35. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  36. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ 1.Create branch 2.Event trigger 3. Create blog 4.

    Get blog 5. Commit blog GitHub Actions
  37. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  38. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  39. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  40. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  41. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  42. ͸ͯͳϒϩάͷԼॻ͖࡞੒ ϫʔΫϑϩʔ

  43. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  44. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ 1.Push blog 2.Pull Request 3. Update blog GitHub

    Actions
  45. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  46. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  47. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  48. ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  49. ৽نϒϩά͕࡞੒͞ΕΔ͕ ίϛοτ͠ͳ͍ ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ

  50. ৽نϒϩά͕࡞੒͞ΕΔ͕ ίϛοτ͠ͳ͍ ͸ͯͳϒϩάͷԼॻ͖ߋ৽ ϫʔΫϑϩʔ →ࣥචऀ͕ಉ͡ϑΝΠϧύ εͷϒϩάͰฤू͠ଓ͚Β ΕΔΑ͏ʹ͢ΔͨΊ

  51. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  52. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ 3. Update blog 1.Approve label 2.Event trigger 4.

    Get blog 5.Replace and Commit blog GitHub Actions
  53. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  54. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  55. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  56. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  57. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  58. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  59. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ ɾgitͷཤྺΛอ࣋Ͱ͖Δ ɾϒϩάެ։೔ͱGitHub্ ͷϒϩάͷ೔࣌ͷϑΝΠϧ ύε͕Ұக͢Δ

  60. ͸ͯͳϒϩάͷެ։ ϫʔΫϑϩʔ

  61. ੍ݶࣄ߲ • GitHub্ͷԼॻ͖ϒϩάʹΞοϓϩʔυͨ͠ը૾Λɺ͸ͯͳϒϩά΁ެ։Ͱ ͖ͳ͍ • ͸ͯͳϒϩά্Ͱ௚઀ฤूͨ͠৔߹ɺGitHub্ͷϒϩάͱϚοϐϯάͰ͖ͳ ͍

  62. ·ͱΊ • GitHub ActionsͱblogsyncΛ࢖༻ͯ͠ɺ͸ͯͳϒϩάͷهࣄ࡞੒ɺߋ৽ɺެ։ ΛࣗಈԽͨ͠ • ੍ݶࣄ߲͸͋Δ΋ͷͷɺ୯७Խ࡞ۀΛޮ཰ԽͰ͖ͨ

  63. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ