Hi there, this blog post explains how to manually trigger builds of GitHub actions.
Instead of just waiting for a code change or a GitHub workflow change? Well, for example the last time your build on master ran, maybe some of the servers used by your build were down (example: npm registry, some API you're using for tests, etc..).
For now GitHub says that there's no way to manually trigger a build, while this question was asked on StackOverflow and some people are even using CURL to trigger manual builds.
But I have found a better way! With my solution, once you'll have it set up, the ⭐️ button of your GitHub repository will trigger a build every time YOU (and only you) will star the repository.
You can do that as many times as you want.
Yes, it's a VERY hacky solution but it works pretty well. ✨
Let's dig into it.
Update your workflow file to include:
on: watch types: [started]
So the workflow will be executed each time you star, or unstar and star again the repo.
If we combine that by a useful advice from Samira in Stack Overflow, you can launch your workflow only if it's the owner who trigger the action.
if: github.actor == github.event.repository.owner.login
It prevents to execute the action by others and only by maintainers for example.
Next you can add your job(s) to do and additional services.
At the end, we have the following workflow...
name: Test on: watch types: [started] jobs: build: runs-on: ubuntu-latest if: github.actor == github.event.repository.owner.login steps: - name: Checkout repository uses: actions/checkout@v2 # add more ...
It's a starter, so you can adapt it for an existing workflow or start a new one with this.
There is the possibility to combine two events.
For example you can set your workflow with the watch event and on each push, to have the both ways.
name: Test on: push: branches: - master watch: types: [started]
Here it run the process for each push on master branch and on star of the repo.
Don't forget that if you want to re-run a workflow which have failed,
you can re-run all the checks with a UI button set for a failed workflow just like that...
It depends on what you really want to do.
Moreover, you can launch the full workflow with the watch event or only some particular steps if you add a conditional if on a step like this:
name: Test on: watch types: [started] jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - name: Step 2 if: github.actor == github.event.repository.owner.login
In this case, it will run step 2 only if the repo is starred by the owner.
Don't forget that the ⭐️ button launch the workflow from the default branch (master) only.
Notice that there is permissions to avoid actions in the repository or to avoid the third party to run your actions in the settings of the repo.
GitHub just released their action APIs which should allow soon either GitHub or browser extensions to add "trigger workflow" buttons on their UI.
I hope you liked this post and special thanks to Vincent who pushed me to write it :)