GitHub Releases present a straightforward to entry methodology for finish customers to obtain versioned software program binaries. You’ll be able to create them manually, however it’s a lot simpler to let GitHub Actions construct them mechanically utilizing launch tags created in your repository.
Utilizing Tagged Releases
Tags are an current characteristic in Git, with prolonged assist provided by GitHub with Releases, which provide a spot to host binaries with related changelogs.
You’ll be able to create a tag very like you’d make a department, besides it’s a hard and fast level that doesn’t transfer and all the time factors to a particular commit. That is helpful for creating versioned releases, and most of the people will create tags utilizing semantic versioning format (Main.Minor.Patch).
Tags may be pushed to GitHub the place they can be utilized in different automation workflows. On this case, we can be establishing a GitHub Actions script that can hear for commits containing tagged releases and mechanically publish the construct artifacts to a launch.
Setting Up GitHub Actions
First, you’ll need to ensure you have a working GitHub Actions construct, and that your construct scripts are functioning correctly. The precise setup on your workflow will rely upon what sort of challenge you’re constructing, however usually, you don’t need to be debugging two issues directly, so it is best to add the discharge publishing as soon as you have already got working artifacts. You’ll be able to learn our information to establishing a GitHub Actions construct to be taught extra.
The very first thing to do is edit the “on” part of your Actions script to additionally run when Tags are created. By default, you most likely have the “push” occasion to trace releases or the grasp department. You’ll want so as to add tags, and set a filter. For all tags, merely use a wildcard:
On the finish of the workflow, after every part is constructed, we are going to create the Launch entry. This can be a two half step—first, we might want to create a brand new Launch object with all of the metadata, after which we are able to use the outputted publish URL for this to add the artifacts. You’ll be able to create a number of add steps in case you have a number of artifacts.
In both case, we are going to need to solely run these steps if the workflow is working due to a tag. We are able to do that with a easy if
examine, and examine if the github.ref
object is a tag, which shops the ref identify of the department or tag that triggered the workflow.
Step one is to create a Launch object, which may be accomplished with the next step. The GitHub token doesn’t must be created manually—it’s a particular token that may all the time be referenced from Actions scripts.
- identify: Create Launch if: startsWith(github.ref, 'refs/tags/') makes use of: actions/create-release@v1 id: create_release with: draft: false prerelease: false release_name: ${{ github.ref }} tag_name: ${{ github.ref }} body_path: CHANGELOG.md env: GITHUB_TOKEN: ${{ secrets and techniques.GITHUB_TOKEN }}
Be aware right here that the changelog for the discharge is saved at CHANGELOG.md
, which should exist for the workflow to run correctly. You’ll be able to edit this with every tag to alter the markdown displayed by GitHub on the discharge web page. There are instruments to generate this mechanically with commit messages, however most groups can have their very own methodology of managing this anyway.
Subsequent, you can begin importing artifacts. This makes use of the add URL from the earlier step, and also you’ll have to outline a path the place it may be discovered together with the show identify for the asset.
- identify: Add Launch if: startsWith(github.ref, 'refs/tags/') makes use of: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets and techniques.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: Oxide.Ext.Sanctuary/bin/Launch/net48/Oxide.Ext.Sanctuary.dll asset_name: Oxide.Ext.Sanctuary.dll asset_content_type: utility/octet-stream
Be aware right here that the content material sort is ready to octet-stream
, which is typical for binary information like executables and DLLs. In case you’re publishing a ZIP or another type of file, you’ll want to change this, although it solely impacts the visuals on the discharge web page.
Now, you may commit the modifications to the Actions workflow, after which create a brand new tag and push it to GitHub. It’s best to see a brand new workflow run being created, besides as a substitute of working off the grasp department, it’s working due to the tag:
As soon as it’s completed, you’ll see the discharge within the GitHub sidebar.