Skip to content

Commit

Permalink
Merge pull request #74 from ty-ras/issue/73-add-common-code-used-by-c…
Browse files Browse the repository at this point in the history
…lients

Issue/73 add common code used by clients
  • Loading branch information
stazz authored Sep 9, 2023
2 parents 9345025 + d03d69f commit ec00d19
Show file tree
Hide file tree
Showing 76 changed files with 2,734 additions and 5,735 deletions.
29 changes: 0 additions & 29 deletions .codecov.yml

This file was deleted.

118 changes: 105 additions & 13 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,73 @@ on:
default: |
tyras_post_run ()
{
TYRAS_GIT_ROOT="$(pwd)"
cd "$1"
cp ../LICENSE ./LICENSE.txt
cp "${TYRAS_GIT_ROOT}/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)"
yarn global add "@jsdevtools/npm-publish@$(cat "${TYRAS_GIT_ROOT}/versions/npm-publish")"
npm-publish --dry-run --access public
}
secrets:
npm-publish-token:
required: false

jobs:
construct_matrix_input:
runs-on: ubuntu-latest
name: Construct input for matrix job
outputs:
matrix_spec: ${{ steps.set_output.outputs.matrix_spec }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get all global and project-specific changes
id: changed-files-yaml
uses: tj-actions/changed-files@v38
with:
dir_names: true
dir_names_max_depth: 2
json: true
escape_json: false
quotepath: false
files_yaml: |
global:
- 'code/.c8rc.json'
- 'code/.eslintrc.*'
- 'code/.pretterrc'
- 'code/ava.config.mjs'
- 'code/tsconfig.*'
- '.codecov.yml'
- '.github/**'
code:
- 'code/*/**'
- '!code/*/**.md'
- name: Mark all components to be run
if: steps.changed-files-yaml.outputs.global_any_changed == 'true'
run: |
echo "$(find code -type d -maxdepth 1 -mindepth 1 -print0 | while IFS= read -r -d '' line; do jq -nM --arg dirname "$line" '$dirname'; done | jq -sMc)" > __output.txt
- name: Mark only affected components to be run
if: steps.changed-files-yaml.outputs.global_any_changed == 'false' && steps.changed-files-yaml.outputs.code_any_changed == 'true'
run: |
echo '${{ steps.changed-files-yaml.outputs.code_all_changed_files }}' > __output.txt
- name: Save job output
id: set_output
run: |
echo "matrix_spec={\"dir\":$(cat __output.txt || echo '[]')}" > "${GITHUB_OUTPUT}"
build_and_test:
needs:
- construct_matrix_input
# Without this if, the job will fail on empty input
if: needs.construct_matrix_input.outputs.matrix_spec != ''
strategy:
matrix:
dir: [ data, protocol, data-frontend, data-backend ]
matrix: ${{ fromJson(needs.construct_matrix_input.outputs.matrix_spec) }}
runs-on: ubuntu-latest
name: Build and test ${{ matrix.dir }}
steps:
Expand All @@ -52,14 +103,47 @@ jobs:
${{ inputs.pre-run-function }}
tyras_pre_run '${{ matrix.dir }}'
- id: install
name: Install dependencies of ${{ matrix.dir }}
- id: cache-dl
name: Cache downloaded Yarn packages
uses: actions/cache@v3
env:
cache-name: cache-dl
with:
# Our install script uses this as yarn cache directory
path: .yarn
# We don't need OS in cache key, as we run yarn always via Docker (Alpine image)
key: ${{ env.cache-name }}-${{ matrix.dir }}-${{ hashFiles(format('{0}/yarn.lock', matrix.dir)) }}

- id: cache-modules
name: Cache installed Yarn packages
uses: actions/cache@v3
env:
cache-name: cache-modules
with:
# Our install script uses this as yarn cache directory
path: ${{ matrix.dir }}/node_modules
# We don't need OS in cache key, as we run yarn always via Docker (Alpine image)
key: ${{ env.cache-name }}-${{ matrix.dir }}-${{ hashFiles(format('{0}/yarn.lock', matrix.dir)) }}

- id: install-fresh
if: steps.cache-dl.outputs.cache-hit != 'true' || steps.cache-modules.outputs.cache-hit != 'true'
name: Download and install Yarn packages
shell: bash
run: |
set -e
./scripts/install.sh '${{ matrix.dir }}' --frozen-lockfile
- id: install-existing
if: steps.cache-dl.outputs.cache-hit == 'true' && steps.cache-modules.outputs.cache-hit == 'true'
name: Setup target project
shell: bash
run: |
set -e
./scripts/setup-project.sh '${{ matrix.dir }}' --frozen-lockfile

- id: test
name: Test ${{ matrix.dir }}
shell: bash
Expand All @@ -68,6 +152,16 @@ jobs:
./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
Expand All @@ -76,22 +170,20 @@ jobs:
./scripts/lint.sh '${{ matrix.dir }}'
# 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.
# Because we test first and build then, we can do compilation without __tests__ directory.
- id: compile
name: Compile ${{ matrix.dir }}
# CodeCov does not accept flags with '/' in them
- id: prepare-coverage
name: Prepare coverage
shell: bash
run: |
set -e
./scripts/build.sh '${{ matrix.dir }}' ci
echo "flag=$(basename '${{ matrix.dir }}')" >> $GITHUB_OUTPUT
- id: coverage
name: Upload coverage for '${{ matrix.dir }}'
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.dir }}
flags: ${{ steps.prepare-coverage.outputs.flag }}
directory: ${{ matrix.dir }}

