Skip to content

Commit

Permalink
docs: describe a setup action on a higher level
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoral committed Feb 21, 2025
1 parent 53f5377 commit 6f44a36
Showing 1 changed file with 38 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,78 +41,53 @@ Let's look at how continuous integration works in a multistore setup, using GitH
First, we need to set up the environment. Our setup action handles several crucial steps:

::tip Why a Separate Setup Action?
We use a separate setup action to follow the DRY (Don't Repeat Yourself) principle, as these setup steps are used in multiple workflows - for instance `continuous-integration.yml` and `continuous-deployment.yml`. However, you can include these steps directly in your workflow if you prefer - there's no technical requirement to have them as a separate action.
We use a separate setup action to follow the DRY (Don't Repeat Yourself) principle, as these setup steps are used in multiple workflows. We've implemented it as a [composite action](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action) to make it reusable across different workflows.
::

Here's how our setup action is defined:
The Setup action performs these steps in sequence:

```yaml
name: Setup repository
description: Installs all the packages and initializes environment variables
1. **Node.js Setup**
- Uses Node.js version specified in `.nvmrc` file

# Define required inputs for npm registry authentication
inputs:
npm_user:
description: Enterprise NPM registry user
required: true
npm_password:
description: Enterprise NPM registry password
required: true
npm_email:
description: Enterprise NPM registry email
required: true
2. **Cache Configuration**
- Sets up Yarn cache for `node_modules` directory to speed up installations
- Configures Turbo build cache for faster builds. Read more about Turbo CI caching [here](https://turbo.build/repo/docs/guides/ci-vendors).

runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ./.nvmrc

# Configure Yarn cache to speed up installations
- name: Yarn cache
uses: actions/cache@v4
with:
path: .yarn
key: storefront-yarn-cache

# Set up Turbo cache for faster builds
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: starter-turbo-${{ github.sha }}
restore-keys: |
starter-turbo-
# Configure access to private npm registry
- name: Configure NPM registry
shell: bash
run: |
npm install -g npm-cli-login;
npm-cli-login -u ${{ inputs.npm_user }} -p ${{ inputs.npm_password }} -e ${{ inputs.npm_email }} -r https://registrynpm.storefrontcloud.io || exit 1;
# Install all project dependencies
- name: Install dependencies
shell: bash
# We use frozen-lockfile to ensure consistent dependencies across all environments
# This is important for CI/CD to avoid unexpected issues
# We run init.mjs to ensure the project is properly initialized
run: yarn install --frozen-lockfile --cache-folder .yarn && node init.mjs
```
3. **NPM Registry Access**
- Configures access to private npm registry
- Uses provided credentials for authentication
```bash
# Install npm-cli-login globally
npm install -g npm-cli-login

# Configure access to Alokai Enterprise Registry
npm-cli-login \
-u $NPM_USER \
-p $NPM_PASSWORD \
-e $NPM_EMAIL \
-r "https://registrynpm.storefrontcloud.io"

# You can verify the configuration by running the following command:
npm config get @alokai:registry
# Should return: https://registrynpm.storefrontcloud.i
```

4. **Dependencies Installation**
- Installs project dependencies using Yarn
- Uses frozen lockfile for consistency
- Runs initialization script
```bash
# Install dependencies with frozen lockfile
yarn install --frozen-lockfile --cache-folder .yarn

# Run initialization script
node init.mjs
```

And here's how we use it in our workflow:
Here's how to use it in your workflow:

```yaml
steps:
# 1. Check out your code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Important: Need full git history for change detection

# 2. Set up environment using our custom action
- name: Install dependencies
uses: ./.github/actions/setup
with:
Expand Down

0 comments on commit 6f44a36

Please sign in to comment.