Creating GitHub releases with Powershell

GitHub allows you to maintain a list of your previous releases, linked to the commit that was used, and attach any artifacts you have, see the releases page of the TeamCity xUnit meta runner for an example. You can create these manually from the GitHub website, but I wanted to add it into my Continuous Integration process, creating a release with the built artifacts on every checkin. This example uses Appveyor for the CI server (Scott Hanselman talks more about it here), but could use any CI system which allows you to run Powershell scripts.

The Script

The script has a few variables that need to be configured for your project. The example below uses Appveyor environment variables for a lot of these. The variables are:

  • $versionNumber – The version number to be used – this will be prepended with ‘v’ when creating the release and the tag in GitHub
  • $commitId – The git commit ID associated with this release
  • $releaseNotes – The notes to display with the release, this example uses the commit message
  • $artifactOutputDirectory – The folder where the artifact will be created
  • $artifact – The filename of the artifact to attach
  • $gitHubUsername – The username of the user or organisation that owns the repository
  • $gitHubRepository – The name of the repository
  • $gitHubApiKey – The API key to use when creating the release. Read this page for information on creating an API key. This key needs to be kept secure, if you’re using Appveyor check out there encrypted variable feature.
  • $draft - Draft releases can only be seen by project members
  • $preRelease – Release will be marked as “Pre-Release”, will be shown to all users but not shown as the latest release until it is updated.

Appveyor Setup

Once you have updated the variables add this script to the “On build success script” textbox on the project settings page

Now when your build runs you should see a new release in GitHub complete with your built artifact.

  • Post
  • Rachel
    Rachel

    Hello,

    Thank you for this - it doesn't appear to work with GitHub given that OAuth is now required.