- id: finalize
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
post-run-function: |
tyras_post_run ()
{
PACKAGE_VERSION="$(cat "$1/package.json" | jq -rM .version)"
GIT_TAG_NAME="$1-v${PACKAGE_VERSION}"
TYRAS_LIB_DIR="$1"
TYRAS_LIB_NAME="$(basename "${TYRAS_LIB_DIR}")"
PACKAGE_VERSION="$(cat "${TYRAS_LIB_DIR}/package.json" | jq -rM .version)"
GIT_TAG_NAME="${TYRAS_LIB_NAME}-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
Expand All @@ -31,15 +33,16 @@ jobs:
git config --global user.name "CD Automation"
git tag \
-a \
-m "Component $1 release ${PACKAGE_VERSION}" \
-m "Component ${TYRAS_LIB_NAME} release ${PACKAGE_VERSION}" \
"${GIT_TAG_NAME}"
# Publish NPM package
cd "$1"
cp ../LICENSE ./LICENSE.txt
TYRAS_GIT_ROOT="$(pwd)"
cd "${TYRAS_LIB_DIR}"
cp "${TYRAS_GIT_ROOT}/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)"
yarn global add "@jsdevtools/npm-publish@$(cat "${TYRAS_GIT_ROOT}/versions/npm-publish")"
npm-publish --access public --token "${NPM_PUBLISH_TOKEN}"
# Push Git tag
Expand Down
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
node_modules
.vscode
build
dist*
coverage
.yarn
yarn-*.log
*/.eslintrc*.cjs
*/tsconfig*.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The protocol specification is checked both at compile-time and run-time to verif
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 data validation related libraries, and is designed to be consumed by other TyRAS libraries:
- [data](./data) contains some core types and utility methods to handle data validation,
- [protocol](./protocol) contains protocol-related types for other libraries to build their own types on,
- [data-frontend](./data-frontend) contains types and utility methods to create callbacks to invoke backend endpoints from frontend, and
- [data-backend](./data-backend) contains types and utility methods to handle data validation on backend side.
- [data](./code/data) contains some core types and utility methods to handle data validation,
- [protocol](./code/protocol) contains protocol-related types for other libraries to build their own types on,
- [data-frontend](./code/data-frontend) contains types and utility methods to create callbacks to invoke backend endpoints from frontend, and
- [data-backend](./code/data-backend) contains types and utility methods to handle data validation on backend side.
File renamed without changes.
9 changes: 0 additions & 9 deletions .eslintrc.library.cjs → code/.eslintrc.library.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:type-only-import/recommended",
"plugin:jsdoc/recommended-typescript-error",
"plugin:prettier/recommended",
"plugin:sonarjs/recommended"
],
plugins: [
"import",
"type-only-import",
"jsdoc",
"prettier"
Expand Down Expand Up @@ -60,11 +57,5 @@ module.exports = {
]
}
]
},
settings: {
"import/resolver": {
typescript: true,
node: true
}
}
};
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
build
dist*
coverage
*/.eslintrc*.cjs
*/tsconfig*.json
yarn-error.log
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 18 additions & 18 deletions data-backend/package.json → code/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@
"raw-body": "^2.5.2"
},
"devDependencies": {
"@babel/core": "7.21.5",
"@babel/eslint-parser": "7.21.3",
"@babel/core": "7.22.11",
"@babel/eslint-parser": "7.22.11",
"@typescript-eslint/eslint-plugin": "6.5.0",
"@typescript-eslint/parser": "6.5.0",
"@types/node": "18.16.3",
"@typescript-eslint/eslint-plugin": "5.59.2",
"@typescript-eslint/parser": "5.59.2",
"ava": "5.2.0",
"c8": "7.13.0",
"eslint": "8.39.0",
"eslint-config-prettier": "8.8.0",
"eslint-import-resolver-typescript": "3.5.5",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.27.5-3",
"eslint-plugin-jsdoc": "43.1.1",
"ava": "5.3.1",
"c8": "8.0.1",
"eslint": "8.48.0",
"eslint-plugin-jsdoc": "46.5.0",
"eslint-plugin-path-import-extension": "0.9.0",
"eslint-plugin-type-only-import": "0.9.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-sonarjs": "0.19.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-sonarjs": "0.21.0",
"madge": "6.1.0",
"prettier": "2.8.8",
"prettier": "3.0.2",
"ts-node": "10.9.1",
"typescript": "5.0.4"
"typescript": "5.1.6"
},
"scripts": {
"build:run": "yarn run lint && yarn run tsc",
Expand All @@ -64,17 +62,19 @@
"format-output-files": "yarn run format-output-files-ts && yarn run format-output-files-js",
"format-output-files-ts": "eslint --no-eslintrc --config '.eslintrc.out-ts.cjs' --fix --fix-type layout './dist-ts/**/*.ts'",
"format-output-files-js": "eslint --no-eslintrc --config '.eslintrc.out.cjs' --fix 'dist-cjs/**/*js' 'dist-esm/**/*js'",
"generate-stub-package-json-for-cjs": "../scripts/generate-stub-package-json.cjs",
"generate-stub-package-json-for-cjs": "../../scripts/generate-stub-package-json.cjs",
"lint": "yarn run lint:eslint && yarn run lint:circular",
"lint:circular": "madge --circular --no-color --no-spinner --extensions ts --warning ./src",
"lint:eslint": "eslint ./src --ext .ts,.tsx",
"remove-empty-js-files": "../scripts/remove-empty-js-files.cjs",
"remove-empty-js-files": "../../scripts/remove-empty-js-files.cjs",
"tsc": "tsc --project tsconfig.build.json",
"tsc:plain": "tsc",
"test:coverage": "c8 --temp-directory /tmp ava",
"test:run": "c8 --temp-directory /tmp --reporter text ava"
},
"resolutions": {
"dependency-tree": "10.0.9"
"dependency-tree": "10.0.9",
"precinct": "11.0.5",
"typescript": "5.1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const CONTENT_TYPE = "text";

export const VALIDATOR_NATIVE:
| data.MaterializeDecoder<ValidatorHKT, string>
| data.MaterializeEncoder<ValidatorHKT, string, string> = "ValidatorNative";
| data.MaterializeEncoder<ValidatorHKT, string, string> = "ValidatorNative"; // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents

/**
* This is validator to be used only for tests.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ResponseHeaderDataValidatorSpec<
export type HeaderDataValidatorSpec<
THeaderData extends
| protocol.TRequestHeadersDataBase
| protocol.TResponseHeadersDataBase,
| protocol.TResponseHeadersDataBase, // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
TValidatorHKT extends data.ValidatorHKTBase,
IsDecoder extends boolean,
> = s.StringDataValidatorSpec<
Expand Down Expand Up @@ -66,7 +66,7 @@ export type ResponseHeaderDataValidatorSpecMetadata<
export type HeaderDataValidatorSpecMetadata<
THeaderData extends
| protocol.TRequestHeadersDataBase
| protocol.TResponseHeadersDataBase,
| protocol.TResponseHeadersDataBase, // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
TValidatorHKT extends data.ValidatorHKTBase,
IsDecoder extends boolean,
> = s.StringDataValidatorSpecMetadata<
Expand Down Expand Up @@ -95,7 +95,7 @@ export type ResponseHeaderDataValidators<
export type HeaderDataValidators<
THeaderData extends
| protocol.TRequestHeadersDataBase
| protocol.TResponseHeadersDataBase,
| protocol.TResponseHeadersDataBase, // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
IsDecoder extends boolean,
> = s.StringDataValidators<
THeaderData,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ec00d19

Please sign in to comment.