Published on

๐ŸŽ Swift - MusicSpot CI ์ ์šฉ๊ธฐ

Authors
  • avatar
    Name
    ์ด์ฐฝ์ค€
    Twitter

๋ฐฐ๊ฒฝ

MusicSpot์€ ์—ฌ๋Ÿฌ ๋ชจ๋“ˆ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

์•ฑ ํ”„๋กœ์ ํŠธ ํ•˜๋‚˜๋งŒ ๋นŒ๋“œํ•˜๋ฉด ๋๋˜ ์ด์ „์— ๊ฒฝํ—˜ํ–ˆ๋˜ CI์™€๋Š” ๋‹ค๋ฅด๊ฒŒ ๊ฐ ๋ชจ๋“ˆ์„ ์ฐพ์•„๋‚ด์„œ ๊ฐ๊ฐ ๋นŒ๋“œํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™์€๋ฐ..

์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ์š”?

๊ณผ์ •

MusicSpot์€ ๋ชจ๋“ˆ๋Ÿฌ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜์˜ ์•ฑ ํƒ€๊ฒŸ์— ๋ชจ๋“  ์†Œ์Šค๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ฐ ํŒจํ‚ค์ง€๊ฐ€ ๊ฐ๊ฐ์˜ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ดํ›„์— ํ•˜๋‚˜์˜ ์•ฑ ํƒ€๊ฒŸ์—์„œ ๋ชจ๋“  ํŒจํ‚ค์ง€๋ฅผ Dependency๋กœ ๊ฐ–๊ฒŒ๋˜๋ฉด, ์•ฑ ํƒ€๊ฒŸ ํ•˜๋‚˜๋งŒ ๋นŒ๋“œํ•ด์ค˜๋„ ํ…Œ์ŠคํŠธ๊ฐ€ ๋ ํ…Œ์ง€๋งŒ,

๊ทธ ์ „์—๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ์š”?

๊ฐ ๋ชจ๋“ˆ์„ ์ฐพ์•„๋‚ด์„œ ๋นŒ๋“œํ•˜๋Š” ์—ฌ์ •... ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค..

์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ๋“ค์„ ์ฐพ์•„๋‚ด๊ธฐ

๊ฐ ๋ชจ๋“ˆ๋“ค์„ ๋นŒ๋“œํ•˜๋ ค๋ฉด, ์šฐ์„  ์–ด๋–ค ๋ชจ๋“ˆ๋“ค์ด ์žˆ๋Š”์ง€๋ถ€ํ„ฐ ํ™•์ธํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

xcodebuild๊ฐ€ ๋‹คํ–‰ํžˆ list๋ฅผ ๋ฝ‘์•„๋‚ด๋Š” ๋ช…๋ น์–ด๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

xcodebuild -workspace MusicSpot.xcworkspace -list

MusicSpot ์›Œํฌ์ŠคํŽ˜์ด์Šค์— ๋ชจ๋“  ํŒจํ‚ค์ง€๋“ค์„ ์ถ”๊ฐ€ํ•ด์คŒ์œผ๋กœ์จ ๊ด€๋ฆฌํ•˜๋Š” ํŒจํ‚ค์ง€๋“ค์„ ์ฐพ์•„๋‚ผ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ๊ฒฐ๊ณผ๊ฐ€ ๊ต‰์žฅํžˆ ๊ธฐ๋„ค์š”..!?

์ €ํฌ๊ฐ€ ์›ํ•˜๋Š” ๊ฑด ๊ฐ€์žฅ ๋ฐ‘์— ์žˆ๋Š” Schemes์— ๋Œ€ํ•œ ์ •๋ณด์ž…๋‹ˆ๋‹ค.

