Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 5개 있습니다.)
개발 환경 구성: 543. 애저듣보잡 - Github Workflow/Actions 소개
; https://www.sysnet.pe.kr/2/0/12541

개발 환경 구성: 545. github workflow/actions에서 빌드시 snk 파일 다루는 방법 - Encrypted secrets
; https://www.sysnet.pe.kr/2/0/12546

개발 환경 구성: 546. github workflow/actions에서 nuget 패키지 등록하는 방법
; https://www.sysnet.pe.kr/2/0/12548

개발 환경 구성: 547. github workflow/actions에서 Visual Studio Marketplace 패키지 등록하는 방법
; https://www.sysnet.pe.kr/2/0/12552

개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정
; https://www.sysnet.pe.kr/2/0/12904




github workflow/actions에서 nuget 패키지 등록하는 방법

물론 이에 대해서도 github marketplace에 등록된 action이 있으므로,

Publish NuGet
; https://github.com/marketplace/actions/publish-nuget

아래와 같은 방법으로 사용하면 됩니다.

Use GitHub actions to publish NuGet packages
; https://lukelowrey.com/use-github-actions-to-publish-nuget-packages/

따라서, nuget에 등록하는데 사용하는 API key를 "Encrypted secrets"에 (이 글에서는 NUGET_API_KEY라는 이름으로) 등록한 후, 다음과 같은 식으로 사용하는 코드를 추가하면 됩니다.

- name: Publish NuGet
  id: pub_nuget
  uses: brandedoutcast/publish-nuget@v2.5.5
  with:
    PROJECT_FILE_PATH: ./XmlSrcGenerator/XmlSrcGenerator.csproj
    NUGET_KEY: ${{secrets.NUGET_API_KEY}}
    TAG_COMMIT: false
    INCLUDE_SYMBOLS: true

만약 이렇게 등록한 nupkg 파일을 github의 release에도 올리고 싶다면 "github repo의 Release 활성화 및 Actions를 이용한 자동화 방법" 글에서 소개했던 create_release 작업의 추가와 함께 아래와 같은 actions/upload-release-asset 작업이 필요합니다.

- name: Upload Nuget Release Asset
  id: upload-nuget-release-asset
  uses: actions/upload-release-asset@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    upload_url: ${{ needs.create_release.outputs.upload_url }}
    asset_path: ${{ steps.pub_nuget.outputs.PACKAGE_PATH }}
    asset_name: ${{ steps.pub_nuget.outputs.PACKAGE_NAME }}
    asset_content_type: application/octet-stream

참고로, action의 "OUTPUTS" 변수들은 모두 대소문자 구분을 하기 때문에 반드시 문서를 확인하시고 정확히 일치하는 이름을 사용해야 합니다. (예를 들어 위의 yml에서 outputs.package_path라고 쓰면 빈 문자열이 반환됩니다.)

마지막으로 위에서 설명한 내용의 실제 사용 예를 다음의 yml 파일에 적용했습니다.

XmlCodeGenerator/.github/workflows/git-releases.yml
; https://github.com/stjeong/XmlCodeGenerator/blob/master/.github/workflows/git-releases.yml




이미 같은 버전의 패키지가 nuget에 등록되어 있다면 actions/upload-release-asset 작업은 실패 없이 그냥 넘어가게 됩니다. 단지 이런 경우 output으로 출력하는 outputs.PACKAGE_PATH 값이 비어 있게 됩니다. 그래서 이런 상황이라면 nupkg 파일을 github releases에도 업로드하는 actions/upload-release-asset 작업을 수행하는 경우 다음과 같이 오류 메시지가 발생하며 빌드 실패를 합니다.

Run actions/upload-release-asset@v1
  with:
    upload_url: https://uploads.github.com/repos/stjeong/XmlCodeGenerator/releases/39255023/assets{?name,label}
    asset_content_type: application/octet-stream
  env:
    SOLUTION_FILE_PATH: .
    BUILD_CONFIGURATION: Release
    GITHUB_TOKEN: ***
Error: Input required and not supplied: asset_path

만약 실패를 원하지 않는다면 if 조건을 추가해 upload-release-asset 작업을 생략하는 식으로 대응할 수 있습니다.

- name: Upload Nuget Release Asset
  if: steps.pub_nuget.outputs.PACKAGE_PATH != ''
  id: upload-nuget-release-asset
  uses: actions/upload-release-asset@v1
  ...[생략]...




기타 유의할 점이 하나 있다면, nuget api token의 만료가 보통 1년 단위이기 때문에 매해 secrets.NUGET_API_KEY를 갱신시켜줘야 한다는 것을 잊지 마시고. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/16/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13426정성태10/13/20233288스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/20233105닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/20233085스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233224닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233255닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235358스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233109스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233790닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233355닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233161오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233643닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233410디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233604닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236877닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233388Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20234894닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233751닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233739Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233497닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233451VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20233870닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233398오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
13403정성태8/21/20233231오류 유형: 875. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
13402정성태8/20/20233298닷넷: 2137. ILSpy의 nuget 라이브러리 버전 - ICSharpCode.Decompiler
13401정성태8/19/20233536닷넷: 2136. .NET 5+ 환경에서 P/Invoke의 성능을 높이기 위한 SuppressGCTransition 특성 [1]
13400정성태8/10/20233376오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...