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

脱初心者のための GitHub Actions

脱初心者のための GitHub Actions

「GitHub Actionsって聞いたことあるけど、よく理解していない」
「知ってるけど使ったことない」
という方向けの内容です。

897f2389f9228d4ef123f4196e75f3a4?s=128

yukimasa ikeda

January 13, 2022
Tweet

Transcript

  1. ୤ॳ৺ऀͷͨΊͷ GitHub Actions ϛϥΠτσβΠϯ / ϖνΦϒ 2021.08.12 / Yukimasa Ikeda

  2. ࣗݾ঺հ • ஑ా ༗ًক / Yukimasa Ikeda • 1994೥ੜ·Ε ਆಸ઒ݝԣ඿ࢢग़਎

    • 2015/04ʙ2018/12 ધһ • 2019/06ʙ2021/08 ΤϯδχΞ • Rails, iOS, Android, Laravel, React, Next.js
  3. ࠓճͷର৅ • GitHub Actionsͬͯฉ͍ͨ͜ͱ͋Δ͚Ͳɺ 
 Α͘ཧղ͍ͯ͠ͳ͍ • GitHub Actions͸஌ͬͯΔ͚Ͳ࢖ͬͨ͜ͱ͕ ͳ͍

  4. ࿩͢಺༰ 1. GitHub Actionsͱ͸ʁ 2. GitHub Actionsͷ࢖͍ํ 3. ࣮ࡍʹಈ͔ͯ֬͠ೝͯ͠ΈΔ

  5. GitHub Actionsͱ͸ʁ

  6. GitHub Actionsͱ͸ʁ 6 • CI/CDͷαʔϏε • ϦϙδτϦͱ࿈ܞ͠ɺϏϧυɾ 
 ςετɾσϓϩΠΛࣗಈԽͤ͞Δ •

    GitHubͷϑΝʔετύʔςΟ੡ ͳͷͰIssue΍PRͱͷ࿈ܞ͕Մೳ GitHub Actionsͷಛ௃
  7. GitHub Actionsͱ͸ʁ 7 GitHub Actionsͷྉۚ

  8. GitHub Actionsͱ͸ʁ 8 GitHub Actionsͷྉۚ

  9. Ϋϥ΢υܕCI/CDαʔϏεͷਓؾ౓ͷൺֱ

  10. GitHub Actionsͷ࢖͍ํ

  11. GitHub Actionsͷ࢖͍ํ ϫʔΫϑϩʔΛઃఆ͢Δ

  12. GitHub Actionsͷ࢖͍ํ 12 ϫʔΫϑϩʔͱ͸ʁ • ϏϧυɾςετɾσϓϩΠͳͲɺͦͷଞϦϙδτϦ಺ͰԿ͔͠Βࣗಈ Խ͞Εͨϓϩηε • push΍PRɺWebhookΛ࢖༻ͨ͠֎෦ΠϕϯτͳͲΛτϦΨʔʹಈ࡞ ͢Δ

    • Կ͔͠ΒͷλεΫΛ࣮ߦ͢Δδϣϒ͔Βߏ੒͞ΕΔ • YAMLܗࣜͰઃఆϑΝΠϧΛ࡞੒͢Δ
  13. GitHub Actionsͷ࢖͍ํ 13 ϫʔΫϑϩʔͷ࡞੒ • ϦϙδτϦʹ .github/workflows ͱ͍͏σΟϨΫτϦΛ࡞੒͠ɺ ͦͷ௚Լʹ .yml

    ͔ .yaml ͱ͍͏֦ுࢠͰϫʔΫϑϩʔͷઃఆϑΝ ΠϧΛ࡞੒ • ϑΝΠϧ໊͸ࣗ༝ • ϫʔΫϑϩʔ͝ͱʹෳ਺ϑΝΠϧΛ࡞੒͢Δ͜ͱ΋Մೳ
  14. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v GitHub Actionsެࣜͷαϯ ϓϧͷϫʔΫϑϩʔ GitHub Actionsͷ࢖͍ํ ެࣜͷwork fl ow
  15. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v GitHubϦϙδτϦʹදࣔ͞ ΕΔϫʔΫϑϩʔͷ໊લɻ লུՄೳͰɺলུ͢Δͱ૬ ରύε໊͕લͱͳΔɻ GitHub Actionsͷ࢖͍ํ name:
  16. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v ඞਢ 
 τϦΨʔͱͳΔΠϕϯτͷ ໊લɻ 1ͭͷΠϕϯτ΋͘͠͸ෳ਺ ͷΠϕϯτΛࢦఆ͢Δ͜ͱ ͕Ͱ͖Δɻ GitHub Actionsͷ࢖͍ํ on:
  17. name: learn-github-actions on: [push, pull_request ] jobs : check-bats-version :

    runs-on: ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v ෳ਺ͷ৔߹͸഑ྻͰࢦఆ͢ Δ͜ͱ͕Մೳɻ GitHub Actionsͷ࢖͍ํ on:
  18. name: learn-github-actions on : push : branches : - main

    pull_request : branches : - main jobs : check-bats-version : runs-on: ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v Πϕϯτ͝ͱʹઃఆΛߦ͏ ৔߹͸ɺͦΕͧΕͷΠϕϯ τʹରͯ͠ઃఆ͢Δඞཁ͕ ͋Δɻ ઃఆ͕ͳ͍Πϕϯτ΋ؚΊ ίϩϯʢ:ʣΛ௥Ճ͢Δ GitHub Actionsͷ࢖͍ํ on:
  19. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v ϫʔΫϑϩʔϑΝΠϧͰ࣮ ߦ͞ΕΔશͯͷδϣϒΛά ϧʔϓԽ͢Δɻ 
 sampleͰ͸
 check-bats-versio n ͱ͍͏໊લͷJobΛ1͚ͭͩ ఆ͍ٛͯ͠Δɻ GitHub Actionsͷ࢖͍ํ jobs:
  20. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v ඞਢ Ծ૝Ϛγϯͷࢦఆɻ sanpleͰ͸Ubuntu LinuxͰ ࣮ߦ͢ΔΑ͏ʹઃఆΛͯ͠ ͍Δ GitHub Actionsͷ࢖͍ํ run-on:
  21. αϙʔτ͞Ε͍ͯΔԾ૝Ϛγϯ

  22. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v ίϚϯυΛ࣮ߦͰ͖Δλε Ϋɻ Կ͔͠ΒͷίϚϯυΛ࣮ߦ ͢Δ͔ɺԿ͔͠ΒͷΞΫ γϣϯΛݺͼग़͢ɻ uses͸ΞΫγϣϯɺ 
 run͸ίϚϯυΛࢦఆ͢Δɻ GitHub Actionsͷ࢖͍ํ steps:
  23. GitHub Actionsͷ࢖͍ํ 23 Action • StepΛߏ੒͢Δ࠷খ୯ҐͰɺԿ͔͠ΒͷॲཧͷմΛද͢ • GitHub Actions͕ఏڙ͍ͯͨ͠ΓɺಠࣗͷΞΫγϣϯΛ࡞੒͢Δ͜ͱ͕Ͱ ͖Δ

    • ύϒϦοΫϦϙδτϦ΍DockerϨδετϦͰެ։͞ΕͨΞΫγϣϯΛ࣮ߦ ͢Δ͜ͱ͕Ͱ͖Δ
  24. name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on:

    ubuntu-latest steps : - name: First step uses: actions/checkout@v 2 - name: Setup node uses: actions/setup-node@v 1 - name: Install bats run: npm install -g bat s - name: Bats version run: bats -v step͸GitHubͰදࣔ͞ΕΔ ໊લΛ͚ͭΔ͜ͱ͕Ͱ͖ Δɻ GitHub Actionsͷ࢖͍ํ steps:
  25. GitHubͷActionsͰ֬ೝ͢Δͱ໊લ͕͍͍ͭͯΔ

  26. ࣮ࡍʹαϯϓϧΛ࣮ߦͯ͠ΈΑ͏ʂ

  27. ϦϙδτϦΛ࡞੒࣮ͯ͠ࡍʹ֬ೝͯ͠ΈΔ # ϦϙδτϦΛ࡞੒ $ mkdir github-actions-sampl e $ cd github-actions-sampl

    e # ࢦఆͷσΟϨΫτϦΛ࡞੒ $ mkdir -p .github/workflow s # ϫʔΫϑϩʔΛ࡞੒ $ vi .github/workflows/learn-github-actions.ym l # pushͯ͠ActionsΛ֬ೝ͢Δ $ git ini t $ git add . $ git commit -m "Initial commit " $ git remote add origin [ϦϙδτϦurl ] $ git push -u origin main name: learn-github-actions on: [push ] jobs : check-bats-version : runs-on: ubuntu-latest steps : - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - run: npm install -g bats - run: bats -v
  28. ·ͱΊ

  29. ·ͱΊ 29 GitHub Actionsͱ͸ʁ • ϦϙδτϦͱ࿈ܞͯ͠ɺϏϧυɾςετɾσϓϩΠͳͲͦͷଞ༷ʑͳ ϓϩηεΛࣗಈԽͤ͞ΔCI/CDͷαʔϏε • όϒϦοΫϦϙδτϦ͸ແྉɺϓϥΠϕʔτϦϙδτϦ͸Ұ෦ແྉͰ ࢖༻Մೳ

    • YAMLܗࣜͷϫʔΫϑϩʔΛ࡞੒͢Δ͚ͩͰ࣮ߦՄೳ
  30. Thank you! yukimasa @yyykms123