-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
actions workflow 새 organization에 맞게 migrate한다 #16
Conversation
- PR 기반으로하면 fork받은 리포지토리에서 PR시 secrets 토큰 못가져옴 - ${GITHUB_ACTOR} 리포지토리 user 가져와서 commit_message url에 추가
- npm ci를 yarn install --prefer-offline --frozen-lockfile로 변경 - 불필요한 부분 삭제
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간략하게 무엇이 바뀌었는지 적어두었습니다.
push: | ||
branches: [ master ] | ||
pull_request: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
push할 경우에만 실행하도록 변경하였습니다.
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actions 작업시간 단축을 위해 node_modules를 캐싱하기 위한 부분입니다.
npm 기준으로 되어있던 것을 yarn 기준으로 변경하였습니다.
https://whitekiwi.medium.com/github-actions-cache-node-modules-99935de9e8fa
- run: npm ci | ||
- run: npm run build-storybook | ||
- name: Install dependencies | ||
run: yarn install --prefer-offline --frozen-lockfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm ci 를 대체하기 위해 yarn install --prefer-offline --frozen-lockfile
옵션을 사용하였습니다.
--prefer-offline은 cache된 것에 우선순위를 주는 옵션이며, --frozen-lockfile은 CI 서버와 같이 재사용 가능한 의존 패키지가 필요한 경우에 적용하는 옵셥입니다.
uses: peaceiris/actions-gh-pages@v3 | ||
if: env.BRANCH_NAME != 'master' | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
직접 발급한 github token을 secrets에 넣어서 사용하는게 아닌 github에서 제공하는 GITHUB_TOKEN을 사용하였습니다.
commit_message: https://Yapp-17th.github.io/Web_2_Client/${{ env.BRANCH_NAME }} | ||
|
||
commit_message: https://${{ env.USER_NAME }}.github.io/witherview_frontend/${{ env.BRANCH_NAME }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하나의 origin에서 브랜치간 PR하는 절차에서 포크받아 각자의 origin에서 작업 후 upstream에 PR하는 경우로 바뀌어서 수정한 부분입니다.
앞서 언급했듯이 포크받은 브랜치에서 upstream으로 PR 하여 upstream에서 actions가 실행되는 경우 secrets를 가져오지 못합니다. 이를 위해 push될 때 마다 origin에서 actions가 실행하도록 수정하였는데 이 경우 origin마다 url이 달라지므로 이를 고려하여 반영하였습니다.
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 👍
Detail & Solution
지금까지 Storybook 배포는 PR 혹은 master로 머지되는 경우 GitHub Actions를 통해 빌드하여 GitHub Pages로 배포되도록 파이프라인을 구축하였습니다. - 배포 현황
배포는 브랜치별로 되도록 빌드된 파일을 브랜치명 폴더에 담도록 처리한 상황이었으며 컴포넌트 등을 새로 만든 경우 해당 브랜치의 URL을 공유하면 바로 확인할 수 있도록 하고자 하는 의도였습니다.
ex) master 브랜치 스토리북 / feat/#73 브랜치 스토리북
기존 프로젝트 진행은 fork 절차 없이 브랜치로 나눠서 브랜치간의 PR로 작업이 되어 GitHub secrets나 GITHUB_TOKEN의 권한에 대해 생각하지 않아도 되었습니다.
프로젝트 진행에 fork 절차를 추가한 결과 권환 문제가 생겨 이를 해결하고자 했습니다.
포크받은 origin 리포지토리에서 upstream으로 PR시 GitHub Actions에서 Secrets에 정의해놓은 토큰이 사용 가능한지 + GITHUB_TOKEN 사용이 가능한지 실험해보았습니다.
결론적으로 위와 같은 상황에서 upstream의 Secrets Token 사용 혹은 기본으로 제공해주는 GITHUB_TOKEN 사용이 불가능합니다.
https://gh.neting.ccmunity/t/make-fork-secrets-available-to-fork-prs/17762 *
https://gh.neting.ccmunity/t/make-secrets-available-to-builds-of-forks/16166/25
codecov/codecov-action#29
What I did
GitHua App으로 생성한 토큰을 Secret에 정의했지만 실패했습니다.
Organization 토큰을 설정 (실패)
자체적으로 제공하는 GITHUB_TOKEN을 사용 (실패)
fork 받은 브랜치에서는 READ only permission이기 때문에 GitHub Actions을 통한 push 이벤트시 403 에러가 발생합니다.
Organization settings에 옵션을 킴 (실패)
fork 받은 branch에서 upstream으로 향하는게 아닌 자기 자신으로 향하는 PR에 Secrets를 전달하는 옵션이었습니다.
push 기반으로하면 upstream이 아닌 fork 받은 리포지토리 자체적으로 workflow가 실행됩니다. 따라서 기존에 발생했던 이슈를 해결할 수 있습니다. 다만, storybook URL은 PR이 merge되는게 아닌이상 fork된 repository에 따라 바뀌게 됩니다. 해당 URL은 gh-pages branch의 커밋메시지에서 확인 가능합니다.
What I need to do