Skip to content
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

Merged
merged 2 commits into from
Apr 13, 2021
Merged

actions workflow 새 organization에 맞게 migrate한다 #16

merged 2 commits into from
Apr 13, 2021

Conversation

dididy
Copy link
Member

@dididy dididy commented Mar 16, 2021

resolve #15

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

  1. Personal Access Token으로 정의했던 것을 GitHub App으로 토큰으로 변경 (실패)
    GitHua App으로 생성한 토큰을 Secret에 정의했지만 실패했습니다.

Screen Shot 2021-03-17 at 12 01 24 AM

  1. Organization 토큰을 설정 (실패)

  2. 자체적으로 제공하는 GITHUB_TOKEN을 사용 (실패)
    fork 받은 브랜치에서는 READ only permission이기 때문에 GitHub Actions을 통한 push 이벤트시 403 에러가 발생합니다.

  3. Organization settings에 옵션을 킴 (실패)
    fork 받은 branch에서 upstream으로 향하는게 아닌 자기 자신으로 향하는 PR에 Secrets를 전달하는 옵션이었습니다.

Screen Shot 2021-03-18 at 7 54 07 PM

  1. PR 및 master merge 기준으로 trigger 되던 workflow를 모든 push기반으로 trigger되도록 처리 (타협)
    push 기반으로하면 upstream이 아닌 fork 받은 리포지토리 자체적으로 workflow가 실행됩니다. 따라서 기존에 발생했던 이슈를 해결할 수 있습니다. 다만, storybook URL은 PR이 merge되는게 아닌이상 fork된 repository에 따라 바뀌게 됩니다. 해당 URL은 gh-pages branch의 커밋메시지에서 확인 가능합니다.

https://<fork 받은 user>.github.io/witherview_frontend/<push 한 branch>

What I need to do

@dididy dididy added the 🛠 fix This doesn't seem right label Mar 16, 2021
@dididy dididy self-assigned this Mar 16, 2021
@dididy dididy changed the title [develop] actions workflow 새 organization에 맞게 migrate [develop] actions workflow 새 organization에 맞게 migrate하라 Mar 17, 2021
@dididy dididy changed the title [develop] actions workflow 새 organization에 맞게 migrate하라 [develop] actions workflow 새 organization에 맞게 migrate한다 Mar 18, 2021
- PR 기반으로하면 fork받은 리포지토리에서 PR시 secrets 토큰 못가져옴
- ${GITHUB_ACTOR} 리포지토리 user 가져와서 commit_message url에 추가
@dididy dididy changed the title [develop] actions workflow 새 organization에 맞게 migrate한다 actions workflow 새 organization에 맞게 migrate한다 Apr 4, 2021
- npm ci를 yarn install --prefer-offline --frozen-lockfile로 변경
- 불필요한 부분 삭제
Copy link
Member Author

@dididy dididy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간략하게 무엇이 바뀌었는지 적어두었습니다.

Comment on lines 4 to -6
push:
branches: [ master ]
pull_request:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push할 경우에만 실행하도록 변경하였습니다.

Comment on lines -19 to +20
- 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') }}
Copy link
Member Author

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

Comment on lines -27 to +23
- run: npm ci
- run: npm run build-storybook
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
Copy link
Member Author

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 }}
Copy link
Member Author

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을 사용하였습니다.

Comment on lines -52 to +50
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 }}
Copy link
Member Author

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이 달라지므로 이를 고려하여 반영하였습니다.

@sonarcloud
Copy link

sonarcloud bot commented Apr 8, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@Sung-jin Sung-jin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 👍

@dididy dididy merged commit 8c96835 into witherview:develop Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠 fix This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitHub 토큰 gitflow 이슈를 해결
2 participants