for scheme in $(xcodebuild -workspace ${{ env.WORKSPACE }} -list | grep -A 100 "Schemes:" | grep -v "Schemes:" | sed '/^$/d' | sed 's/^[ \t]*//')
  1. grep -A 100 "Schemes:" - Schemes:`๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์ฐพ์•„์„œ ํ•ด๋‹น ๋‹จ์–ด๋ถ€ํ„ฐ 100๊ฐœ์˜ ์ค„์„ ๋”ฐ์˜ต๋‹ˆ๋‹ค.
  2. grep -v "Schemes:" - ๊ทธํ›„ ๋ฐ˜๋Œ€๋กœ Schemes:๋ผ๋Š” ๋‹จ์–ด๋ฅผ ๊ฐ€์ง€์ง€ ์•Š์€ ๋ฌธ์žฅ๋“ค์„ ๋”ฐ์˜ต๋‹ˆ๋‹ค.

์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๋ฉด ๋ชฉ๋ก๋“ค์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ ํƒญ๊ณผ ๊ฐ€๋” ์ƒ๊ธฐ๋Š” Next-Line๋“ค์„ ์ œ๊ฑฐํ•ด์ค˜์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— 3. sed '/^$/d'์™€ sed 's/^[ \t]*//'๋กœ ๊ณต๋ž€๋“ค์„ ์ œ๊ฑฐํ•ด์ค๋‹ˆ๋‹ค.

matrix

์ด๋ ‡๊ฒŒ ์ถ”์ถœํ•œ Scheme๋“ค.. ์ˆœ์ฐจ์ ์œผ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜ ๋นŒ๋“œํ•˜๋ฉด ํ•œ์„ธ์›”์ด๊ฒ ์ฃ ?

๊ทธ๋ž˜์„œ ์ด๊ฑธ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—†๋‚˜ ์ฐพ์•„๋ณด๋˜ ์™€์ค‘

GitHub Action์— matrix๋ผ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.

jobs:
  example_matrix:
    strategy:
      matrix:
        version: [10, 12, 14]
        os: [ubuntu-latest, windows-latest]

์ด๋Ÿฐ ์‹์œผ๋กœ matrix๋ฅผ ์ •์˜ํ•ด์ฃผ๋ฉด, ์ฃผ์–ด์ง„ ๊ฐ ๊ฐ’๋“ค์„ ํ•œ ๋ฒˆ์”ฉ ๋งค์นญ์‹œ์ผœ์„œ ๊ฐ™์€ ๋™์ž‘์„ ์ˆ˜ํ–‰์‹œ์ผœ์ค๋‹ˆ๋‹ค.

- `{version: 10, os: ubuntu-latest}`
- `{version: 10, os: windows-latest}`
- `{version: 12, os: ubuntu-latest}`
- `{version: 12, os: windows-latest}`
- `{version: 14, os: ubuntu-latest}`
- `{version: 14, os: windows-latest}`

์ด๋ ‡๊ฒŒ version 3๊ฐœ, os 2๊ฐœ์˜ ์กฐํ•ฉ์œผ๋กœ 6๊ฐœ์˜ ์ผ€์ด์Šค๊ฐ€ ์ƒ๊ธฐ๊ฒ ๋„ค์š”.

๊ทธ๋Ÿฐ๋ฐ ์ €ํฌ๋Š” ์ด๋ ‡๊ฒŒ ์กฐํ•ฉ์„ ์‚ฌ์šฉํ•  ๊ฑด ์•„๋‹ˆ๊ณ , ์ด ์กฐํ•ฉ์„ ํ•œ ๋ฒˆ์— ๋Œ๋ฆฐ๋‹ค๋Š” ์ ์„ ํ™œ์šฉํ• ๊ฒ๋‹ˆ๋‹ค.

matrix="{\"include\":["
for scheme in Schemes ...
	if [ "$first_entry" = true ]; then
	  first_entry=false
	else
	  matrix+=","
	fi
	matrix+="{\"scheme\":\"$scheme\"}"
done
matrix+="]}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT

matrix๋Š” key-value์˜ ํ˜•์‹์„ ๋”ฐ๋ผ์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—

{
	"include": [
		{
			"scheme": "MusicSpot"
		},
		{
			"scheme": "MusicSpot-Release"
		},
		...
	]
}

์ด๋ ‡๊ฒŒ "scheme"์„ key ๊ฐ’์œผ๋กœ ๊ฐ–๋Š” Scheme Value๋“ค์„ ๋งŒ๋“ค์–ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ์ถ”๊ฐ€ํ•œ matrix๋Š” ์ดํ›„ ๋นŒ๋“œ action ์ชฝ์—์„œ

xcode-build:
needs: prepare-matrix
runs-on: macos-13
strategy:
  fail-fast: false
  matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} // โœ…

์ด๋ ‡๊ฒŒ JSON ํŒŒ์‹ฑ์„ ํ†ตํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ

์ด๋ ‡๊ฒŒ ์ €ํฌ ์ถ”๊ฐ€ํ•œ Scheme๋“ค์ด ๋ณ‘๋ ฌ์ ์œผ๋กœ ํ•œ ๋ฒˆ์— ๋Œ์•„๊ฐ€๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

์กฐ๊ธˆ ๊ฑธ๋ฆฌ๋Š” ์ ๋“ค์ด ๋‚จ์•„์žˆ๊ธด ํ•ฉ๋‹ˆ๋‹ค.

  1. ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ๊ณผ ์ƒ๊ด€์—†์ด ๋ชจ๋“  Scheme๋“ค์˜ ๊ฒ€์‚ฌ๊ฐ€ ์ด๋ฃจ์–ด์ง€๊ณ  ์žˆ๋‹ค๋Š” ์ 
  2. ์ดํ›„ ์•ฑ ํƒ€๊ฒŸ์— ๋ชจ๋“  Dependency๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด, ๊ทธ ์ดํ›„์—๋„ ์ด๋ ‡๊ฒŒ ๋ชจ๋“  Scheme์„ ๊ฒ€์‚ฌํ•  ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ ํ•˜๋Š” ์˜๋ฌธ

์•„๋งˆ ํ”„๋กœ์ ํŠธ ๊ธฐ๊ฐ„๋™์•ˆ์€ ์ด๋Œ€๋กœ ๊ณ„์† ์‚ฌ์šฉํ•˜๊ณ ,

์ดํ›„์— ์ถ”๊ฐ€์ ์œผ๋กœ ์ง„ํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ๊ณ ๋ฏผํ•ด๋ณด๊ณ  ์ˆ˜์ •ํ•  ๊ฒƒ ๊ฐ™๋„ค์š”.

์ฐธ๊ณ  ๋ฌธ์„œ