error: pathspec ‘main’ did not match any file(s) known to git
2023.10.11
Github Actions
를 이용하여 npm
모듈 packages
를 배포할 때, 자동으로 버전을 업데이트하고 태깅을 자동화하려고 하였을 때, 다음과 같은 에러가 발생했다. yaml 파일 작성은 공식 문서를 참고하면 된다.
error: pathspec 'main' did not match any file(s) known to git
npm
모듈은 package.json
, package-lock.json
에 있기 때문에, release
할 때, 버전을 자동으로 올려주는 것을 처리하려고 하면, Github actions에 다음과 같은 step을 추가해주면 된다.
- name: Check package version
run: npm version patch
- name: Push changes
run: git push origin main --tags
를 이용하여, pakcage.json
과 package-lock.json
의 버전을 올려준 뒤, 해당 버전으로 커밋을 생성하고, 태그를 추가해준 뒤, 깃헙 origin
에 push
를 해줄 때, 에러가 발생하였다.
actions/checkout@v4
The branch, tag or SHA to checkout. When checking out the repository that triggered a workflow, this defaults to the reference or SHA for that event. Otherwise, uses the default branch.
release
를 생성하였을 때는, ref
를 이용하여, 특정 브랜치를 설정해주어야 된다.
steps:
- uses: actions/checkout@v4
with:
ref: main
References:
https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
https://stackoverflow.com/questions/69390914/github-action-on-release-push-fails
https://github.com/actions/checkout/blob/main/README.md#usage