GitHub Actions Day 23: Upload Release Builds
This is day 23 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.
Here's another nice way that GitHub Actions has simplified the way that I manage my open source projects: when I create a new release, GitHub Actions will run a release build and add the final build archive directly to the release itself as an asset.
This means that I don't have to download the build artifact from my CI build and upload it -- or worse, run a build locally and upload it from my machine. Running the final release build within my CI system ensures that I always build it correctly every time.
Here I'll create a workflow that runs whenever I create a release.
(If I were to leave out the types: [created]
here, this workflow
would run on every release activity, including editing or deleting
an existing release, which is definitely not what I want.)
I'll do a checkout, set up Java and then run a build similar to what
I do in a normal CI workflow. But I'll pass a property to maven
(the Java build system that I use) so that my output filename has
no suffix. By default, I add a suffix like SNAPSHOT
so that people
know that this is a prerelease, but for final release builds I want
to make sure that there's no suffix.
I'll also ask maven for the filename that it created, so that I can use it in the upload task.
Finally, I'll run my colleague Jason Etco's very helpful upload-to-release action. This will take my build output and upload it to my release as an asset.
Now when I create a release in the GitHub UI, I don't have to worry about uploading any release assets myself. I don't have to remember the build property that I need to change to create the proper filename, and I don't have to upload it from my machine. Instead, a GitHub Actions workflow run will be queued to take care of all of this for me.
Just another way that I leverage GitHub Actions to help me manage my projects.