Skip to content

Commit

Permalink
Merge pull request #25 from ty-ras/issue/24-streamline-code
Browse files Browse the repository at this point in the history
Issue/24 streamline code
  • Loading branch information
stazz committed Sep 9, 2023
2 parents ec8c0c7 + 08c0cba commit bb1f001
Show file tree
Hide file tree
Showing 34 changed files with 1,112 additions and 932 deletions.
29 changes: 0 additions & 29 deletions .codecov.yml

This file was deleted.

117 changes: 105 additions & 12 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: [ client ]
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,21 +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.
- 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
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
node_modules
.vscode
build
dist*
coverage
.yarn
*/.eslintrc*.cjs
*/tsconfig*.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ 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 library which implements typesafe HTTP invocation API of [`@ty-ras/data-frontent`](https://github.com/ty-ras/data) using [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
- [`@ty-ras/client-fetch`](./client) contains code for creating callbacks implementing `CallHTTPEndpoint` using the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
- [`@ty-ras/client-fetch`](./code/client) contains code for creating callbacks implementing `CallHTTPEndpoint` using the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
28 changes: 0 additions & 28 deletions client/src/__test__/errors.spec.ts

This file was deleted.

0 comments on commit bb1f001

Please sign in to comment.