DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How GitHub Copilot Helps You Write More Secure Code
  • Code Reviews: Building an AI-Powered GitHub Integration
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Concourse CI/CD Pipeline: Webhook Triggers

Trending

  • Strategies for Securing E-Commerce Applications
  • Simplifying Multi-LLM Integration With KubeMQ
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Navigating Double and Triple Extortion Tactics
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Automate GitHub Releases With CircleCI

Automate GitHub Releases With CircleCI

Learn how to automate your GitHub releases as part of a DevOps workflow using the CircleCI continuous integration tool.

By 
Ricardo Feliciano user avatar
Ricardo Feliciano
·
Jul. 16, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

Releases is a GitHub feature that allows you to present significant snapshots of your code, marked with a git tag, in GitHub’s nice UI. If you’re not currently using releases, I want to show you why you might want to, and how to implement them automatically.

With releases, you get what tags provide–a version number and description–but you also get a longer section for release notes and a place to store and display release artifacts. This means your software’s binary, .deb, .rpm, and AppImage files will be hosted by GitHub for each release, providing a convenient place for users to install your software.

In this post, I will show you how to create releases within CircleCI. For a more general overview, see GitHub’s doc on creating releases.

At its core, GitHub Releases is simply a GitHub feature layered on top of git tags. Let’s break it down:

Git Tags

Git tags give you a version number to mark a specific git commit as well as a short description. Believe it or not, just pushing a git tag to GitHub will create a new release in the “Releases” tab of your project on GitHub. This is a barebones release that includes only the tag information.

Releases

Releases add to git tags by providing a longer, “rich” description, the ability to mark the tag as a normal release or a pre-release, and most importantly, the ability to upload artifacts such as binaries for that release. Uploading these artifacts from CircleCI is what we’re going to walk through here.

Tools

There are a few ways to publish artifacts from a CircleCI build to a GitHub Release:

  • manually with curl and the GitHub API
  • using GitHub Release
  • using GotHub (a GitHub Release fork)
  • and using ghr, which is what we’ll use in our example

Using ghr

The ghr command full details can be found on GitHub, however, we really only need to learn one subcommand:

ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/


This command uploads specific artifacts, typically binaries, to our GitHub release on GitHub. Let’s break this down:

  • ghr -t ${GITHUB_TOKEN} - Here we start the command and pass it a GitHub token for authentication. This is a GitHub Personal Access Token and not an OAuth token/key.

Specifically created via your personal GitHub account, you’ll want to safeguard this token and only load it into the CircleCI environment via a private environment variable.

  • -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} - This is where we pass the GitHub user/org name and the repository name. Both values are passed via built-in CircleCI Environment Variables. No extra work is needed.
  • -c ${CIRCLE_SHA1} - Here we provide the Git commit hash (available in CircleCI as $CIRCLE_SHA1) to ghr. This tells it which commit, and thus tag, the release is for.
  • -delete - This deletes the git tag and release if it already exists.
  • ${VERSION} - We set the git tag/release version via a $VERSION environment variable. This can be any variable you want or a string. Typically this is the same as the version of your software release.
  • ./artifacts/ - Then we set the PATH to find the artifacts. In this case, everything in a directory called artifacts inside the current directory.

Plain CircleCI 2.0 Example

We’ve walked through how to use ghr to create a GitHub Release but let’s see how it can look inside of a CircleCI 2.0 configuration file:

  publish-github-release:
    docker:
      - image: circleci/golang:1.8
    steps:
      - attach_workspace:
          at: ./artifacts
      - run:
          name: "Publish Release on GitHub"
          command: |
            go get github.com/tcnksm/ghr
            VERSION=$(my-binary --version)
            ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/


CI Builds CircleCI 2.0 Example

This is a CircleCI job called publish-github-release that uses a CircleCI Go convenience image. Here’s the breakdown:

  • Using workspaces, we pull in the binaries for our project from a previous job (not covered in this post).
  • This job pulls and compiles ghr via go get (since ghr is written in Go).
  • It populates $VERSION with the output of my-binary --version, our example application for this post.
  • We then use the ghr command to upload the binaries in the artifacts directory to GitHub.

We can shave a few seconds off of the job above by using the ghr Docker image from CI Builds. It’s a lightweight Docker image that already has ghr installed. Here’s how the new example config would look:

  publish-github-release:
    docker:
      - image: cibuilds/github:0.10
    steps:
      - attach_workspace:
          at: ./artifacts
      - run:
          name: "Publish Release on GitHub"
          command: |
            VERSION=$(my-binary --version)
            ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/


Workflow Example

Here’s an example of how one of the variations of the above job can be implemented within a Workflow to publish tagged commits to GitHub releases:

workflows:
  version: 2
  main:
    jobs:
      - build:
          filters:
            tags:
              only: /^\d+\.\d+\.\d+$/
      - publish-github-release:
          requires:
            - build
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^\d+\.\d+\.\d+$/


In this example, we have CircleCI kick off the publish-github-release job when a git tag is pushed. How exactly you choose when to publish a GitHub release is up to you, but here we’ll do it with a SemVer-like git tag. We say SemVer-like because the tag regex we’re using /^\d+\.\d+\.\d+$/ matches tags such as 1.2.3 but doesn’t take into account all of the rules of SemVer (Semantic Versioning). For the sake of completeness, here’s what a complete regex for SemVer would look like according to rgxdb.com:

/(?<=^[Vv]|^)(?:(?<major>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<minor>(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?<patch>(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?<prerelease>(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?<build>(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/


Release (computing) GitHub

Published at DZone with permission of Ricardo Feliciano. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How GitHub Copilot Helps You Write More Secure Code
  • Code Reviews: Building an AI-Powered GitHub Integration
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Concourse CI/CD Pipeline: Webhook Triggers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!