์๊ฐ
์ด ๊ฐ์ด๋์์๋ Rust ํจํค์ง๋ฅผ ๋น๋ํ๊ณ ํ ์คํธํ๊ณ ๊ฒ์ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
GitHub ํธ์คํ ์คํ๊ธฐ์๋ Rust์ ์ข ์์ฑ์ ํฌํจํ๋ ์ํํธ์จ์ด๊ฐ ์ฌ์ ์ค์น๋ ๋๊ตฌ ์บ์๊ฐ ์์ต๋๋ค. ์ต์ ์ํํธ์จ์ด ๋ฐ ์ฌ์ ์ค์น๋ Rust ๋ฒ์ ์ ์ ์ฒด ๋ชฉ๋ก์ GitHub ํธ์คํ ์คํ๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
ํ์ ์กฐ๊ฑด
YAML ๊ตฌ๋ฌธ๊ณผ ์ด๋ฅผ GitHub Actions์ ํจ๊ป ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ ์๊ณ ์์ด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ GitHub Actions์ ๋ํ ์ํฌํ๋ก ๊ตฌ๋ฌธ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
Rust ์ธ์ด๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ดํดํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์์ธํ ๋ด์ฉ์ Rust ์์ํ๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
Rust ์ํฌํ๋ก ํ ํ๋ฆฟ ์ฌ์ฉ
๋น ๋ฅด๊ฒ ์์ํ๋ ค๋ฉด ์ํฌํ๋ก ํ
ํ๋ฆฟ์ ๋ฆฌํฌ์งํ ๋ฆฌ์ .github/workflows
๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐํฉ๋๋ค.
GitHub์ ๋๋ถ๋ถ์ Rust ํ๋ก์ ํธ์์ ์๋ํ๋ Rust ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ ๊ณตํฉ๋๋ค. ์ด ๊ฐ์ด๋์ ํ์ ์น์ ์์๋ ์ด ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ฌ์ฉ์ ์ง์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
-
GitHub์์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๊ธฐ๋ณธ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ ์ด๋ฆ ์๋์์ ์์ ์ ํด๋ฆญํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ์ ์ํฌํ๋ก๊ฐ ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ ์ ์ํฌํ๋ก๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
"์ํฌํ๋ก ์ ํ" ํ์ด์ง์๋ ๊ถ์ฅ๋๋ ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ ํ ํญ๋ชฉ์ด ํ์๋ฉ๋๋ค. โRustโ๋ฅผ ๊ฒ์ํฉ๋๋ค.
-
์ง์์ ํตํฉ์ ํด๋ฆญํ์ฌ ์ํฌํ๋ก ์ ํ์ ํํฐ๋งํฉ๋๋ค.
-
โRust - GitHub Actions ๊ธฐ์คโ ์ํฌํ๋ก์์ ๊ตฌ์ฑ์ ํด๋ฆญํฉ๋๋ค.
-
ํ์์ ๋ฐ๋ผ ์ํฌํ๋ก๋ฅผ ํธ์งํฉ๋๋ค. ์๋ฅผ ๋ค์ด Rust ๋ฒ์ ์ ๋ณ๊ฒฝํฉ๋๋ค.
-
๋ณ๊ฒฝ ๋ด์ฉ ์ปค๋ฐ์ ํด๋ฆญํฉ๋๋ค.
rust.yml
์ํฌํ๋ก ํ์ผ์ด ๋ฆฌํฌ์งํ ๋ฆฌ์ .github/workflows
๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐ๋ฉ๋๋ค.
Rust ๋ฒ์ ์ง์
GitHub ํธ์คํ ์คํ๊ธฐ๋ ์ต์ ๋ฒ์ ์ Rust ๋๊ตฌ ์ฒด์ธ์ ํฌํจํฉ๋๋ค. rustup์ ์ฌ์ฉํ์ฌ ์คํ๊ธฐ์์ ์ค์น๋ ๋ฒ์ ์ ๋ณด๊ณ ํ๊ณ ๋ฒ์ ์ ์ฌ์ ์ํ๊ณ ๋ค๋ฅธ ๋๊ตฌ ์ฒด์ธ์ ์ค์นํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ rustup ์ฑ ์ ์ฐธ์กฐํ์ธ์.
์ด ์์ ์์๋ ์คํ๊ธฐ ํ๊ฒฝ์ ์ค์ ํ์ฌ rust์ ์ผ๊ฐ ๋น๋๋ฅผ ์ฌ์ฉํ๊ณ ๋ฒ์ ์ ๋ณด๊ณ ํ๊ธฐ ์ํด ์ฌ์ฉํ ์ ์๋ ๋จ๊ณ๋ฅผ ๋ณด์ฌ ์ค๋๋ค.
- name: Temporarily modify the rust toolchain version run: rustup override set nightly - name: Output rust version for educational purposes run: rustup --version
- name: Temporarily modify the rust toolchain version
run: rustup override set nightly
- name: Output rust version for educational purposes
run: rustup --version
์ข ์์ฑ ์บ์ฑ
์บ์ ์์
์ ์ฌ์ฉํ์ฌ ์ข
์์ฑ์ ์บ์ํ๊ณ ๋ณต์ํ ์ ์์ต๋๋ค. ์ด ์์ ์์๋ ๋ฆฌํฌ์งํ ๋ฆฌ์ Cargo.lock
ํ์ผ์ด ํฌํจ๋์ด ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
- name: Cache uses: actions/cache@v4 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
์ฌ์ฉ์ ์ง์ ์๊ตฌ ์ฌํญ์ด ์๊ฑฐ๋ ์บ์ฑ์ ๋ํ ๋ ์ธ๋ถ์ ์ธ ์ ์ด๊ฐ ํ์ํ ๊ฒฝ์ฐ cache
์์
์ ๋ํ ๋ค๋ฅธ ๊ตฌ์ฑ ์ต์
์ ํ์ํด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์ข
์์ฑ ์บ์ฑ ์ฐธ์กฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
์ฝ๋ ๋น๋ ๋ฐ ํ ์คํธ
์ฝ๋๋ฅผ ๋น๋ํ๊ณ ํ
์คํธํ๊ธฐ ์ํด ๋ก์ปฌ์์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๋์ผํ ๋ช
๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด ์์ ์ํฌํ๋ก์์๋ ์์
์์ cargo build
๋ฐ cargo test
๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
jobs: build: runs-on: ubuntu-latest strategy: matrix: BUILD_TARGET: [release] # refers to a cargo profile outputs: release_built: ${{ steps.set-output.outputs.release_built }} steps: - uses: actions/checkout@v4 - name: Build binaries in "${{ matrix.BUILD_TARGET }}" mode run: cargo build --profile ${{ matrix.BUILD_TARGET }} - name: Run tests in "${{ matrix.BUILD_TARGET }}" mode run: cargo test --profile ${{ matrix.BUILD_TARGET }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
BUILD_TARGET: [release] # refers to a cargo profile
outputs:
release_built: ${{ steps.set-output.outputs.release_built }}
steps:
- uses: actions/checkout@v4
- name: Build binaries in "${{ matrix.BUILD_TARGET }}" mode
run: cargo build --profile ${{ matrix.BUILD_TARGET }}
- name: Run tests in "${{ matrix.BUILD_TARGET }}" mode
run: cargo test --profile ${{ matrix.BUILD_TARGET }}
์ด ์์ ์์ ์ฌ์ฉ๋๋ release
ํค์๋๋ cargo ํ๋กํ์ ํด๋นํฉ๋๋ค. Cargo.toml
ํ์ผ์์ ์ ์ํ ๋ชจ๋ ํ๋กํ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
ํจํค์ง ๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ crates.io์ ๊ฒ์
์ํฌํ๋ก๋ฅผ ์ค์ ํ์ฌ ์ฝ๋๋ฅผ ๋น๋ํ๊ณ ํ ์คํธํ ํ์๋ ๋น๋ฐ์ ์ฌ์ฉํ์ฌ ๋ก๊ทธ์ธํ์ฌ ํจํค์ง๋ฅผ crates.io์ ๊ฒ์ํ ์ ์์ต๋๋ค.
- name: Login into crates.io run: cargo login ${{ secrets.CRATES_IO }} - name: Build binaries in "release" mode run: cargo build -r - name: "Package for crates.io" run: cargo package # publishes a package as a tarball - name: "Publish to crates.io" run: cargo publish # publishes your crate as a library that can be added as a dependency
- name: Login into crates.io
run: cargo login ${{ secrets.CRATES_IO }}
- name: Build binaries in "release" mode
run: cargo build -r
- name: "Package for crates.io"
run: cargo package # publishes a package as a tarball
- name: "Publish to crates.io"
run: cargo publish # publishes your crate as a library that can be added as a dependency
ํฌ๋ ์ดํธ๋ฅผ ๋น๋ํ๊ณ ํจํค์งํ๋ ๋ฐ ์ค๋ฅ๊ฐ ์๋ ๊ฒฝ์ฐ ๋งค๋ํ์คํธ, Cargo.toml
ํ์ผ์์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ํ์ธํฉ๋๋ค. ๋งค๋ํ์คํธ ํ์์ ์ฐธ์กฐํ์ธ์. ๋ํ Cargo.lock
ํ์ผ์ ํ์ธํด์ผ ํฉ๋๋ค. Cargo.toml ๋ฐ Cargo.lock ์ ์ฐธ์กฐํ์ธ์.
์ํฌํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ํฐํฉํธ๋ก ํจํค์ง
์ํฌํ๋ก๊ฐ ์๋ฃ๋๋ฉด ๋ถ์์ ์ํด ๊ฒฐ๊ณผ ์ํฐํฉํธ๋ฅผ ์ ๋ก๋ํ๊ฑฐ๋ ๋ค๋ฅธ ์ํฌํ๋ก์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ํฌํ๋ก์ ์ด๋ฌํ ์์ ๋จ๊ณ๋ฅผ ์ถ๊ฐํ์ฌ ๋ค๋ฅธ ์ํฌํ๋ก์์ ์ฌ์ฉํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ๋ก๋ํ ์ ์์ต๋๋ค.
- name: Upload release artifact uses: actions/upload-artifact@v4 with: name: <my-app> path: target/${{ matrix.BUILD_TARGET }}/<my-app>
- name: Upload release artifact
uses: actions/upload-artifact@v4
with:
name: <my-app>
path: target/${{ matrix.BUILD_TARGET }}/<my-app>
์ ๋ก๋๋ ์ํฐํฉํธ๋ฅผ ๋ค๋ฅธ ์์ ์์ ์ฌ์ฉํ๋ ค๋ฉด ์ํฌํ๋ก์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ํ ์ฌ๋ฐ๋ฅธ ๊ถํ์ด ์๋์ง ํ์ธํฉ๋๋ค. ์ํฌํ๋ก์์ ์ธ์ฆ์ GITHUB_TOKEN ์ฌ์ฉ์(๋ฅผ) ์ฐธ์กฐํ์ธ์. ๋ค์ ์์ ๋จ๊ณ๋ฅผ ์ฌ์ฉํ์ฌ ์ด์ ์ํฌํ๋ก์์ ๋ง๋ ์ฑ์ ๋ค์ด๋ก๋ํ๊ณ GitHub์ ๊ฒ์ํ ์ ์์ต๋๋ค.
- uses: actions/checkout@v4 - name: Download release artifact uses: actions/download-artifact@v4 with: name: <my-app> path: ./<my-app> - name: Publish built binary to GitHub releases - run: | gh release create --generate-notes ./<my-app>/<my-project>#<my-app>
- uses: actions/checkout@v4
- name: Download release artifact
uses: actions/download-artifact@v4
with:
name: <my-app>
path: ./<my-app>
- name: Publish built binary to GitHub releases
- run: |
gh release create --generate-notes ./<my-app>/<my-project>#<my-app>