Clipใใๆฅ: 2024-11-19T10:53:05+09:00
Clipใใ่จไบ: [Terraform Monorepo ใฎ CI ใฎๅฎ่กๆ้ใๅฏ่ฆๅใ 2 ๅไปฅไธ้ซ้ๅ - freee Developers Hub](https://developers.freee.co.jp/entry/2024/11/19/100000)
----
SRE team ใฎ [suzuki-shunsuke](https://github.com/suzuki-shunsuke) ใงใใ ไปๅนดใฎ 8 ๆ(็ด3ใๆๅ)ใใ freee ใฎ SRE team ใซ join ใใพใใใ
ๆฌ่จไบใงใฏ Terraform Monorepo ใฎ CI ใฎๅฎ่กๆ้ใ [CIAnalyzer](https://github.com/Kesin11/CIAnalyzer) ใงๅฏ่ฆๅใ 2 ๅ (70 percentile ใง็ด 160 %) ไปฅไธ้ซ้ๅใใ่ฉฑใ็ดนไปใใพใใ
## ่ๆฏ
freee ใซใฏ AWS ใชใฉใ็ฎก็ใใ Terraform ใฎ Monorepo ใใใใ SRE ใไธญๅฟใซๅคใใฎ้็บ่
ใใใฎใชใใธใใชใง้็บใ่กใฃใฆใใพใใ CI ใซใฏ GitHub Actions ใฎ Self-hosted Runner ใไฝฟใฃใฆใใพใใ ใใญใผใจใใฆใฏ GitHub Flow ใๆก็จใใฆใใใ Pull Request ใไฝๆใใใจ CI ใง terraform plan ใๅฎ่กใใใพใใ terraform apply ใฏ GitHub ใฎ [Merge Queue](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue) ใไฝฟใฃใฆๅฎ่กใใใ terraform apply ใๅคฑๆใใใจใใผใธใใใชใใใใซใชใฃใฆใใพใใ
่ชๅใๅ
ฅ็คพใใๅใใใใฎ CI ใซๆ้ใใใใ้็บ่
ไฝ้จใๆใชใฃใฆใใใจใใ่ชฒ้กใใใใพใใใ ่ชๅใๅ
ฅ็คพใใฆๅฐใ่งฆใฃใใ ใใงใ็ขบใใซ CI ใ้
ใใจๆใใพใใใ
ไธ่ฟฐใฎ้ใ SRE ใไธญๅฟใซๅคใใฎ้็บ่
ใใใฎใชใใธใใชใง้็บใ่กใฃใฆใใใใใใใฎใชใใธใใชใฎ CI ใ้ซ้ๅใใใใจใงๅคใใฎ้็บ่
ใฎ็็ฃๆงใๅไธใซใคใชใใใจ่ใใๆนๅใซๅใ็ตใใใจใซใใพใใใ
## ใใฃใใใจ
ใใฃใใใจใฏๅคงใใๅใใฆๆฌกใฎ 5 ใคใงใใ
1. OKR ใฎ่จญๅฎ
2. ๅฎ่กๆ้ใฎ่จๆธฌใปๅฏ่ฆๅ
3. SLI / SLO ใฎ่จญๅฎ
4. ใใใซใใใฏใฎๅๆ
5. ๆนๅ
### OKR ใฎ่จญๅฎ
ใพใๆๅใซ OKR ใ่จญๅฎใใใใใใจใ็ฐกๆฝใซๆ็ขบใซใใพใใ (ๅฎ้ใฎใใฎใซ่ฅๅนฒๆใๅ ใใฆใใพใ)ใ
- Objective: CI ใ้ซ้ๅใใๅ
จ้็บ่
ใ็ด ๆฉใ Terraform ใงใคใณใใฉใๆง็ฏใใใๅคๆดใๅ ใใใใใใใซใใ้็บ่
ใฎ็็ฃๆงใซ่ฒข็ฎใใ
- KR1: CI ใซใฉใฎใใใใใใฃใฆใใใฎใๅฏ่ฆๅใใใใใคใงใ็ขบ่ชใใใใจใใงใใ
- KR2: SLI/SLO ใๅฎใพใฃใฆใใใ CI ใฎ้ๅบฆใซใคใใฆๅฎข่ฆณ็ใซ่ฉไพกใป่ญฐ่ซใงใใใใใซใชใฃใฆใใ
- KR3: SLO ใ้ๆใใ
### ๅฎ่กๆ้ใฎ่จๆธฌใปๅฏ่ฆๅ
ๆนๅใฎๅใซใพใใฏ CI ใฎๅฎ่กๆ้ใ่จๆธฌใปๅฏ่ฆๅใใๆนๅใ่ฉไพกใงใใใใใซใใๅฟ
่ฆใใใใพใใใ ใใใงใชใใจๆนๅใใใจใใฆใใๅฎ้ๆฌๅฝใซ้ใใชใฃใใฎใใปใฉใฎใใใ้ใใชใฃใใฎใๆ่ฆใงใใๅใใใใๅฎข่ฆณ็ใช่ญฐ่ซใใงใใพใใใ ๅฏ่ฆๅใฎใใใฎใใผใซใจใใฆๆฌกใฎ 2 ใคใๅ่ฃใซไธใใใพใใใ
1. [GitHub Actions Usage Metrics](https://docs.github.com/en/enterprise-cloud@latest/organizations/collaborating-with-groups-in-organizations/viewing-usage-metrics-for-github-actions)
2. [CIAnalyzer](https://github.com/Kesin11/CIAnalyzer)
CIAnalyzer ใซใคใใฆใฏไฝ่
ๆงใฎใใญใฐใๅ็
งใใฆใใ ใใ: [CI/CDใฎใใผใฟใๅ้ใใCIAnalyzerใฎ็ดนไป](https://zenn.dev/kesin11/articles/cf08579949b8b0)
GitHub Actions Usage Metrics ใฏ GitHub ๅ
ฌๅผใฎๆฉ่ฝใงใ Plan ใซใใใใพใใ็นๅฅใชใปใใใขใใใชใใซไฝฟใใพใใ ไธๆน CIAnalyzer ใฏ OSS ใง CIAnalyzer ใๅฎ่กใใ CI ใ BigQuery ใ Looker Studio ใชใฉใฎใปใใใขใใใๅฟ
่ฆใง GitHub Actions Usage Metrics ใใๆ้ใใใใใพใใ
ใใใงใพใใฏ GitHub Actions Usage Metrics ใ็บใใฆใฟใใใจใซใใพใใใ ็บใใฆใฟใ็ตๆใ่ฉณ็ดฐใชใใใซใใใฏใฎๅๆใชใฉใฏ GitHub Actions Usage Metrics ใงใฏ้ฃใใใใจใๅใใใพใใใ
ใใใง CIAnalyzer ใๆง็ฏใใพใใใ ๆ้ใใใใใจใฏๆธใใพใใใใๅ
ฌๅผใฎใใญใฅใกใณใใซๅพใใฐใใปใฉ้ฃใใใฏใใใพใใใ GitHub Actions ใงๅฎๆๅฎ่กใใฆใใผใฟใ BigQuery ใซๅ้ใใใใใซใใพใใใ CIAnalyzer ใงใฏๅ
ฌๅผใซ Looker Studio ใฎใตใณใใซใๆไพใใใฆใใพใใใๆใ
ใฎใใผใบใซใฏใใพใๅใใชใใฃใใใ่ชไฝใใพใใใ ็ตๆใจใใฆใฉใฎ Workflow, Job, step ใซใฉใฎใใใๆ้ใใใใฃใฆใใใใๅใใใใใซใชใใพใใใ
### ่ฃ่ถณ: Actions Performance Metrics ใซใคใใฆ
ใใฎ่จไบใฎๅท็ญไธญใซ [Actions Performance Metrics ใ Public preview ใซใชใใพใใ](https://github.blog/changelog/2024-10-31-actions-performance-metrics-in-public-preview/)ใ Actions Usage Metrics ใจๆฏในใใจๅ Job ใฎๅนณๅๅฎ่กๆ้ใๆๅ็ใชใฉใ่ฆใใฆไพฟๅฉใงใใ Actions Usage Metrics ๅๆง็นๅฅใชใปใใใขใใ็กใใงไฝฟใใใฎใ่ฏใใจใใใงใใ ใใ ใใ step ๅไฝใฎๆ
ๅ ฑใฏๅใใพใใใ CIAnalyzer ใฎใใใซๅฏ่ฆๅใฏๅบๆฅใชใใฎใงใใใฏใ CIAnalyzer ใๅฟ
่ฆใงใใใ
### ่ฃ่ถณ: actions-timeline ใซใคใใฆ
CIAnalyzer ใฎไฝ่
ๆงใไฝใฃใฆใใ [actions-timeline](https://github.com/Kesin11/actions-timeline) ใจใใๅฅใฎใใผใซใซใคใใฆ่ฃ่ถณใใพใใ
[GitHub Actionsใฎใฏใผใฏใใญใผใๅฏ่ฆๅใใactions-timelineใไฝใฃใ](https://zenn.dev/cybozu_ept/articles/20231002_actions_timeline)
actions-timeline ใฏๅใไฝ่
ใ CIAnalyzer ใฎใใจใซไฝใฃใใใฎใงใใ GitHub Star ๆฐใไธๅใฃใฆใใใใจใใใใใใฎใใผใซใใใ็ฅใใชใไบบใใใใใจ actions-timeline ใไฝฟใฃใใปใใ่ฏใใฎใงใฏใชใใใจๆใใใใใใพใใใ ใใใใใใใใฎใใผใซใฏๆฉ่ฝ็ใซๅ
จใ็ฐใชใใใฎใงใใ actions-timeline ใฏๆฑบใใฆ CIAnalyzer ใฎไธไฝไบๆใงใฏใใใพใใใ actions-timeline ใฏ BigQuery ใชใฉใๅฟ
่ฆใจใใ้ๅธธใซๅฐๅ
ฅใๅฎนๆใง workflow ใฎๅฎ่ก็ตๆใ Mermaid ใไฝฟใฃใฆๅใใใใใๆ็ปใใฆใใใใใผใซใงใใใใใใพใงๅใ
ใฎ workflow run ใฎ็ตๆใๅฏ่ฆๅใใใใผใซใงใใใ้ๅปใฎ workflow ใฎๅฎ่ก็ตๆใ่็ฉใใฆ็ตฑ่จ็ใซๅๆใงใใใใใชใใผใซใงใฏใใใพใใใ ไปๅใฎใใใซ CI ใฎๅฎ่ก็ตๆใซ้ขใใใใใทใฅใใผใใๆง็ฏใใใใๆนๅๆดปๅใ่กใฃใ N ใถๆใงใฉใฎใใใ CI ใๆนๅใใใฎใๅฎข่ฆณ็ใซ็คบใใใใใใฎใซใฏไฝฟใใพใใใ ไปๅใฏไปใฎใจใใ actions-timeline ใฎๅฟ
่ฆๆงใๆใใชใใฃใใฎใงๅฐๅ
ฅใใพใใใงใใใ
### SLI / SLO ใฎ่จญๅฎ
CI ใฎ้ๅบฆใซใคใใฆๅฎข่ฆณ็ใซ่ฉไพกใป่ญฐ่ซใงใใใใใซใใใใใฎ SLI/SLO ใ่จญๅฎใใพใใใ Google ใฎ SRE ใๅ
ฌ้ใใฆใใ [The Art of SLOs](https://static.googleusercontent.com/media/sre.google/ja//static/pdf/jp-art-of-slos-handbook-pdf-a4.pdf) ใซใใใจ SLI ใฏ workflow ใฎๅฎ่กๆ้ใฎใใใชใใฎใงใฏใชใ 0 ~ 1 ใซๅใพใใใใชๅคใ่ฏใใจใใใฆใใพใใ ใใใงไปฅไธใฎใใใชใใฎใ SLI ใจใใฆ่จญๅฎใใพใใใ
`ๆๅใใ workflow ใฎใใก็ฎๆจๆ้ไปฅๅ
ใซๅฎไบใใ workflow ใฎๅฒๅ`
ๆฐๅผใง่กจใใจไปฅไธใฎใใใซใชใใพใใ
```
SLI = (ใฟใคใ ใใฌใผใ A ใฎ้ใซ B ๅไปฅๅ
ใซๆๅใใ workflow ใฎๆฐ) / (Aๆ้ใฎใฟใคใ ใใฌใผใ ใฎ้ใซๆๅใใ workflow ใฎๆฐ) * 100%
```
ใใใง 2 ใคใฎใใฉใกใผใฟ A, B ใใใใพใใ
- A: ใฉใฎใใใใฎๆ้ใงใใผใฟใ้่จใใใ (1ๆ้, 1 ๆฅ, etc)
- B: workflow ใฎๅฎ่กๆ้ใฎๆๅพ
ๅค (3 ๅ, 5 ๅ, 10 ๅ, etc)
ใใจใฏ็ฎๆจใจใใ SLI ใฎๅค (SLO) ใใใใพใใ
ใใใใฎใใฉใกใผใฟใใฉใ่จญๅฎใใใใฏๆญฃ่งฃใฎใชใ้ฃใใๅ้กใงใใใๆซๅฎใง่จญๅฎใๅฟ
่ฆใซๅฟใใฆ่ฆ็ดใใใจใซใใพใใใ workflow ใฎๅฎ่กๆ้ใฏ queuedDurationSec + workflowDurationSec ใจใใพใใใ
### ใใใซใใใฏใฎๅๆ
ๆ้ใฎใใใฃใฆใใ Job ใ Step ใ็นๅฎใใใใใซใใใฏใซใชใฃใฆใใใจใใใใๅชๅ
็ใซๆนๅใใพใใใ ใพใ checkout ใซใใใๆ้ใใใใฃใฆใใใใจใๅใใใใใใๆนๅใใใ ใใงใ็ตๆง้ใใชใใใจใๅใใใพใใใ
### ๆนๅ
ๅๆใซๅบใฅใๅฎ้ใซ workflow ใไฟฎๆญฃใ้ซ้ๅใใพใใใ
1. Job ใฎไธฆๅๅฎ่ก
2. Workflow ใ Job ใฎใใผใธ
3. shallow clone
4. sparse checkout
5. ็ก้งใชๅฆ็ใฎๅ้ค
6. ใชใใธใใชใซใณใใใใใใฆใใ zip ใใกใคใซใฎๅ้ค
7. ใใกใคใซใใใฃใฌใฏใใชใฎๅญๅจใใงใใฏใฎใใใ ใใซๆ
ใ
checkout ใใฆใใใฎใ GitHub Content API ใซ็ฝฎใๆใ
8. terrform plan ใ no change ใฎใจใ infracost ใ skip
ๆนๅใฎ PR ใไฝๆใใ้ใฏใไบใๆนๅๅฏพ่ฑกใฎๅฆ็ใซใฉใฎ็จๅบฆๆ้ใใใใฃใฆใใใฎใใใใฃใฆใใใใใใใฎ PR ใซใใฃใฆใฉใฎ็จๅบฆใฎๆนๅใ่ฆ่พผใใใใๅฎข่ฆณ็ใซๅใใใ PR ใซ่ชฌๅพๅใใใใใใใจใๅบๆฅใพใใใ
#### Job ใฎไธฆๅๅฎ่ก
job ใฎไพๅญ้ขไฟใ่ฆ็ดใใ็ดๅใงๅฎ่กใใใฆใใ job ใไธฆๅใงๅฎ่กใใใใใซใใพใใใ
#### Workflow ใ Job ใฎใใผใธ
็ฌ็ซใใ job ใงๅฅใ
ใซๅใๅฆ็ใ่กใฃใฆใใใฑใผในใใใใพใใใไพใใฐ terraform plan ใๅฎ่กใใใกใคใณใฎ workflow ใจใฏๅฅใซ terraform plan ใฎ็ตๆใซๅฏพใใฆ infracost ใๅฎ่กใใ workflow ใใใใไธกๆนใฎ workflow ใง็ฌ็ซใใฆ terraform plan ใๅฎ่กใใฆใใพใใใ ใใใง infracost ใๅฎ่กใใ workflow ใใกใคใณใฎ workflow ใจใใผใธใใใใจใง็ก้งใช workflow ใฎๅฎ่กใใชใใใพใใใ ใใใฏ้ซ้ๅใจใใใใใฏ Self hosted Runner ใฎใชใฝใผในๅน็ใฎๆนๅใจใ่จใใพใใ
workflow ใ job ใๅๅฒใใฆไธฆๅๅฎ่กใใฆ้ซ้ๅใใๅ ดๅใใใใพใใใ Job ใๅฎ่กใใใฐ Job ใๅฎ่กใใ Node ใฎในใฑใธใฅใผใชใณใฐใใปใใใขใใใใใใใชใซใใใชใใฆใใชใผใใผใใใใใใใพใใ ใพใ job ๆฏใซ checkout ใๅฎ่กใใฆใใใฐไปๅใฎใใใซ checkout ใซๆ้ใใใใใฑใผในใงใฏ็ก้งใๅคงใใใชใใพใใ
#### shallow clone
ๅ
่ฟฐใฎ้ใ checkout ใซๆ้ใใใใฃใฆใใใฎใงๆนๅใใพใใใ ใพใ [shallow clone](https://github.blog/jp/2021-01-13-get-up-to-speed-with-partial-clone-and-shallow-clone/) ใใใซๅ
จๅฑฅๆญดใ checkout ใใฆใใ job ใใใฃใใฎใงใใชใ shallow clone ใใฆใใชใใฎใ่ชฟในใ็นใซ็็ฑใใชใใใฐ shallow clone ใใใใใใซใใๅฟ
่ฆใใใใฐใญใธใใฏใๆนไฟฎใใฆ shallow clone ใงใๅใใใใซใใพใใใ actions/checkout ใฏใใใฉใซใใง shallow clone ใชใฎใง็็ฑใใชใ shallow clone ใใใชใใฎใฏๅคใช่ฉฑใงใฏใใใพใใใ shallow clone ใง่ฏใใจใใใงใ shallow clone ใใชใใณใผใใใณใใใใใฆๆฅใฆใใพใฃใใจใใๆญดๅฒ็็ต็ทฏใง shallow clone ใงใใใใใซใชใฃใใฎใซ shallow clone ใใชใใพใพใซใชใฃใฆใใจใใใใจใ่ใใใใพใใ PR ใงๅคๆดใใใใณใผใใๆคๅบใใใฎใซ git ใณใใณใใไฝฟใฃใฆใใฆใใใใง git ใฎๅฑฅๆญดใๅฟ
่ฆใชใฎใง shallow clone ใ ใจๅใใชใใฑใผในใใใใพใใใใใใใฏ GitHub API ใง PR ใงๅคๆดใใใใใกใคใซใฎไธ่ฆงใๅๅพใใใใจใง่งฃๆฑบใใพใใใ
[REST API endpoints for pull requests - GitHub Docs](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files)
ใชใใ API ใ ใจ 3,000 ใใกใคใซใพใงใใๅๅพใงใใชใใจใใๅถ็ดใฏใใใพใใใใปใผๅ้กใซใชใใชใใจๆใใพใใ
#### ใชใใธใใชใซใณใใใใใใฆใใ zip ใใกใคใซใฎๅ้ค
shallow clone ใงใๆใฃใใปใฉ้ใใชใใชใใฃใใฎใไธๆ่ญฐใ ใฃใใฎใงใใใ็ตๆงใชๆฐใฎๅคงใใใฎ zip ใใกใคใซใใณใใใใใใฆใใใใจใๅคๆใใพใใใ ใใใใฏๅ
จใฆ Lambda Function ใฎใณใผใใงใใใ
ใพใๅคงใใช zip ใใกใคใซใฎใใใชใใคใใชใใกใคใซใ Git ใง็ฎก็ใใใฎใฏ้ฉๅใงใฏใใใพใใใ Git ใง็ฎก็ใใใจใใใ Git LFS ใฎใใใชใใฎใไฝฟใในใใงใใใใใ่ชๅใฎ็่งฃใๆญฃใใใใฐ Git LFS ใไฝฟใฃใฆใ shallow clone ใฏ้ใใชใใพใใใ
[About Git Large File Storage - GitHub Docs](https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-git-large-file-storage)
ๅ ใใฆไปๅใฎ zip ใใกใคใซใฏใณใผใใใ็ๆใใใ Lambda Function ใฎใณใผใใงใใใใใใๆๅ
ใง็ๆใใฆใณใใใใใใฎใฏ CI ใฎ้ซ้ๅใจใฏๅฅใซๅคงใใชๅ้กใใใใพใใ
1. ใณใผใใจ็ๆใใใ zip ใซๅทฎๅใใใๅฏ่ฝๆงใใใ(ใณใผใใๆดๆฐใใใใจใซใใฃใใ zip ใๆดๆฐใๅฟใใใจใ)
2. ๆชๆใฎใใใณใผใใไป่พผใพใใ Lambda ใงๅฎ่กใใใใ
3. zip ใฎไธญ่บซใ PR ใฌใใฅใผใใใฎใๅฐ้ฃ
ใใใงๆนๅๆกใไธปใซ 2 ใคใใใพใใ
1. zip ใ S3 ใซ็งปใ
2. [lambroll](https://github.com/fujiwara/lambroll) ใชใฉใไฝฟใฃใฆใใใญใคใใ
ไปๅๅ้กใซใชใฃใฆใใ Lambda Function ใฏ SRE team ใ็ฎก็ใใใใฎใงใฏใชใใฃใใฎใงใๅ
ทไฝ็ใซใฉใๅฏพๅฟใใใใฏใไปปใใใคใคใชใใธใใชใใ zip ใใกใคใซใๅ้คใใใใใซไพ้ ผใใฆๅใใพใใใ
#### sparse checkout
shallow clone ใงใๆใฃใใปใฉ้ใใชใใชใใฃใใฎใงใ [sparse checkout](https://git-scm.com/docs/git-sparse-checkout) ใใใใใจใซใใพใใใ sparse checkout ใฏ [actions/checkout](https://github.com/actions/checkout) ใฎ sparse-checkout input ใงๅฏพ่ฑกใฎใในใๆๅฎใใใ ใใงใใ ๅคงใใช Monporepo ใงใฏใชใใธใใชๅ
จไฝใ checkout ใใใจใ CI ใซๅฟ
่ฆใชในใฏใชใใใ่จญๅฎใใกใคใซใจๅฏพ่ฑกใฎใใฃใฌใฏใใชใ ใ checkout ใใใฐๅใๅ ดๅใใใใใใพใใ ใพใใไพใใฐ [actionlint](https://github.com/rhysd/actionlint) ใ [ghalint](https://github.com/suzuki-shunsuke/ghalint) ใง GitHub Actions Workflow ใฎ lint ใใใๅ ดๅ .github ้
ไธใ ใ checkout ใใใฐๅๅใ ใฃใใใใพใใ
ใใ ใใไพๅญใใ local Module ใชใฉใ checkout ใใฆใชใใจๅใใชใใชใฃใฆใใพใใฑใผในใใใใพใใใ ใใใงๅใซ terraform ใๅฎ่กใใใใฃใฌใฏใใชใ ใใงใชใใใฎใใฃใฌใฏใใชใไพๅญใใใใฃใฌใฏใใชใ checkout ใใชใใจใใใชใใฎใงใใใใใฎไพๅญ้ขไฟใใณใผใใ checkout ใใๅใซ่งฃๆฑบใใใฎใฏๅฐ้ฃใงใใใ ไปๅใฎๅ ดๅใใใฃใฌใฏใใช้ๅฑคใฎๆๅใฎใใฃใฌใฏใใชใใตใผใในๅใซใชใฃใฆใใใไปใฎใตใผใในใใฃใฌใฏใใช้
ไธใซใใ local Module ใๅ็
งใใฆใใใใใชใฑใผในใฏใชใใฃใใใใไปฅไธใฎใใฃใฌใฏใใชใใใงใใฏใขใฆใใใใใจใซใใพใใใ
- ใชใใธใใชๅ
จไฝใงๅ
ฑ้ใฎ local module ใ็ฝฎใใใฆใใใใฃใฌใฏใใช
- ๅคๆดใใใใใฃใฌใฏใใชใๅฑใใๆๅใฎใใฃใฌใฏใใช
- CI ใซๅฟ
่ฆใชในใฏใชใใใชใฉใใใใใฃใฌใฏใใช
sparse checkout ใซใใ checkout ใๆฐ็งใง็ตใใใใใซใชใใๅคงใใช้ซ้ๅใซ็นใใใพใใใ
#### ใใกใคใซใใใฃใฌใฏใใชใฎๅญๅจใใงใใฏใฎใใใ ใใซๆ
ใ
checkout ใใฆใใใฎใ GitHub Content API ใซ็ฝฎใๆใ
[REST API endpoints for repository contents - GitHub Docs](https://docs.github.com/en/rest/repos/contents)
GitHub CLI ใไฝฟใใฐ็ฐกๅใซใใกใคใซใปใใฃใฌใฏใใชใฎๅญๅจใใงใใฏใ่กใใพใใ
```
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/contents/PATH?ref=main
```
#### ็ก้งใชๅฆ็ใฎๅ้ค
็ก้งใซ actions/setup-node ใง Node.js ใใปใใใขใใใใฆใใใใใใฎใงๅ้คใใพใใใใใใ ใใง 10 ๆฐ็งใฎ็ญ็ธฎใซใชใใพใใใ ใใไปฅๅคใซใ่ฒใ
็ก้งใชๅฆ็ใใชใใใใใใพใใใ
#### terrform plan ใ no change ใฎใจใ infracost ใ skip
terraform plan ใฎ็ตๆใ [infracost](https://github.com/infracost/infracost) ใซๆธกใใฆ็ตๆใ PR ใซใณใกใณใใใฆใใพใใใใใใซ็ตๆงๆ้ใใใใฃใฆใใพใใ Infracost ใฏใชใฝใผในใฎๆไฝใซใใฃใฆใฉใฎ็จๅบฆ้้ญ็ใณในใใ็บ็ใชใใๅๆธใใใใใๅบๅใใฆใใใใใผใซใงใใ ใใใ terraform plan ใฎ็ตๆใซใใใใใๅฎ่กใใใฆใใพใใใใ terraform plan ใฎ็ตๆใ No Change ใงใใใฐๅฝ็ถใณในใใฎๅคๅใใชใใฏใใงใๆ้ใใใใฆ infracost ใๅฎ่กใใๆๅณใฏใใใพใใใ ใใใง terraform plan ใฎ็ตๆใ No change ใฎใจใใฏ infracost ใ skip ใใฆ้ซ้ๅใใพใใใ
## ๆๆ
ๆงใ
ใชๆนๅใ่กใฃใ็ตๆใ CI ใ 2 ๅไปฅไธ้ซ้ๅใใใใจใๅบๆฅใพใใใ ไปฅไธใฎๅณใฏ terraform plan ใๅฎ่กใใ workflow ใฎๅฎ่กๆ้ใๆฅใใจใซ 70 percentile ใงใใญใใใใใใฎใงใใ
![](https://cdn-ak.f.st-hatena.com/images/fotolife/s/seli07/20241016/20241016154328.png)
ๆ้ใซไผดใ CI ใฎๅฎ่กๆ้ใฎ้ท็งป
็ธฆ่ปธใๅฎ่กๆ้ใงๆจช่ปธใๆฅไปใงใใ ไผๆฅใฏ workflow ใๅฎ่กใใใฆใใชใใฎใงใใผใฟใๆฌ ่ฝใใฆใใพใใใๅ
จไฝใจใใฆๅณไธใใใใคใพใๅฎ่กๆ้ใ็ญ็ธฎใใใฆใใใฎใใใใใใจๆใใพใใ ใชใใ terraform plan ใฎๅฎ่กๆ้ใฏๅฝ็ถๅฏพ่ฑกใใฃใฌใฏใใชใง็ฎก็ใใใฆใใใชใฝใผในใซไพๅญใใใใใๅคใใฎใชใฝใผในใ็ฎก็ใใฆใใใใฃใฌใฏใใชใไฟฎๆญฃใใใใฐใใฎๅๅฎ่กๆ้ใฏไผธใณใพใใใใฎใใใใฐใฉใใใใ็จๅบฆไนฑ้ซไธใใใฎใฏไปๆนใใใใพใใใ
ๅๅใใใฏใCI ใ็้ใซใชใฃใฆๅฉใใฃใฆใใใใจใใธใใฃใใชใณใกใณใใๅคใใใใ ใพใใใ ๅ ใใฆ CIAnalyzer ใซใใฃใฆใใใทใฅใใผใใๆง็ฏใใ็ถ็ถ็ใซ CI ใฎๅฎ่กๆ้ใๅฏ่ฆๅใใใใจใๅบๆฅใพใใใ ไปๅใฏ Terraform Monorepo ใซ CIAnalyzer ใๅฐๅ
ฅใใพใใใใ้ๅธธใซไพฟๅฉใ ใฃใใใไปใฎใชใใธใใชใธใฎๅฑ้ใๆค่จใใฆใใพใใ
## ใใใใซ
ไปๅ CI ใฎ้ซ้ๅใซ้ข้ฃใใฆไธๅฎใฎๆๆใไธใใใใจใๅบๆฅใพใใใใ CI ใฎๆนๅใฎใใใซใใใใจใฏใพใ ใพใ ใใใพใใ ็พๅจ้ฒใใฆใใๆฝ็ญใใใใฎใงใใใใพใใใญใฐใชใฉใง็ดนไปใงใใใฐใจๆใใพใใ