{"id":582823,"date":"2023-07-15T10:00:34","date_gmt":"2023-07-15T07:00:34","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-automatically-publish-github-releases-from-git-tags\/"},"modified":"2023-07-15T10:00:34","modified_gmt":"2023-07-15T07:00:34","slug":"how-to-automatically-publish-github-releases-from-git-tags","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-automatically-publish-github-releases-from-git-tags\/","title":{"rendered":"#How to Automatically Publish GitHub Releases From Git Tags"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2dfb2015df4\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2dfb2015df4\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-automatically-publish-github-releases-from-git-tags\/#Using_Tagged_Releases\" >Using Tagged Releases<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-automatically-publish-github-releases-from-git-tags\/#Setting_Up_GitHub_Actions\" >Setting Up GitHub Actions<\/a><\/li><\/ul><\/nav><\/div>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-738302\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"GitHub hero\" width=\"1200\" height=\"675\"\/><\/p>\n<p>GitHub Releases provide an easy to access method for end users to <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">download<\/a> versioned software binaries. You can create them manually, but it\u2019s much easier to let GitHub Actions build them automatically using release tags created in your repository.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Using_Tagged_Releases\"><\/span>Using Tagged Releases<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895820\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/05\/Screenshot_952.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1077\" height=\"523\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Tags are an existing feature in Git, with extended support offered by GitHub with Releases, which offer a place to host binaries with associated changelogs.<\/p>\n<p>You can create a tag much like you\u2019d make a branch, except it\u2019s a fixed point that doesn\u2019t move and always points to a specific commit. This is useful for creating versioned releases, and most people will create tags using semantic versioning format (Major.Minor.Patch).<\/p>\n<p>Tags can be pushed to GitHub where they can be used in other automation workflows. In this case, we will be setting up a GitHub Actions script that will listen for commits containing tagged releases and automatically publish the build artifacts to a release.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Setting_Up_GitHub_Actions\"><\/span>Setting Up GitHub Actions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>First, you\u2019ll want to make sure you have a working GitHub Actions build, and that your build scripts are functioning properly. The exact setup for your workflow will depend on what kind of project you\u2019re building, but <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly, you don\u2019t want to be debugging two problems at once, so you should add the release publishing once you already have working artifacts. You can read our guide to setting up a GitHub Actions build to learn more.<\/p>\n<p>The first thing to do is edit the \u201con\u201d section of your Actions script to also run when Tags are created. By default, you probably have the \u201cpush\u201d event to track releases or the master branch. You\u2019ll need to add tags, and set a filter. For all tags, simply use a wildcard:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895822\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/05\/Screenshot_951.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"387\" height=\"149\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>At the end of the workflow, after everything is built, we will create the Release entry. This is a two part step\u2014first, we will need to create a new Release object with all the metadata, and then we can use the outputted publish URL for this to upload the artifacts. You can create multiple upload steps if you have multiple artifacts.<\/p>\n<p>In either case, we will want to only run these steps if the workflow is running because of a tag. We can do this with a simple <code>if<\/code> check, and check if the <code>github.ref<\/code> object is a tag, which stores the ref name of the branch or tag that triggered the workflow.<\/p>\n<p>The first step is to create a Release object, which can be done with the following step. The GitHub token doesn\u2019t need to be created manually\u2014it\u2019s a special token that can always be referenced from Actions scripts.<\/p>\n<pre>     - name: Create Release&#13;\n      if: startsWith(github.ref, 'refs\/tags\/')&#13;\n      uses: actions\/create-release@v1&#13;\n      id: create_release&#13;\n      with:&#13;\n        draft: false&#13;\n        prerelease: false&#13;\n        release_name: ${{ github.ref }}&#13;\n        tag_name: ${{ github.ref }}&#13;\n        body_path: CHANGELOG.md&#13;\n      env:&#13;\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895824\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/05\/Screenshot_949.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"787\" height=\"362\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Note here that the changelog for the release is stored at <code>CHANGELOG.md<\/code>, which <strong>must exist for the workflow to run properly<\/strong>. You can edit this with each tag to change the markdown displayed by GitHub on the release page. There are tools to generate this automatically with commit messages, but most teams will have their own method of managing this anyway.<\/p>\n<p>Next, you can start uploading artifacts. This uses the upload URL from the previous step, and you\u2019ll need to define a path where it can be found along with the display name for the asset.<\/p>\n<pre>     - name: Upload Release&#13;\n      if: startsWith(github.ref, 'refs\/tags\/')&#13;\n      uses: actions\/upload-release-asset@v1&#13;\n      env:&#13;\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}&#13;\n      with:&#13;\n        upload_url: ${{ steps.create_release.outputs.upload_url }}&#13;\n        asset_path: Oxide.Ext.Sanctuary\/bin\/Release\/net48\/Oxide.Ext.Sanctuary.dll&#13;\n        asset_name: Oxide.Ext.Sanctuary.dll&#13;\n        asset_content_type: application\/octet-stream<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895823\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/05\/Screenshot_950.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"821\" height=\"319\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Note here that the content type is set to <code>octet-stream<\/code>, which is typical for binary data like executables and DLLs. If you\u2019re publishing a ZIP or some other kind of file, you will want to change this, though it only affects the visuals on the release page.<\/p>\n<p>Now, you can commit the changes to the Actions workflow, and then create a new tag and push it to GitHub. You should see a new workflow run being created, except instead of running off the master branch, it\u2019s running because of the tag:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895825\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/05\/Screenshot_948.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"646\" height=\"246\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once it\u2019s finished, you\u2019ll see the release in the GitHub sidebar.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/devops\/how-to-automatically-publish-github-releases-from-git-tags\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GitHub Releases provide an easy to access method for end users to download versioned software binaries. You can create them manually, but it\u2019s much easier to let GitHub Actions build them automatically using release tags created in your repository. Using Tagged Releases Tags are an existing feature in Git, with extended support offered by GitHub&#8230;<\/p>\n","protected":false},"author":1,"featured_media":582824,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/06\/GitHub-hero.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-582823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/582823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=582823"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/582823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/582824"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=582823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=582823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=582823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}