์๊ฐ
์ด ๊ฐ์ด๋์์๋ Go ํจํค์ง๋ฅผ ๋น๋ํ๊ณ ํ ์คํธํ๊ณ ๊ฒ์ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
GitHub ํธ์คํธ ์คํ๊ธฐ์๋ Go์ ์ข ์์ฑ์ ํฌํจํ๋ ์ํํธ์จ์ด๊ฐ ์ฌ์ ์ค์น๋ ๋๊ตฌ ์บ์๊ฐ ์์ต๋๋ค. ์ต์ ์ํํธ์จ์ด ๋ฐ ์ฌ์ ์ค์น๋ Go ๋ฒ์ ์ ์ ์ฒด ๋ชฉ๋ก์ GitHub ํธ์คํ ์คํ๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
ํ์ ์กฐ๊ฑด
YAML ๊ตฌ๋ฌธ๊ณผ ์ด๋ฅผ GitHub Actions์ ํจ๊ป ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ ์๊ณ ์์ด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ GitHub Actions์ ๋ํ ์ํฌํ๋ก ๊ตฌ๋ฌธ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
Go ์ธ์ด๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ดํดํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์์ธํ ๋ด์ฉ์ Go ์์์ ์ฐธ์กฐํ์ธ์.
Go ์ํฌํ๋ก ํ ํ๋ฆฟ ์ฌ์ฉ
๋น ๋ฅด๊ฒ ์์ํ๋ ค๋ฉด ์ํฌํ๋ก ํ
ํ๋ฆฟ์ ๋ฆฌํฌ์งํ ๋ฆฌ์ .github/workflows
๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐํฉ๋๋ค.
GitHub๋ ๋๋ถ๋ถ์ Go ํ๋ก์ ํธ์์ ์๋ํ๋ Go ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ ๊ณตํฉ๋๋ค. ์ด ๊ฐ์ด๋์ ํ์ ์น์ ์์๋ ์ด ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ฌ์ฉ์ ์ง์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
-
GitHub์์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๊ธฐ๋ณธ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ ์ด๋ฆ ์๋์์ ์์ ์ ํด๋ฆญํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ์ ์ํฌํ๋ก๊ฐ ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ ์ ์ํฌํ๋ก๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
"์ํฌํ๋ก ์ ํ" ํ์ด์ง์๋ ๊ถ์ฅ๋๋ ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ ํ ํญ๋ชฉ์ด ํ์๋ฉ๋๋ค. "go"๋ฅผ ๊ฒ์ํฉ๋๋ค.
-
์ง์์ ํตํฉ์ ํด๋ฆญํ์ฌ ์ํฌํ๋ก ์ ํ์ ํํฐ๋งํฉ๋๋ค.
-
"Go - by GitHub Actions" ์ํฌํ๋ก์์ ๊ตฌ์ฑ์ ํด๋ฆญํฉ๋๋ค.
-
ํ์์ ๋ฐ๋ผ ์ํฌํ๋ก๋ฅผ ํธ์งํฉ๋๋ค. ์๋ฅผ ๋ค์ด Go ๋ฒ์ ์ ๋ณ๊ฒฝํฉ๋๋ค.
-
๋ณ๊ฒฝ ๋ด์ฉ ์ปค๋ฐ์ ํด๋ฆญํฉ๋๋ค.
go.yml
์ํฌํ๋ก ํ์ผ์ด ๋ฆฌํฌ์งํ ๋ฆฌ์ .github/workflows
๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐ๋ฉ๋๋ค.
Go ๋ฒ์ ์ง์
Go ๋ฒ์ ์ ์ง์ ํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ GitHub์์ ์ ๊ณตํ๋ setup-go
์์
์ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. ์์ธํ ๋ด์ฉ์ setup-go
์์
์ ์ฐธ์กฐํ์ธ์.
GitHub ํธ์คํ
์คํ๊ธฐ์์ ๋ฏธ๋ฆฌ ์ค์น๋ Go ๋ฒ์ ์ ์ฌ์ฉํ๋ ค๋ฉด ๊ด๋ จ ๋ฒ์ ์ ์์
์ ์์ฑ์ setup-go
์์
์ go-version
์์ฑ์ ์ ๋ฌํฉ๋๋ค. ์ด ์์
์ ๊ฐ ์คํ๊ธฐ์ ๋๊ตฌ ์บ์์์ ํน์ ๋ฒ์ ์ Go๋ฅผ ์ฐพ๊ณ ํ์ ์ด์ง ํ์ผ์ PATH
์ ์ถ๊ฐํฉ๋๋ค. ์ด๋ฌํ ๋ณ๊ฒฝ ๋ด์ฉ์ ์์
์ ๋๋จธ์ง ๋ถ๋ถ์ ๋ํด ์ ์ง๋ฉ๋๋ค.
setup-go
์์
์ ๋ค์ํ ์คํ๊ธฐ ๋ฐ ๋ค์ํ ๋ฒ์ ์ Go์์ ์ผ๊ด๋ ๋์์ ๋ณด์ฅํ๋ ๋ฐ ์ ์ฉํ๋ฏ๋ก GitHub Actions๋ก Go๋ฅผ ์ฌ์ฉํ๋ ๋ฐ ๊ถ์ฅ๋๋ ๋ฐฉ๋ฒ์
๋๋ค. ์์ฒด ํธ์คํธ ์คํ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ Go๋ฅผ ์ค์นํ๊ณ ์ด๋ฅผ PATH
์ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
์ฌ๋ฌ ๋ฒ์ ์ Go ์ฌ์ฉ
name: Go on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: go-version: [ '1.19', '1.20', '1.21.x' ] steps: - uses: actions/checkout@v4 - name: Setup Go ${{ matrix.go-version }} uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} # You can test your matrix by printing the current Go version - name: Display Go version run: go version
name: Go
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.19', '1.20', '1.21.x' ]
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
# You can test your matrix by printing the current Go version
- name: Display Go version
run: go version
ํน์ Go ๋ฒ์ ์ฌ์ฉ
1.20.8
๊ณผ ๊ฐ์ ํน์ ๋ฒ์ ์ Go๋ฅผ ์ฌ์ฉํ๋๋ก ์์
์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ๋๋ ์๋ฏธ ์ฒด๊ณ ๋ฒ์ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์ต์ ๋ถ ๋ฆด๋ฆฌ์ค๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. ์ด ์์์๋ Go 1.21์ ์ต์ ํจ์น ๋ฆด๋ฆฌ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค:
- name: Setup Go 1.21.x uses: actions/setup-go@v5 with: # Semantic version range syntax or exact version of Go go-version: '1.21.x'
- name: Setup Go 1.21.x
uses: actions/setup-go@v5
with:
# Semantic version range syntax or exact version of Go
go-version: '1.21.x'
์ข ์์ฑ ์ค์น
์ข
์์ฑ์ ์ค์นํ๋ ๋ฐ go get
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
steps: - uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.21.x' - name: Install dependencies run: | go get . go get example.com/octo-examplemodule go get example.com/octo-examplemodule@v1.3.4
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Install dependencies
run: |
go get .
go get example.com/octo-examplemodule
go get example.com/octo-examplemodule@v1.3.4
์ข ์์ฑ ์บ์ฑ
setup-go
์์
์ ์ฌ์ฉํ์ฌ ์ข
์์ฑ์ ์บ์ํ๊ณ ๋ณต์ํ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์บ์ฑ์ setup-go
์์
์ ์ฌ์ฉํ ๋ ํ์ฑํ๋ฉ๋๋ค.
setup-go
์์
์ ๋ฆฌํฌ์งํ ๋ฆฌ ๋ฃจํธ์์ ์ข
์์ฑ ํ์ผ go.sum
์ ๊ฒ์ํ๊ณ ์ข
์์ฑ ํ์ผ์ ํด์๋ฅผ ์บ์ ํค์ ์ผ๋ถ๋ก ์ฌ์ฉํฉ๋๋ค.
์ฌ๋ฌ ์ข
์์ฑ ํ์ผ์ด ์ฌ์ฉ๋๊ฑฐ๋ ์๋ก ๋ค๋ฅธ ํ์ ๋๋ ํฐ๋ฆฌ์ ์๋ ๊ฒฝ์ฐ cache-dependency-path
๋งค๊ฐ ๋ณ์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.17' cache-dependency-path: subdir/go.sum
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.17'
cache-dependency-path: subdir/go.sum
์ฌ์ฉ์ ์ง์ ์๊ตฌ์ฌํญ์ด ์๊ฑฐ๋ ์บ์ฑ์ ๋ํ ์ธ๋ถ์ ์ธ ์ ์ด๊ฐ ํ์ํ ๊ฒฝ์ฐ cache
์์
์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ข
์์ฑ ์บ์ฑ ์ฐธ์กฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
์ฝ๋ ๋น๋ ๋ฐ ํ ์คํธ
์ฝ๋๋ฅผ ๋น๋ํ๊ณ ํ
์คํธํ๊ธฐ ์ํด ๋ก์ปฌ์์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๋์ผํ ๋ช
๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด ์์ ์ํฌํ๋ก์์๋ ์์
์์ go build
๋ฐ go test
๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
name: Go on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.21.x' - name: Install dependencies run: go get . - name: Build run: go build -v ./... - name: Test with the Go CLI run: go test
name: Go
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test
์ํฌํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ํฐํฉํธ๋ก ํจํค์ง
์ํฌํ๋ก๊ฐ ์๋ฃ๋๋ฉด ๋ถ์์ ์ํด ๊ฒฐ๊ณผ ์ํฐํฉํธ ์
๋ก๋ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ก๊ทธ ํ์ผ, ์ฝ์ด ๋คํ, ํ
์คํธ ๊ฒฐ๊ณผ ๋๋ ์คํฌ๋ฆฐ์ท์ ์ ์ฅํด์ผ ํ ์ ์์ต๋๋ค. ๋ค์ ์์์์๋ upload-artifact
์์
์ ์ฌ์ฉํ์ฌ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ์
๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
์์ธํ ๋ด์ฉ์ ์ํฌํ๋ก ์ํฐํฉํธ์ ๋ฐ์ดํฐ ์ ์ฅ ๋ฐ ๊ณต์ ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
name: Upload Go test results on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: go-version: [ '1.19', '1.20', '1.21.x' ] steps: - uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - name: Install dependencies run: go get . - name: Test with Go run: go test -json > TestResults-${{ matrix.go-version }}.json - name: Upload Go test results uses: actions/upload-artifact@v4 with: name: Go-results-${{ matrix.go-version }} path: TestResults-${{ matrix.go-version }}.json
name: Upload Go test results
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.19', '1.20', '1.21.x' ]
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: go get .
- name: Test with Go
run: go test -json > TestResults-${{ matrix.go-version }}.json
- name: Upload Go test results
uses: actions/upload-artifact@v4
with:
name: Go-results-${{ matrix.go-version }}
path: TestResults-${{ matrix.go-version }}.json