Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(csi-38): create basic project structure with ci/cd pipeline #1

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
// project: 'tsconfig.json',
},
plugins: [
'@typescript-eslint'
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'no-console': 'error',
'quote-props': ['error', 'as-needed'],
quotes: ['error', 'single', { allowTemplateLiterals: false }],
indent: ['error', 2, { SwitchCase: 1 }],
semi: ['error'],
},
env: {
node: true,
jest: true,
},
overrides: [
{
files: ['test/**/*.ts'],
env: {
jest: true,
},
rules: {
// add here any rules specific to test files
},
},
{
extends: ['plugin:@typescript-eslint/disable-type-checked'],
files: ['./**/*.js'],
},
],
};
33 changes: 33 additions & 0 deletions .github/actions/npm-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'get-npm-cache Action'
description: 'Retrieve and restore NPM cache'

outputs:
cache-dir:
value: ${{ steps.npm-cache-dir.outputs.cache-dir }}
description: 'NPM cache directory'

runs:
using: 'composite'

steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Get npm-cache directory
id: npm-cache-dir
shell: bash
run: |
echo "cache-dir=$(npm config get cache)" >> $GITHUB_OUTPUT
# by default, it should be ~/.npm

- name: Restore npm cache
id: npm-cache-restore
uses: actions/cache/restore@v4
with:
path: ${{ steps.npm-cache-dir.outputs.cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

# todo: think, if we should move npm ci here?
48 changes: 48 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Main CI (install/cache + lint/tests)

on:
workflow_call:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize

jobs:
install-and-cache:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: "${{ secrets.COMMIT_KEY }}"

- name: Use get-npm-cache Action
id: npm-cache-dir
uses: ./.github/actions/npm-cache
- run: npm ci

- name: Save npm cache
id: npm-cache-save
uses: actions/cache/save@v4
with:
path: ${{ steps.npm-cache-dir.outputs.cache-dir }}
key: "${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}"

lint-and-test:
runs-on: ubuntu-latest
needs: install-and-cache

steps:
- uses: actions/checkout@v4

- name: Use get-npm-cache Action
uses: ./.github/actions/npm-cache
- run: npm ci

- run: npm run build
- run: npm run lint
- run: npm run test
88 changes: 20 additions & 68 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -21,12 +16,11 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -42,27 +36,18 @@ build/Release
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo
# TypeScript dist folder
dist/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -72,59 +57,26 @@ web_modules/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
# dotenv environment variables file
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
# next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/
# typedocs directory
docs/

# DynamoDB Local files
.dynamodb/
# editor directory
.vscode/**

# TernJS port file
.tern-port
# idea directory
.idea/**
**/*.iml

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# https://devspace.sh/
devspace*
.devspace/**.*

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Add Ignores
*IGNORE*
*ignore*
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
6 changes: 6 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run dep:check
npm run audit:check
npm run test:unit
4 changes: 4 additions & 0 deletions .ncurc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Add a comment indicating the reason for each rejected dependency upgrade added to this list, and what should be done to resolve it (i.e. handle it through a story, etc).
reject: [
"eslint" # typescript-eslint v7 only supports eslint v8
]
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.14.0
17 changes: 17 additions & 0 deletions .nycrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: "@istanbuljs/nyc-config-typescript"
all: true
check-coverage: true
per-file: true
temp-directory: "./.nyc_output"
lines: 90
statements: 90
functions: 90
branches: 90
include:
- "src/**/*.ts"
require:
- ts-node/register
reporter:
- text-summary
- lcov
- json
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
semi: true,
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};
20 changes: 20 additions & 0 deletions .versionrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* References:
* https://github.com/conventional-changelog/conventional-changelog-config-spec
* https://github.com/conventional-changelog/standard-version#customizing-changelog-generation
**/

module.exports = {
types: [
{type: "feat", section: "Features", hidden: false},
{type: "fix", section: "Bug Fixes", hidden: false},
{type: "chore", section: "Chore", hidden: false},
{type: "docs", section: "Documentation", hidden: false},
{type: "style", section: "Style", hidden: false},
{type: "refactor", section: "Refactor", hidden: false},
{type: "perf", section: "Performance", hidden: false},
{type: "test", section: "Test", hidden: false},
{type: "ci", section: "Continuous Integration", hidden: true},
{type: "build", section: "Build", hidden: true}
]
}
6 changes: 6 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @vijayg10 @geka-evk
# will be requested for review when someone opens a pull request.

* @vijayg10 @geka-evk
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributing Guidelines

## How to Contribute

1. Fork this repository
2. Create a new branch
3. Submit a pull request

NOTE: To make the Pull Requests' (PRs) testing and merging process easier, please submit changes to multiple charts in separate PRs unless the changes are related.

### Technical Requirements

When submitting a PR make sure that it:

1. Must pass CI jobs for linting and test the changes on top of different k8s platforms.
2. Must follow best practices and coding standards.
3. Do NOT bump the version as versioning will be handled by our CI/CD release process using semver principles driving by [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). CI/CD will then automatically create Tagged/Github releases with an updated [CHANGELOG](./CHANGELOG.md), and then publish (including your changes) to our artefact (i.e. Docker, NPM, etc) repository.

### Documentation Requirements

1. [README.md](./README.md) must include:
1. configuration options; and
2. instructions on how to run and test this component

## Committing Changes

Git commits will execute the following pre-hook scripts:

- [commit-msg](./.husky/commit-msg): this will validate commit messages against [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standards.
- [pre-commit](./.husky/pre-commit): this will execute standard checks (e.g. lint, dependencies, audits, unit tests, etc) before allowing the commit to pass.

This can be avoided by using the `-n` (e.g. `git commit -n -m 'fix: bad bug'`) flag when committing changes as these checks are done as part of our CI/CD workflow, and are merely in place for the convenience of the developer.

## Releases

As part of our CI/CD process, we automatically trigger our releases and image builds on merges to `main` branch. This process essentially mimics a manual tag and release.

Once those changes are pushed to the `main` branch, CI/CD workflows will pull create a new tagged release (including an updated [CHANGELOG](./CHANGELOG.md)) using semantic versioning based on the commit history (using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)), this will then trigger off a GitHub release, followed by the publishing of any artifacts (i.e. Docker images, NPM libraries, etc).

## Snapshots

Snapshot releases are handled manually by the developer working from a branch (e.g. `fix/bad-bug-example`).

Snapshots can be triggered by running following command, which will:

1. create a snapshot of the current version as `v#.#.#-snapshot.#`.
2. commit changes to git locally.

```bash
npm run snapshot
```

You will need to then manually push the changes and the tag to Github:

```bash
git push --follow-tags
```

The automated CI-CD release process will then publish the snapshot artifact.
Loading