{"id":8493,"date":"2020-08-17T22:26:18","date_gmt":"2020-08-17T22:26:18","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8493"},"modified":"2020-08-17T22:26:18","modified_gmt":"2020-08-17T22:26:18","slug":"deploying-my-library-to-github-packages-using-github-actions","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/deploying-my-library-to-github-packages-using-github-actions\/","title":{"rendered":"Deploying my library to Github packages using Github actions"},"content":{"rendered":"<p>In my previous post I explained the steps to use Github actions to package and deploy your .nupkg to NuGet, but Github also includes support for you to deploy your package alongside your project sources.<\/p>\n<p>If you take a look at the right hand of your project within Github (i.e. where you see your main README.md) you&#8217;ll notice the <em>Packages<\/em> section, if you click on the <em>Publish your first package<\/em> it tells you the steps you need to take to create and deploy your package, but it wasn&#8217;t quite that simple for me, hence this post will hopefully help others out a little if they hit similar issues.<\/p>\n<p>The first thing you need to do is make sure you are using a version of the dotnet CLI that supports <em>nuget<\/em> commands (specifically the <em>add<\/em> command). Here&#8217;s a set-up step with a compatible version of dotnet CLI.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n - name: Setup .NET Core\r\n      uses: actions\/setup-dotnet@v1\r\n      with:\r\n        dotnet-version: 3.1.401\r\n<\/pre>\n<p>The version must be 3.1.401 or above. There may be another before this but I was using 3.1.101 and was getting the following failure in the build output<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nSpecify --help for a list of available options and commands.\r\nerror: Unrecognized command or argument 'add'\r\n<\/pre>\n<p>So the first command listed in <em>Publish your first package<\/em> will fail if you&#8217;re not upto date with the version of dotnet. If you&#8217;re using ubuntu instead of Windows for your builds, then you need to include the &#8211;store-password-in-clear-text on your <em>dotnet nuget add<\/em> command. Also change GH_TOKEN to ${{ secrets.GITHUB_TOKEN }}<\/p>\n<p>Hence your first command will look more like this now<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndotnet nuget add source https:\/\/nuget.pkg.github.com\/your_user\/index.json -n github -u your_user -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text\r\n<\/pre>\n<p>Replace &#8220;your_user&#8221; with your GitHub username and if you&#8217;ve created a permission that you prefer to use in place of GITHUB_TOKEN, then replace that also.<\/p>\n<p>The second line shown in <em>Publish your first package<\/em> is<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndotnet pack --configuration Release\r\n<\/pre>\n<p>Thankfully this is worked without an issue, however the Step 3 from <emPublish your first package<\/em> didn&#8217;t work for me. It requires that I set the API key, similar to way we do this with NuGet publishing but using GITHUB_TOKEN again, hence the third step for me to publish to GitHub is<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndotnet nuget push your_path\/bin\/Release\/*.nupkg --skip-duplicate --api-key ${{secrets.GITHUB_TOKEN}} --source &quot;github&quot;\r\n<\/pre>\n<p>Replacing &#8220;your_path&#8221; with the path of your package to be published. Use &#8211;skip-duplicate so that any change to your code will not fail when a build is triggered, as without this option the command tries to publish an existing\/unchanged package, causing a failure. Also set the &#8211;api-key as shown.<\/p>\n<p>As I am already creating a package for NuGet and want to do the same for GitHub, we can condense the commands to something like<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nrun: |\r\n  dotnet nuget add source https:\/\/nuget.pkg.github.com\/your_user\/index.json -n github -u your_user -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text\r\n  dotnet nuget push your_path\/bin\/Release\/*.nupkg --skip-duplicate --api-key ${{secrets.GITHUB_TOKEN}} --source &quot;github&quot;\r\n<\/pre>\n<p><strong>Don&#8217;t Forget<\/strong><\/p>\n<p>One more thing, in your nuspec or via the Properties | Package tab for your project, ensure you add a Repository URL to your source code. The Github package will fail without this.<\/p>\n<p>For example in the SDK style csproj we have<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&lt;RepositoryUrl&gt;https:\/\/github.com\/putridparrot\/PutridParrot.Randomizer.git&lt;\/RepositoryUrl&gt;\r\n&lt;RepositoryType&gt;git&lt;\/RepositoryType&gt;\r\n<\/pre>\n<p>The RepositoryType is not required for this to work, just using RepositoryUrl with https:\/\/github.com\/putridparrot\/PutridParrot.Randomizer worked fine.<\/p>\n<p>Within a nuspec the format is as follows (if I recall)<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&lt;repository type=&quot;git&quot; url=&quot;https:\/\/github.com\/putridparrot\/PutridParrot.Randomizer.git&quot; \/&gt;\r\n<\/pre>\n<p>Finally you&#8217;ll want to add https:\/\/nuget.pkg.github.com\/your_user\/index.json to you nuget.config to access Github&#8217;s NuGet package management from a project using this file and you will need a permission set up to access to API to pull in your package, alternatively simply download the package from Github and set-up a local nuget repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post I explained the steps to use Github actions to package and deploy your .nupkg to NuGet, but Github also includes support for you to deploy your package alongside your project sources. If you take a look at the right hand of your project within Github (i.e. where you see your main [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[304,66],"tags":[],"class_list":["post-8493","post","type-post","status-publish","format-standard","hentry","category-github-actions","category-nuget"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8493"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8493\/revisions"}],"predecessor-version":[{"id":8505,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8493\/revisions\/8505"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}