Our team developed a game called "5 more minutes" for the Playdate as a part of the Summer Slow Jam hosted by PIGSquad. One of the things we wanted to eventually add to our devkit was a way to automatically increment the buildNumber so when our game was sideloaded, the updates would know which one to keep and which to ditch. If you want to read more about what can go into the pdxinfo file, click here.
Well, it’s past the deadline now, and we’re figuring out what to do in preparation for next game jam we participate in for the Playdate.
We’re managing code through GitHub, and we’ve written (probably not for the first time this wheel was invented...) a GitHub action to manage our buildNumber on main.
This script makes the assumption that:
main
, andI am assuming that you know how to use a terminal and can find your directory.
From the root of the directory, run mkdir -p .github/workflows
to create the folders.
mkdir makes directories, and -p allows parent folders that don't exist to also be made.
Change directories into the workflows folder (hint, it's cd .github/workflows
). Then create a new file. We've called it bump-build-number.yml
but it doesn't matter. The command for that is touch bump-build-number.yml
.
This is probably what you're looking for.
name: "Bump buildNumber"
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
bump-build-number:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
run: |
cd source
i=$(cat pdxinfo | sed -n -e 's/buildNumber=//p')
((i=i+1))
oldpdxinfo=$(grep -v 'buildNumber' pdxinfo)
echo "$oldpdxinfo" > pdxinfo
echo "buildNumber=$i" >> pdxinfo
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "main-CI/bump-buildNumber"
git push
name:
is simple enough, every action should have a different name.
on:
defines when the action should be run. In this case, whenever we push to main, run this action.
jobs:
A workflow run is made up of one more more jobs
, which run in parallel by default. Ripped shamelessly from GitHub Docs. Click here to read more. This is essentially what runs the code we want it to run.
bump-build-number:
this is the name of the job. Call it what you want.
runs-on:
this is the image your runner will be using. linux is cheapest at time of writing, and unlikely to change.
steps:
groups all the commands that need to be run in our job.
uses:
dictates what actions we're depending on, in this case, we want to checkout our main
branch to make changes to it.
run: |
allows us to use multiple commands in one block.
Now we're at what I specifically wrote for our project.
cd source
: Since pdxinfo
is in source, and the runner starts at the root of the project, we want to change directories into source.
i=$(cat pdxinfo | sed -n -e 's/buildNumber=//p')
: We're looking for just the number after buildNumber= in pdxinfo, and storing it as i.
((i=i+1))
: increments i by 1.
oldpdxinfo=$(grep -v 'buildNumber' pdxinfo)
: Essentially, we're asking grep to give us all the lines that do not match /buildNumber=/. So name, author, description, etc. and storing it in oldpdxinfo.
echo "$oldpdxinfo" > pdxinfo
: repeat everything from the pdxinfo we had, except for buildNumber. >
erases all content in the file, and replaces it with what we're echoing.
echo "buildNumber=$i" >> pdxinfo
: adds the line buildNumber= i, where i is the buildNumber we had previously, incremented by 1.
git config user.name github-actions
: configures the commit username to github-actions
.
git config user.email github-actions@github.com
: configures the commit email to github-actions@github.com
.
git add .
: adds all changed files in directory. Essentially, we only changed pdxinfo
.
git commit -m "main-CI/bump-buildNumber"
: sets the commit message to "main-CI/bump-buildNumber".
git push
: pushes the change to main.
^ that expands.
And that's that! Tweet me @taithethai if you have any questions!