Testing and releasing Pharo with GitHub actions
Hi 👋, Travis is becoming a pay to use service. So why not move to GitHub actions to test your Pharo project?
Here I'm presenting everything you need to know to test your project with GitHub Actions.
We'll also see how to release your project (also continuously ✨).
Testing with Smalltalk CI
The simplest case
To test a Pharo project, we will create a GitHub action.
Upon each commit on the
main branch, this action will test your project.
To do so, it:
- checks out your project
- runs Smalltalk CI on your project
To create the GitHub action, you need first to create a file under the folder
Since the action is to test the project, I decided to name it
test.yml, but any other name will work.
So in my git repository I have a file in:
In the file write:
The first lines indicate when the action is triggered.
In this simple case, it is triggered on each push on the branch
Then, the jobs part describes the steps of the CI. It runs on a Ubuntu image. There are three steps, (1) it checks out the last version of the project for the current branch, (2) it prepares the smalltalkCI tool, and (3) it runs smalltalkCI on your project for the Pharo64-8.0 image.
A more complex case
Indeed, you might want to test your project over several pharo versions. In this section, we see another example using GitHub actions matrix:
The name and the trigger part are the same as before. In the build part, we add a matrix strategy. In this strategy, we set the name of the Pharo versions compatible with our project. Then, in the steps, we tell SmallTalk CI to use the current smalltalk name of the matrix.
Testing Upon a Pull Request
It is also possible to test on each Pull Request instead of commit to the main branch. To do so, change the trigger part by
Many other trigger options exist; you should check them on the GitHub action page.
A final version of the file can be found here.
Using GitHub action to test your project is nice, but we can do more. We will automatically release our project using GitHub Actions. To so, we create two other actions: one for common release, one for continuous release.
To create a release action, we first create a new file, for example
This action is triggered upon release creation and will test the project and release an image with the project loaded.
The above example is the one used by the Moose Project.
First, we define an environment variable named
<current matrix name>-Moose.
In addition to the testing steps, we add three steps:
Package takes the source file after testing the project (i.e. .image, .changes, .sources, and pharo.version) and zips them into one zip file with the current matrix name.
Get release allows us to access the release GitHub API.
Thus, we can access the upload URL of the release.
Then, Upload Release Asset uploads the zip file created in the package step.
When developers release their code, the action downloads an image for each specified Pharo version, tests it, packages it, and uploads it in the GitHub release. Then, users can directly download the released version of the project, with project code loaded in the image.
For the continuous release, we add a schedule to trigger the GitHub actions. Thus, if the Pharo image evolves, our build will evolve with it.
Note that we have also changed the way to update the release. Indeed, the Update Release automatically creates a release and uploads the last version of the zip file.
Add releases to Pharo Launcher
Finally, I want to share with you a little script to add the GitHub Release into the Pharo Launcher. To do so:
- Open the Pharo Launcher
- Open a Playground (Ctrl + O, Ctrl + W)
- Execute the following piece of code
This piece of code creates a local source file for the Pharo Launcher template.
In the source file, it specifies using an
HttpListing from the release page of GitHub.
Then, with a filter pattern, it creates a beautiful list inside the Pharo Launcher.
To adapt the piece of code for your project, you need to change the
url: method parameters.
The three files: test, release, and continuous can be found in the Moose project repository
I'd like to thanks the authors of smalltalkCI for their incredible work!
Thanks C. Fuhrman for the typos fixes. 🍌