Custom GitHub Actions for Keycloak projects.
The bot contains the following functionality:
- When adding a new comment
/rerun
as is on a pull request that is open, the bot will re-run any failed jobs in a workflow run. The user commenting needs to be either a collaborator, an owner, a member of the organization or a contributor.
After processing the comment, the bot adds a +1 reaction to the comment.
NOTE: If there are queued GitHub actions in the GitHub organization, it might take some time until bot can start, trigger the re-run of the workflow and add the reaction.
To add it to a repository, add the following GitHub workflow to the repository in its main branch. It will then run the action on each comment on either an issue or a pull request to see if one of the commands listed above has been added. When it runs, it will first check if the conditions mentioned above are met, and only then take action.
It needs write-permissions on pull-requests
to be able to add the reaction, and it needs write access to actions
to re-run the failed actions.
name: Keycloak GitHub Action Bot
on:
issue_comment:
types:
- created
permissions:
actions: write
pull-requests: write
jobs:
act:
runs-on: ubuntu-latest
steps:
- uses: keycloak/keycloak-gh-actionbot@v0.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
Fork the repository, clone it and create a feature branch.
-
Run
npm install
to install the dependencies. -
Make changes to
index.js
. -
Run
npm run format
andnpm run dist
to package the changes todist/index.js
. -
Commit and push the changes to the feature branch.
-
In the main branch of the forked repository, add the action bot that points to the feature branch.
-
Test the changes on the forked repository until satisfied, for example, with a PR and a GitHub action that always fails, and therefore can be re-run:
name: Always Fail on: pull_request: jobs: act: runs-on: ubuntu-latest steps: - run: "false"
-
Create a PR for the main project.
A GitHub action environment can be simulated via environment variables, and the event can be provided via a file.
The following example assumes that the event is stored in the file event.json
.
If environment variable INPUT_GITHUB_TOKEN
is set, the action will run with anonymous/read only access.
export GITHUB_EVENT_NAME=issue_comment
export GITHUB_EVENT_PATH=event.json
export INPUT_GITHUB_TOKEN=ghp_...
export INPUT_DEBUG=true
After the environment variables are set, use the following command to execute the action:
node index.js
- Create a new tag for the release using for example
npm version patch
(likev1.0.1
) - Push the changes to the release branch for those who track only the major version (like
v1
)