Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/teambit/bit-with-github-actions

A Bit integration with GitHub Actions CI.
https://github.com/teambit/bit-with-github-actions

bit ci component-architecture component-library components design-system design-systems

Last synced: about 18 hours ago
JSON representation

A Bit integration with GitHub Actions CI.

Awesome Lists containing this project

README

        

# Bit with GitHub Actions

![Build CI](https://github.com/teambit/bit-with-github-actions/workflows/Build%20CI/badge.svg)
![Bit export CI](https://github.com/teambit/bit-with-github-actions/workflows/Bit%20export%20CI/badge.svg)
[![components](https://img.shields.io/badge/dynamic/json.svg?color=6e3991&label=components&query=payload.totalComponents&url=https%3A%2F%2Fapi.bit.dev%2Fscope%2Fjoshk%2Fbit-with-github-actions)](https://bit.dev/joshk/bit-with-github-actions)
[![Slack](https://badgen.now.sh/badge/chat/on%20Slack/cyan)](https://join.slack.com/t/bit-dev-community/shared_invite/enQtNzM2NzQ3MTQzMTg3LWI2YmFmZjQwMTkxNmFmNTVkYzU2MGI2YjgwMmJlZDdkNWVhOGIzZDFlYjg4MGRmOTM4ODAxNTIxMTMwNWVhMzg)

How to integrate Bit in your workflow with GitHub Actions.

## npm install for public or private [Bit components](https://github.com/teambit/bit) during CI (for projects that install components)

For installing public components you need to config the bit registry. To do so create an `.npmrc` file in your project's root directory, and place the following code inside:

```
@bit:registry=https://node.bit.dev
always-auth=true
```

For installing private components, you need to save your `BIT_TOKEN` in the repository settings.

Follow these steps to do this:

- Read how to create encrypted [secrets for a repository](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository).
- Create a new secret and name it `BIT_TOKEN` and then set your Bit token in the value. To get your token, run `bit config get user.token` on your local terminal.
- Update the `.npmrc` file to include the token registry:

```
@bit:registry=https://node.bit.dev
//node.bit.dev/:_authToken=${BIT_TOKEN}
always-auth=true
```

- Now use your secret in the [main workflows file](.github/workflows/main.yml), [read more about it](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#using-encrypted-secrets-in-a-workflow).

## bit export during CI

- Create your collection on [bit.dev](bit.dev).
- Import the [compiler you need](https://bit.dev/bit/envs).
- Import the [tester you need](https://bit.dev/bit/envs).
- Track, tag and export components to your collection, [Alert component for example](src/components/Alert).
- Create a new workflow file for bit export commands. Inside the file we need to do the following: configure Bit token, install Bit, run bit import, build&test, tag and export.
Check out the [workflows file](.github/workflows/bitexport.yml) I wrote about this, it will run when push to master are made(you can change/add branches it to your needs).
Bit will tag components only if changes are made, and it will export and commit back to master the changes that are made to the `.bitmap` file.
- The components will be exported to the default scope that we can configure in the Bit config object inside the `package.json` file.
```
"bit": {
...
"defaultScope": "."
}
```
- When a new component is tracked locally, and then exported during the CI, Bit exports it to the default collection. ([CI example](https://github.com/teambit/bit-with-github-actions/runs/761617133?check_suite_focus=true))
- When a component's test fails in the CI, it is not exported. ([CI example](https://github.com/teambit/bit-with-github-actions/runs/761573923?check_suite_focus=true))

## Run Bit build & test on PR's

When someone in your team made a change to a component, you want to be sure that everything is working well before exporting a new version of it.
For this, I wrote another [workflows file](.github/workflows/bitbuildandtest.yml), and it will run when pull requests are made to master (you can change/add branches it to your needs).
After all the checks have passed, you can merge it.
Now, the [bit export workflows file](.github/workflows/bitexport.yml) will run automatically, and it will export and commit back to master the changes that are made to the `.bitmap` file.

### [Open PR with success workflow example](https://github.com/teambit/bit-with-github-actions/pull/7)



### [Open PR with failure workflow example](https://github.com/teambit/bit-with-github-actions/pull/6)



## Options

- Skip CI: skip bit export workflow by entering `skip-ci` in the commit message.