Skip to content

Commit

Permalink
chore: rework project side configuration (#64)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a pre-installation script to enforce the use of `pnpm` as
the package manager.
- Updated workspace configuration to include all subdirectories under
`apps` and `libs`.
- Added new GitHub Actions workflows for CI checks, cache cleanup, and
release automation.
- Implemented a new target for semantic release in the flowbite-angular
library.

- **Chores**
- Modified CI workflow and other configuration files to transition from
`npm` to `pnpm`.
	- Removed environment variables from the Vercel configuration.
- Introduced a new composite action for installing dependencies using
`pnpm`.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
MGREMY authored Oct 26, 2024
2 parents 8eaf281 + 3e1affc commit 3e681ff
Show file tree
Hide file tree
Showing 19 changed files with 22,874 additions and 41,695 deletions.
89 changes: 89 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
########################################################################################
# "pnpm install" composite action for pnpm 7/8+ #
#--------------------------------------------------------------------------------------#
# Requirement: @setup/node should be run before #
# #
# Usage in workflows steps: #
# #
# - name: 📥 Monorepo install #
# uses: ./.github/actions/pnpm-install #
# with: #
# enable-corepack: false # (default) #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31 #
# #
# Versions: #
# - 1.1.0 - 15-07-2023 - Add project custom directory support. #
########################################################################################

name: 'PNPM install'
description: 'Run pnpm install with cache enabled'

inputs:
enable-corepack:
description: 'Enable corepack'
required: false
default: 'false'
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: '.'

runs:
using: 'composite'

steps:
- name: ⚙️ Enable Corepack
if: ${{ inputs.enable-corepack == 'true' }}
shell: bash
working-directory: ${{ inputs.cwd }}
run: |
corepack enable
echo "corepack enabled"
- uses: pnpm/action-setup@v4
if: ${{ inputs.enable-corepack == 'false' }}
with:
run_install: false
# If you're not setting the packageManager field in package.json, add the version here
version: latest-9

- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
id: pnpm-config
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache rotation keys
id: cache-rotation
shell: bash
run: |
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
# Prevent store to grow over time (not needed with yarn)
# Note: not perfect as it prune too much in monorepos so the idea
# is to use cache-rotation as above. In the future this might work better.
#- name: Prune pnpm store
# shell: bash
# run: pnpm prune store

- name: Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: pnpm install --frozen-lockfile --prefer-offline
env:
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install

- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
36 changes: 36 additions & 0 deletions .github/workflows/cache_cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches for closed branches

on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 | grep pnpm)
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49 changes: 0 additions & 49 deletions .github/workflows/ci-checks.yaml

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI Checks

on:
workflow_dispatch:
pull_request:

concurrency: ${{ github.ref }}

jobs:
lint:
name: Lint the code 🕵
runs-on: ubuntu-latest
steps:
- name: Check out the code 🗄
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup NodeJS 💿
uses: actions/setup-node@v4
with:
node-version: 20

- name: Monorepo install
uses: ./.github/actions/setup

- name: Lint the code 🕵
run: pnpm all:lint

test:
name: Run unit tests 🔬
runs-on: ubuntu-latest
steps:
- name: Check out the code 🗄
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup NodeJS 💿
uses: actions/setup-node@v4
with:
node-version: 20

- name: Monorepo install
uses: ./.github/actions/setup

- name: Run unit tests 🔬
run: pnpm all:test -- --ci --verbose

build:
name: Build code 🛠
runs-on: ubuntu-latest
steps:
- name: Check out the code 🗄
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup NodeJS 💿
uses: actions/setup-node@v4
with:
node-version: 20

- name: Monorepo install
uses: ./.github/actions/setup

- name: Build code 🛠
run: pnpm all:build
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- main
- next
- next-major
- alpha
- beta

jobs:
release:
name: Release new version 🛠
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Check out the code 🗄
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup NodeJS 💿
uses: actions/setup-node@v4
with:
node-version: 20

- name: Monorepo install
uses: ./.github/actions/setup

- name: Release new version 🛠
run: pnpm lib:release -- --ci --verbose --skip-nx-cache
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run all:lint
pnpm all:lint
6 changes: 6 additions & 0 deletions .nxreleaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"repositoryUrl": "https://github.com/themesberg/flowbite-angular/",
"tagFormat": "${PROJECT_NAME}@v${version}",
"branches": ["main"]
}

4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
.angular

/.nx/cache
/.nx/workspace-data
/.nx/workspace-data

pnpm-lock.yaml
1 change: 0 additions & 1 deletion apps/docs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@
}
}
}

4 changes: 2 additions & 2 deletions docs/files/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ To contribute, you will need (of course) to be able to build and start the docum

1. Make sure you have `Node.js > v20` installed
2. Run `git clone https://github.com/themesberg/flowbite-angular.git`
3. Run `npm i`
3. Run `pnpm i`
> [!WARNING]
> If some errors happen, check the logs ; it could be some dependencies outside Node.js (example with [parcel library](https://github.com/parcel-bundler/watcher) ; this library needs a C++ compiler installed on the computer)
4. Run `npm run docs:serve`
4. Run `pnpm docs:serve`
> [!TIP]
> This will start local dev server on `localhost:4200`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
| NAME | VALUE |
| :------------ | :------------------: |
| BUILD_COMMAND | `npm run docs:build` |
| UT_COMMAND | `npm run docs:test` |
| E2E_COMMAND | `npm run ...` |
| NAME | VALUE |
| :------------ | :---------------: |
| BUILD_COMMAND | `pnpm docs:build` |
| UT_COMMAND | `pnpm docs:test` |
| E2E_COMMAND | `pnpm ...` |

![build & test.png](build%20&%20test.png)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| NAME | VALUE |
| :------------ | :-----------------: |
| BUILD_COMMAND | `npm run all:build` |
| UT_COMMAND | `npm run lib:test` |
| NAME | VALUE |
| :------------ | :--------------: |
| BUILD_COMMAND | `pnpm all:build` |
| UT_COMMAND | `pnpm lib:test` |

![build & test.png](build%20&%20test.png)
27 changes: 27 additions & 0 deletions libs/flowbite-angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@
},
"lint": {
"executor": "@nx/eslint:lint"
},
"semantic-release": {
"executor": "@theunderscorer/nx-semantic-release:semantic-release",
"options": {
"github": true,
"npm": true,
"changelog": true,
"branches": [
"main",
"next",
"next-major",
"+([0-9])?(.{+([0-9]),x}).x",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"buildTarget": "flowbite-angular:build",
"outputPath": "{workspaceRoot}/dist/libs/flowbite-angular",
"tagFormat": "flowbite-angular@v${version}",
"commitMessage": "chore(flowbite-angular): ${nextRelease.version} [skip cli]\n\n${nextRelease.notes}"
}
}
}
}

Loading

0 comments on commit 3e681ff

Please sign in to comment.