Plus you can then finally add this sweet fucking status badge to your repository!
This repository demonstrates setting up the basics of a GitHub Actions CI pipeline with samples for GitHub Hosted and Self-Hosted options.
The CI approach is Containerized Hasura/Postgres using an Nx Monorepo with a sample NestJs project.
- Direnv
- Yarn
- Docker/Docker-Compose
- Direnv
Install the dependencies using yarn
.
Copy the .envrc.example
to .envrc
and modify the values as necessary.
If you are intending on using the Self-Hosted option then ensure that you update:
GITHUB_API_TOKEN
,GITHUB_USERNAME
,GITHUB_REPOSITORY
.
If you are intending on using the Self-Hosted option, there's a manual step of registering/retrieving an agent token (that is only valid for 1 hour) that isu sed by the agent to register with GitHub to respond to your repository's events. This is made much easier by their API whcich can enable us to programmatically retrieve this token.
You can create a GitHub Api Key on GitHub by visiting your Settings
-> Developer Settings
-> Personal access tokens
.
In order to automatically create workflow agent tokens the api key requires workflows
and full repo
access.
CI Environment variables are being configured using GitHub Secrets.
Configure the ENV for the CI Pipeline using GitHub Secrets. The CI pipeline utilizes a parallel ./ci/docker-compose.ci.yml
stack with different ports and slightly modified naming to prevent collisions.
- Navigate to the
Settings
->Secrets
in your repository - Add the required env variables as secrets here. Refer to GitHub actions documentation for more information on env injection.
DB_PASSWORD
- copy from.envrc
DB_USER
- copy from.envrc
HASURA_ENDPOINT
- for CI use `http://localhost:8082/v1/graphqlHASURA_GRAPHQL_DATABASE_URL
- for CI usepostgres://prisma:prisma@postgres-ci:5432/prisma
(notepostgres-ci
instead ofpostgres-sample
, that is because ci usesdocker-compose.ci.yml
)HASURA_GRAPHQL_ENABLED_LOG_TYPES
- copy from.envrc
HASURA_GRAPHQL_ENABLE_CONSOLE
-false
HASURA_GRAPHQL_MIGRATIONS_DIR
- copy from.envrc
but instead of$PWD
just use.
(./hasura/migrations
)
This repository demonstrates the differences between GitHub Hosted and Self Hosted Solutions. Self Hosted solutions require a host machine to be running in order to execute the workflow whereas GitHub Hosted are always available.
If you want to use the GitHub Hosted option,
- Uncomment the
Build-and-Test-GitHub-Hosted
job in.github/workflows/ci.yml
- Comment out the
Build-and-Test-Self-Hosted
job in.github/workflows/ci.yml
If you want to use the Self Hosted option,
- Ensure that you have a valid GitHub API Key with sufficient permissions and have it added to
GITHUB_API_TOKEN
along with configuringGITHUB_USERNAME
andGITHUB_REPOSITORY
in the.envrc
- Run
yarn actions:total
, which is a convenience script for:yarn actions:create-token
- use the storedGITHUB
repository, username, and api key to retrieve a self-hosted actions agent token and automatically store it in the.envrc
direnv allow
- to update the environment variablesyarn actions:agent
- build and run the actions agent container with the configured token and repository.
- Ensure the
Build-and-Test-Self-Hosted
is uncommented in.github/workflows/ci.yml
- Ensure the
Build-and-Test-GitHub-Hosted
is commented out.github/workflows/ci.yml
- From this point onward you should now have a functioning basic CI pipeline that you can build off of.
- There's no need to only use the self-hosted or github-hosted runners, it is definitely possible to run both jobs concurrently. Play around!
- This can definitely be improved upon. Submit your ideas!
- I haven't figured out a good update path for the Agent... it self updates but exits the container on completion. This necessitates all instances of the version string with the new version in the
agent-container.dockerfile
. I've introduced an optionalGITHUB_ACTIONS_AGENT_VERSION
build arg that can be used to override the default agent version in the dockerfile. Please let me know if you know an easy solution to this problem that's less manual!