Skip to content

bit-tasks/init

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Initialize Bit for CI/CD Pipelines

Initialize Bit for CI/CD Pipelines

GitHub Actions

This task installs Bit CLI in your CI Agent and executes bit install inside the workspace directory.

Inputs

ws-dir

Optional The workspace directory path from the root. Default "./".

cache

Optional Enables caching for the workflow. Default "false". Available in bit-tasks/init@v2.

ripple

Optional Use ripple ci to build components. Default "false".

skip-deps-install

Optional Skip running bit install command.

skip-bit-install

Optional Skip installing bit cli.

log

Optional Log bit CLI execution, options are: [trace, debug, info, warn, error, fatal], Default "info".

Example usage

  1. Create a new secret variable for BIT_CONFIG_ACCESS_TOKEN(docs) and use it as an environment variable in your GitHub Action.
  2. [Optional] Create new secret variables GIT_USER_NAME, GIT_USER_EMAIL and use them as environment variables in your GitHub Action.
  3. [Optional] Define GITHUB_TOKEN as an environment variable only in the workflow yaml file. Note: This token is automatically generated by GitHub Actions and is a reserved keyword in GitHub action secrets. Therefore, you don't need to create a separate secret for it.
  4. [Optional] If your workspace is not at the root of the Git repository, specify the input parameter ws-dir pointing to the workspace directory path.

Note: GITHUB_TOKEN, GIT_USER_NAME, and GIT_USER_EMAIL are required for tasks like bit-tasks/commit-bitmap@v1, bit-tasks/dependency-update@v1 etc. Therefore, it is recommended to define these variables upfront, which makes the workflow configuration consistent and reusable across different bit-tasks.

name: Test Bit Init
on:
  workflow_dispatch:
jobs:
  install:
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
      GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
      BIT_CONFIG_ACCESS_TOKEN: ${{ secrets.BIT_CONFIG_ACCESS_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Initialize Bit
        uses: bit-tasks/init@v1
        with:
          ws-dir: '<WORKSPACE_DIR_PATH>'

Resolve component packages

Use the below step to resolve component packages from bit.cloud registry.

      - name: Resolve component packages from bit.cloud registry (Mandatory for component installation using package managers other than Bit)
        run: |
          npm config set '@bit:registry' https://node-registry.bit.cloud
          npm config set '@teambit:registry' https://node-registry.bit.cloud
          npm config set //node-registry.bit.cloud/:_authToken ${{ env.BIT_CONFIG_ACCESS_TOKEN }}

Note: For external registries, append a new configuration to the registry config list and configure the authToken if required.

  npm config set`@myorg:registry` https://<my-org-registry-url>
  npm config set //<my-org-registry-url>/:_authToken ${{ <MY ORG ACCESS TOKEN> }}

Docker Support

You can use the official bit docker image to execute the bit-tasks/init@v2 task. This saves the time that used to install bit inside the init task.

name: Bit Init with Docker
on:
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: bitsrc/stable:latest-alpine
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
      GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
      BIT_CONFIG_ACCESS_TOKEN: ${{ secrets.BIT_CONFIG_ACCESS_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Initialize Bit
        uses: bit-tasks/init@v2
        with:
          ws-dir: '<WORKSPACE_DIR_PATH>'

Using a Fixed Docker Image Based on workspace.jsonc

If you need to use a Docker container image with Bit that matches the Bit version defined in your workspace.jsonc file's engine attribute, follow the configuration example below.

/** file: workspace.jsonc **/
{
  // Other configuration options...
  "teambit.harmony/bit": {
    "engine": "1.8.52",
    "engineStrict": true
  }
}

This workflow consists of two jobs:

  1. Job 1 (bit-engine-version): Retrieves the Bit engine version from the workspace.jsonc file.
  2. Job 2 (build): Uses the retrieved Bit engine version to select the appropriate Docker image and run further build steps.
name: Bit Init with Specific Docker Version

on:
  workflow_dispatch:

jobs:
  bit-engine-version:
    runs-on: ubuntu-latest
    outputs:
      engine: ${{ steps.bit-engine-version.outputs.engine }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Get Bit Engine Version
        uses: bit-tasks/init@v2
        id: bit-engine-version
        with:
          ws-dir: "<WORKSPACE_DIR_PATH>"
          skip-bit-install: "true"
          skip-deps-install: "true"

  build:
    runs-on: ubuntu-latest
    needs: bit-engine-version
    container:
      image: bitsrc/stable:${{ needs.bit-engine-version.outputs.engine }}-alpine
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
      GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
      BIT_CONFIG_ACCESS_TOKEN: ${{ secrets.BIT_CONFIG_ACCESS_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Initialize Bit
        uses: bit-tasks/init@v2
        with:
          ws-dir: '<WORKSPACE_DIR_PATH>'

Contributor Guide

Steps to create custom tasks in different CI/CD platforms.

GitHub Actions

Go to the GithHub action task directory and build using NCC compiler. For example;

npm install
npm run build
git commit -m "Update task"
git tag -a -m "action release" v2 --force
git push --follow-tags

For more information, refer to Create a javascript action