From 47fd11050fe0634e3cc2872a527622dcceec4826 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 8 Sep 2021 11:43:46 +0100 Subject: [PATCH] Switch type check to GitHub Actions and add (working) type check for release mode js-sdk types --- .github/workflows/lint.yaml | 25 +++++++++++++++++++++++++ scripts/ci/js-sdk-to-release.js | 17 +++++++++++++++++ scripts/ci/js-sdk-to-release.sh | 21 --------------------- 3 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100755 scripts/ci/js-sdk-to-release.js delete mode 100755 scripts/ci/js-sdk-to-release.sh diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000000..e7f12ab65d --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,25 @@ +name: Lint +on: + pull_request: + branches: [develop] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: c-hive/gha-yarn-cache@v2 + - name: Install Deps + run: "./scripts/ci/install-deps.sh --ignore-scripts" + - name: Typecheck + run: "yarn run lint:types" + - name: Switch js-sdk to release mode + run: | + scripts/ci/js-sdk-to-release.js + pushd node_modules/matrix-js-sdk + yarn install + yarn run build:compile + yarn run build:types + popd + - name: Typecheck (release mode) + run: "yarn run lint:types" + diff --git a/scripts/ci/js-sdk-to-release.js b/scripts/ci/js-sdk-to-release.js new file mode 100755 index 0000000000..e1fecfde03 --- /dev/null +++ b/scripts/ci/js-sdk-to-release.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +const fsProm = require('fs/promises'); + +const PKGJSON = 'node_modules/matrix-js-sdk/package.json'; + +async function main() { + const pkgJson = JSON.parse(await fsProm.readFile(PKGJSON, 'utf8')); + for (const field of ['main', 'typings']) { + if (pkgJson["matrix_lib_"+field] !== undefined) { + pkgJson[field] = pkgJson["matrix_lib_"+field]; + } + } + await fsProm.writeFile(PKGJSON, JSON.stringify(pkgJson, null, 2)); +} + +main(); diff --git a/scripts/ci/js-sdk-to-release.sh b/scripts/ci/js-sdk-to-release.sh deleted file mode 100755 index a03165bd82..0000000000 --- a/scripts/ci/js-sdk-to-release.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# This changes the js-sdk into 'release mode', that is: -# * The entry point for the library is the babel-compiled lib/index.js rather than src/index.ts -# * There's a 'typings' entry referencing the types output by tsc -# We do this so we can test that each PR still builds / type checks correctly when built -# against the released js-sdk, because if you do things like `import { User } from 'matrix-js-sdk';` -# rather than `import { User } from 'matrix-js-sdk/src/models/user';` it will work fine with the -# js-sdk in development mode but then break at release time. -# We can't use the last release of the js-sdk though: it might not be up to date enough. - -cd node_modules/matrix-js-sdk -for i in main typings -do - lib_value=$(jq -r ".matrix_lib_$i" package.json) - if [ "$lib_value" != "null" ]; then - jq ".$i = .matrix_lib_$i" package.json > package.json.new && mv package.json.new package.json - fi -done -yarn run build:compile -yarn run build:types