-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ty-ras/issue/1-add-cicd-setup
#1 Adding CI/CD setup.
- Loading branch information
Showing
26 changed files
with
554 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"all": true, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"src/**/__test__/**/*.*", | ||
"**/*.d.ts", | ||
"**/*.types.ts", | ||
"src/index.ts" | ||
], | ||
"reporter": [ | ||
"text", | ||
"json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# adding Flags to your `layout` configuration to show up in the PR comment | ||
comment: | ||
layout: "reach, diff, flags, files" | ||
behavior: default | ||
require_changes: false | ||
require_base: yes | ||
require_head: yes | ||
branches: null | ||
ignore: | ||
- '**/*.spec.ts' | ||
|
||
flag_management: | ||
# this section will govern all default rules of Flags | ||
default_rules: | ||
statuses: | ||
- name_prefix: project- | ||
type: project | ||
target: auto | ||
threshold: 1% | ||
- name_prefix: patch- | ||
type: patch | ||
target: auto | ||
threshold: 1% | ||
# coverage: | ||
# status: | ||
# # pull-requests only | ||
# patch: | ||
# default: | ||
# threshold: 1% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// ESLint config for formatting the <project name>/src/**/*.ts files. | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:type-only-import/recommended", | ||
"plugin:jsdoc/recommended-typescript-error", | ||
"plugin:prettier/recommended", | ||
"plugin:sonarjs/recommended" | ||
], | ||
plugins: [ | ||
"type-only-import", | ||
"jsdoc", | ||
"prettier" | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
sourceType: "module", | ||
ecmaVersion: "latest", | ||
tsconfigRootDir: __dirname, | ||
}, | ||
rules: { | ||
"prettier/prettier": "error", | ||
//"function-paren-newline": ["error", "always"], | ||
"@typescript-eslint/explicit-module-boundary-types": "off", // IDE will show the return types | ||
"@typescript-eslint/restrict-template-expressions": "off", // We are OK with whatever type within template expressions | ||
"@typescript-eslint/unbound-method": "off", // We never use 'this' within functions anyways. | ||
"@typescript-eslint/no-empty-function": "off", // Empty functions are ok sometimes. | ||
"no-useless-return": "error", | ||
"no-console": "error", | ||
"sonarjs/no-nested-template-literals": "off", // Nested template literals are OK really | ||
"jsdoc/require-file-overview": "error", | ||
"jsdoc/require-jsdoc": [ | ||
"error", | ||
{ | ||
"publicOnly": true, | ||
"require": { | ||
"ArrowFunctionExpression": true, | ||
"ClassDeclaration": true, | ||
"ClassExpression": true, | ||
"FunctionDeclaration": true, | ||
"FunctionExpression": true, | ||
"MethodDefinition": true | ||
}, | ||
"exemptEmptyConstructors": true, | ||
"exemptEmptyFunctions": false, | ||
"enableFixer": false, | ||
"contexts": [ | ||
"TSInterfaceDeclaration", | ||
"TSTypeAliasDeclaration", | ||
"TSMethodSignature", | ||
"TSPropertySignature" | ||
] | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ESLint config for formatting the resulting .d.ts files (<project name>/dist-ts/**/*.d.ts) that end up in NPM package for typing information. | ||
const { extends: extendsArray, plugins, rules } = require("./.eslintrc.cjs"); | ||
module.exports = { | ||
root: true, | ||
extends: extendsArray.filter((ext) => ext.startsWith("plugin:jsdoc/") || ext.startsWith("plugin:prettier/")), | ||
plugins: plugins.filter((plugin) => plugin === "jsdoc" || plugin === "prettier"), | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.out.json", | ||
sourceType: "module", | ||
ecmaVersion: "latest", | ||
tsconfigRootDir: __dirname, | ||
}, | ||
rules: Object.fromEntries(Object.entries(rules).filter(([ruleKey]) => ruleKey.startsWith("jsdoc/") || ruleKey.startsWith("prettier/"))), | ||
// So we won't get errors on comments disable e.g. @typescript-eslint/xyz rules. | ||
noInlineConfig: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ESLint config for formatting the resulting .[m]js files (<project name>/dist-(cjs|mjs)/**/*.[m]js) that end up in NPM package. | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"plugin:path-import-extension/recommended", | ||
"plugin:prettier/recommended", | ||
], | ||
plugins: [ | ||
"path-import-extension", | ||
"prettier" | ||
], | ||
parser: "@babel/eslint-parser", | ||
parserOptions: { | ||
requireConfigFile: false | ||
}, | ||
rules: { | ||
"prettier/prettier": "error", | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: Build, test, and publish | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
fetch-depth: | ||
required: true | ||
type: number | ||
pre-run-function: | ||
required: false | ||
type: string | ||
default: | | ||
tyras_pre_run () | ||
{ | ||
echo 'No pre-run.' | ||
} | ||
post-run-function: | ||
required: false | ||
type: string | ||
default: | | ||
tyras_post_run () | ||
{ | ||
cd "$1" | ||
cp ../LICENSE ./LICENSE.txt | ||
# Note - yarn doesn't have functionality to install package without saving it to package.json (!) | ||
# So we use global install instead. | ||
yarn global add "@jsdevtools/npm-publish@$(cat ../versions/npm-publish)" | ||
npm-publish --dry-run --access public | ||
} | ||
secrets: | ||
npm-publish-token: | ||
required: false | ||
|
||
jobs: | ||
build_and_test: | ||
strategy: | ||
matrix: | ||
dir: | ||
- config | ||
- typed-sql | ||
runs-on: ubuntu-latest | ||
name: Build and test ${{ matrix.dir }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: ${{ inputs.fetch-depth }} | ||
|
||
- id: prepare | ||
name: Prepare ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
${{ inputs.pre-run-function }} | ||
tyras_pre_run '${{ matrix.dir }}' | ||
- id: install | ||
name: Install dependencies of ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
./scripts/install.sh '${{ matrix.dir }}' --frozen-lockfile | ||
- id: test | ||
name: Test ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
./scripts/test.sh '${{ matrix.dir }}' coverage | ||
# Run build *after* tests - since tests no longer require transpiled JS to run | ||
# We still want to run build to catch any TS error possibly lurking somewhere. | ||
- id: compile | ||
name: Compile ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
./scripts/build.sh '${{ matrix.dir }}' ci | ||
- id: lint | ||
name: Lint ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
./scripts/lint.sh '${{ matrix.dir }}' | ||
- id: coverage | ||
name: Upload coverage for '${{ matrix.dir }}' | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
flags: ${{ matrix.dir }} | ||
directory: ${{ matrix.dir }} | ||
|
||
- id: finalize | ||
name: Finalize ${{ matrix.dir }} | ||
shell: bash | ||
run: | | ||
set -e | ||
${{ inputs.post-run-function }} | ||
tyras_post_run '${{ matrix.dir }}' | ||
env: | ||
NPM_PUBLISH_TOKEN: ${{ secrets.npm-publish-token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: CD Pipeline | ||
|
||
# After each successful PR merge to main branch. | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: cd | ||
|
||
# Tbh, the most optimal way would be if I could reuse steps instead of jobs | ||
# I guess that is possible if I would create separate folder for the action, but right now it seems like too heavy approach. | ||
# Worth investigating later tho. | ||
jobs: | ||
cd_job: | ||
uses: ./.github/workflows/build-and-test.yml | ||
with: | ||
fetch-depth: 0 # We must fetch whole history to be able to search for tags | ||
# Don't use normal NPM publish actions in order to avoid token writing to .npmrc file. | ||
post-run-function: | | ||
tyras_post_run () | ||
{ | ||
PACKAGE_VERSION="$(cat "$1/package.json" | jq -rM .version)" | ||
GIT_TAG_NAME="$1-v${PACKAGE_VERSION}" | ||
if [[ -n "$(git ls-remote --tags origin "${GIT_TAG_NAME}")" ]]; then | ||
echo "Detected that tag ${GIT_TAG_NAME} already is existing, not proceeding to publish package $1" | ||
else | ||
# The release can be performed, start by creating Git tag locally | ||
# If there are any errors here, we won't end up in situation where NPM package is published, but no Git tag exists for it | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "CD Automation" | ||
git tag \ | ||
-a \ | ||
-m "Component $1 release ${PACKAGE_VERSION}" \ | ||
"${GIT_TAG_NAME}" | ||
# Publish NPM package | ||
cd "$1" | ||
cp ../LICENSE ./LICENSE.txt | ||
# Note - yarn doesn't have functionality to install package without saving it to package.json (!) | ||
# So we use global install instead. | ||
yarn global add "@jsdevtools/npm-publish@$(cat ../versions/npm-publish)" | ||
npm-publish --access public --token "${NPM_PUBLISH_TOKEN}" | ||
# Push Git tag | ||
git push origin "${GIT_TAG_NAME}" | ||
fi | ||
} | ||
secrets: | ||
npm-publish-token: ${{ secrets.NPM_PUBLISH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: CI Pipeline | ||
|
||
# On each commit to PR to main branch. | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
ci_job: | ||
uses: ./.github/workflows/build-and-test.yml | ||
with: | ||
fetch-depth: 1 # No need to fetch whole history for CI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
.vscode | ||
build | ||
dist* | ||
coverage | ||
.yarn | ||
yarn-*.log | ||
*/.eslintrc*.cjs | ||
*/tsconfig*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 80, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Typesafe REST API Specification | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Typesafe REST API Specification - Runtypes Extras Libraries | ||
|
||
[![CI Pipeline](https://github.com/ty-ras/extras-runtypes/actions/workflows/ci.yml/badge.svg)](https://github.com/ty-ras/extras-runtypes/actions/workflows/ci.yml) | ||
[![CD Pipeline](https://github.com/ty-ras/extras-runtypes/actions/workflows/cd.yml/badge.svg)](https://github.com/ty-ras/extras-runtypes/actions/workflows/cd.yml) | ||
|
||
The Typesafe REST API Specification is a family of libraries used to enable seamless development of Backend and/or Frontend which communicate via HTTP protocol. | ||
The protocol specification is checked both at compile-time and run-time to verify that communication indeed adhers to the protocol. | ||
This all is done in such way that it does not make development tedious or boring, but instead robust and fun! | ||
|
||
This particular repository contains generic libraries related to using [`runtypes`](https://github.com/pelotom/runtypes): | ||
- [typed-sql](./typed-sql) contains library which enables type-safe SQL query string specification and execution with a help of [tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) and [`runtypes`](https://github.com/pelotom/runtypes) library for input and output validation. | ||
- [config](./config) contains library which encapsulates common logic related to reading JSON-encoded configuration values from e.g. environment variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default { | ||
cache: false, // We run Ava in non-coverage mode with 'ro' modifier for Docker volume | ||
extensions: { | ||
ts: "module" | ||
}, | ||
nodeArguments: [ | ||
"--loader=ts-node/esm", | ||
"--experimental-specifier-resolution=node", | ||
"--trace-warnings" | ||
], | ||
files: [ | ||
"**/__test__/*.spec.ts" | ||
], | ||
timeout: "10m", | ||
verbose: true, | ||
// The default is number of corse, which in CI I guess is 1 | ||
concurrency: 5 | ||
} |
Oops, something went wrong.