다음은 .travis.yml 예시예요 (elm 트랙에서 가져왔어요):
sudo: false
language: node_js
node_js:
- lts/*
script:
- bin/fetch-configlet
- bin/configlet lint
- bin/build.sh
이걸 GitHub Actions로 빠르게 바꾸려면 다음 단계를 따라 해요:
| 변수 | 값 |
|---|---|
<track> |
elm |
<image-name> |
ubuntu-latest |
<action to setup tooling> |
actions/setup-node@v1 |
<install dependencies> |
npm ci (build.sh 안에서 실행돼요) |
<code-extensions> |
.elm |
이 검색으로 setup 액션을 찾았어요. Travis의 기본 배포판을 보고 이미지 이름을 찾았어요.
bin/fetch-configlet: configlet.yml 워크플로를 쓰면 더 이상 필요 없어요bin/configlet lint: configlet.yml 워크플로를 쓰면 더 이상 필요 없어요bin/build.sh: 모든 걸 처리하는 단일 스크립트예요이 트랙은 bin 폴더를 사용하니, bin 폴더 안에 다음 파일을 만들어요:
# bin/pr
bin/build.sh
# bin/pr-check
echo "No checks yet"
# bin/ci
bin/build.sh
# bin/ci-check
echo "No checks yet"
이것들을 별도 바이너리로 만들어 두면 나중에 최적화할 수 있어요. 지금 당장 뭔가를 인라인으로 넣을 필요는 없어요.
다음은 workflows/ci.yml의 diff예요.
# # .github/workflows/ci.yml
# This workflow will do a clean install of node dependencies and run tests across different versions
#
- # Replace <track> with the track name
- # Replace <image-name> with an image to run the jobs on
- # Replace <action to setup tooling> with a github action to setup tooling on the image
- # Replace <install dependencies> with a cli command to install the dependencies
- # Replace <code-extensions> with file extensions that should trigger the workflow
- #
- # Find Github Actions to setup tooling here:
- # - https://github.com/actions/?q=setup&type=&language=
- # - https://github.com/actions/starter-workflows/tree/main/ci
- # - https://github.com/marketplace?type=actions&query=setup
- #
# Requires scripts:
- # - scripts/ci-check
- # - scripts/ci
+ # - bin/ci-check
+ # - bin/ci
- name: <track> / main
+ name: elm / main
on:
push:
branches: [main]
workflow_dispatch:
jobs:
precheck:
- runs-on: <image-name>
+ runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- - name: Use <setup tooling>
- uses: <action to setup tooling>
+ - name: Use Node LTS
+ uses: actions/setup-node@v1
with:
- # here, use the LTS/stable version of the track's tooling
- # node-version: 12.x
+ node-version: 12.x
- name: Install project dependencies
- run: <install dependencies>
+ run: npm ci
- - name: Run exercism/<track> ci pre-check (checks config, lint code) for all exercises
- run: scripts/ci-check
+ - name: Run exercism/elm ci pre-check (checks config, lint code) for all exercises
+ run: bin/ci-check
ci:
- runs-on: <image-name>
+ runs-on: ubuntu-latest
strategy:
matrix:
- # here, add all SUPPORTED versions only
- # version: [10.x, 12.x, 14.x]
+ version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- - name: Use <setup tooling> ${{ matrix.version }}
- uses: <action to setup tooling>
+ - name: Use Node ${{ matrix.version }}
+ uses: actions/setup-node@v1
with:
- # below: see how to inject the version
- # node-version: ${{ matrix.version }}
+ node-version: ${{ matrix.version }}
- name: Install project dependencies
- run: <install dependencies>
+ run: npm ci
- - name: Run exercism/<track> ci (runs tests) for all exercises
- run: scripts/ci
+ - name: Run exercism/elm ci (runs tests) for all exercises
+ run: bin/ci
workflows/pr.yml도 같은 변경 사항이 있어요. 다만 변경된 각 파일을 인자로 받아 pr-check와 pr 스크립트를 호출하는 bash-fu 부분은 예외예요:
# # .github/workflows/pr.yml
# # ...
- - name: Run exercism/<track> ci pre-check (stub files, config integrity) for changed exercises
+ - name: Run exercism/elm ci pre-check (stub files, config integrity) for changed exercises
run: |
PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
curl --url $"${PULL_REQUEST_URL}/files" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
- jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(<code-extensions>|md|json)$")) | .filename' | \
+ jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(elm|md|json)$")) | .filename' | \
- xargs -r scripts/pr-check
+ xargs -r bin/pr-check
# ...
이 정도면 GitHub Actions로 전환하기에 충분하고, 스크립트를 최적화할 여지도 남아 있어요.
build.sh에서 한 번만 실행해야 하는 단계를 빼내서 ci-check.sh와 pre-check.sh 파일로 옮겨요 (힌트: lint.sh를 만들어 두고 두 "scripts"에서 호출해도 돼요)pr.sh와 pr-check.sh에, 입력 인자를 사용해 어떤 파일이나 연습 문제를 검사할지 결정하는 최적화를 추가해요.