Skip to content

Commit

Permalink
Merge pull request #136 from tchapgouv/chore/test-node-version
Browse files Browse the repository at this point in the history
Fix pipeline
  • Loading branch information
estellecomment authored Aug 29, 2022
2 parents 827e1f6 + 3469c7a commit e02ec61
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ karma-reports/
.idea/
.tmp/
config.json*
matrix-js-sdk/
matrix-react-sdk/
matrix-analytics-events/
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

- name: Install Dependencies
run: "./scripts/layered.sh"
run: "./scripts/layered.with.version.sh"

- name: Build, Package & Upload sourcemaps
run: "./scripts/ci_package.sh"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/github-script@v5
with:
# PAT needed as the GITHUB_TOKEN won't be able to see cross-references from other orgs (matrix-org)
# PAT needed as the GITHUB_TOKEN won't be able to see cross-references from other orgs (matrix-org)
github-token: ${{ secrets.ELEMENT_BOT_TOKEN }}
script: |
const variables = {
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.
File renamed without changes.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Build the application
#tchap modification : use "./scripts/layered.with.version.sh" instead of "./scripts/layered.sh"
name: Build
on:
pull_request: { }
Expand All @@ -18,9 +20,10 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

- name: Install Dependencies
run: "./scripts/layered.sh"
run: "./scripts/layered.with.version.sh"

- name: Build
run: "yarn build"
42 changes: 25 additions & 17 deletions .github/workflows/static_analysis.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Run a static analysis
#tchap modification : use "./scripts/layered.with.version.sh" instead of "./scripts/layered.sh"
name: Static Analysis
on:
pull_request: { }
Expand All @@ -19,16 +21,18 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

- name: Install Dependencies
run: "./scripts/layered.sh"
run: "./scripts/layered.with.version.sh"

- name: Typecheck
run: "yarn run lint:types"

i18n_lint:
name: "i18n Check"
uses: matrix-org/matrix-react-sdk/.github/workflows/i18n_check.yml@develop
# tchap : tchap does not use extensively i18n
# i18n_lint:
# name: "i18n Check"
# uses: matrix-org/matrix-react-sdk/.github/workflows/i18n_check.yml@develop

js_lint:
name: "ESLint"
Expand All @@ -39,6 +43,7 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

# Does not need branch matching as only analyses this layer
- name: Install Deps
Expand All @@ -56,26 +61,29 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

# Needs branch matching as it inherits .stylelintrc.js from matrix-react-sdk
- name: Install Dependencies
run: "./scripts/layered.sh"
run: "./scripts/layered.with.version.sh"

- name: Run Linter
run: "yarn run lint:style"

analyse_dead_code:
name: "Analyse Dead Code"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# tchap : analyse:unused-exports does not work well with tchap customisations, it raises exception for "default export" not used
#analyse_dead_code:
# name: "Analyse Dead Code"
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2

- uses: actions/setup-node@v3
with:
cache: 'yarn'
# - uses: actions/setup-node@v3
# with:
# cache: 'yarn'
# node-version: 14

- name: Install Deps
run: "scripts/layered.sh"
# - name: Install Deps
# run: "scripts/layered.with.version.sh"

- name: Dead Code Analysis
run: "yarn run analyse:unused-exports"
# - name: Dead Code Analysis
# run: "yarn run analyse:unused-exports"
5 changes: 4 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Run the tests
#tchap modification : use "./scripts/layered.with.version.sh" instead of "./scripts/layered.sh"
name: Tests
on:
pull_request: { }
Expand All @@ -21,9 +23,10 @@ jobs:
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 14

- name: Install Dependencies
run: "./scripts/layered.sh"
run: "./scripts/layered.with.version.sh"

- name: Run tests with coverage
run: "yarn coverage --ci"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"package.json",
"contribute.json"
],
"engines": {
"node": ">=14.19 <15"
},
"style": "bundle.css",
"scripts": {
"i18n": "matrix-gen-i18n",
Expand Down Expand Up @@ -218,5 +215,8 @@
"jestSonar": {
"reportPath": "coverage",
"sonar56x": true
},
"engines": {
"node": ">=14.19 <15"
}
}
81 changes: 81 additions & 0 deletions scripts/fetchdep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
#copied from matrix-react-sdk/scripts

set -x

deforg="$1"
defrepo="$2"
defbranch="$3"

[ -z "$defbranch" ] && defbranch="develop"

rm -r "$defrepo" || true

PR_ORG=${PR_ORG:-"matrix-org"}
PR_REPO=${PR_REPO:-"matrix-react-sdk"}

# A function that clones a branch of a repo based on the org, repo and branch
clone() {
org=$1
repo=$2
branch=$3
if [ -n "$branch" ]
then
echo "Trying to use $org/$repo#$branch"
# Disable auth prompts: https://serverfault.com/a/665959
GIT_TERMINAL_PROMPT=0 git clone https://github.com/$org/$repo.git $repo --branch "$branch" --depth 1 && exit 0
fi
}

# A function that gets info about a PR from the GitHub API based on its number
getPRInfo() {
number=$1
if [ -n "$number" ]; then
echo "Getting info about a PR with number $number"

apiEndpoint="https://api.github.com/repos/$PR_ORG/$PR_REPO/pulls/$number"

head=$(curl $apiEndpoint | jq -r '.head.label')
fi
}

# Some CIs don't give us enough info, so we just get the PR number and ask the
# GH API for more info - "fork:branch". Some give us this directly.
if [ -n "$BUILDKITE_BRANCH" ]; then
# BuildKite
head=$BUILDKITE_BRANCH
elif [ -n "$PR_NUMBER" ]; then
# GitHub
getPRInfo $PR_NUMBER
elif [ -n "$REVIEW_ID" ]; then
# Netlify
getPRInfo $REVIEW_ID
fi

# for forks, $head will be in the format "fork:branch", so we split it by ":"
# into an array. On non-forks, this has the effect of splitting into a single
# element array given ":" shouldn't appear in the head - it'll just be the
# branch name. Based on the results, we clone.
BRANCH_ARRAY=(${head//:/ })
TRY_ORG=$deforg
TRY_BRANCH=${BRANCH_ARRAY[0]}
if [[ "$head" == *":"* ]]; then
# ... but only match that fork if it's a real fork
if [ "${BRANCH_ARRAY[0]}" != "$PR_ORG" ]; then
TRY_ORG=${BRANCH_ARRAY[0]}
fi
TRY_BRANCH=${BRANCH_ARRAY[1]}
fi
clone ${TRY_ORG} $defrepo ${TRY_BRANCH}

# Try the target branch of the push or PR.
if [ -n "$GITHUB_BASE_REF" ]; then
clone $deforg $defrepo $GITHUB_BASE_REF
elif [ -n "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" ]; then
clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH
fi

# Try HEAD which is the branch name in Netlify (not BRANCH which is pull/xxxx/head for PR builds)
clone $deforg $defrepo $HEAD
# Use the default branch as the last resort.
clone $deforg $defrepo $defbranch
54 changes: 54 additions & 0 deletions scripts/layered.with.version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
#inspired from ./layered.sh
set -x

# Creates a layered environment with the full repo for the app and SDKs cloned
# and linked. This gives an tchap-web dev environment ready to build with
# matching branches of react-sdk's dependencies so that changes can be tested
# in tchap-web.

# Note that this style is different from the recommended developer setup: this
# file nests js-sdk and matrix-react-sdk inside element-web, while the local
# development setup places them all at the same level. We are nesting them here
# because some CI systems do not allow moving to a directory above the checkout
# for the primary repo (element-web in this case).

# Install dependencies, as we'll be using fetchdep.sh from matrix-react-sdk
yarn install --pure-lockfile

# Pass appropriate repo to fetchdep.sh (not needed for tchap-web)
#export PR_ORG=vector-im
#export PR_REPO=element-web

#tchap added : grep matrix dependencies version from package.json
export MATRIX_JS_SDK_VERSION=$(awk -F \" '/"matrix-js-sdk": ".+"/ { print $4; exit; }' package.json)
export MATRIX_REACT_SDK_VERSION=$(awk -F \" '/"matrix-react-sdk": ".+"/ { print $4; exit; }' package.json)

# Set up the js-sdk first
./scripts/fetchdep.sh matrix-org matrix-js-sdk v$MATRIX_JS_SDK_VERSION
pushd matrix-js-sdk
yarn link
yarn install --pure-lockfile
popd

# Also set up matrix-analytics-events so we get the latest from
# the main branch or a branch with matching name
./scripts/fetchdep.sh matrix-org matrix-analytics-events main
pushd matrix-analytics-events
yarn link
yarn install --pure-lockfile
yarn build:ts
popd

# Now set up the react-sdk
./scripts/fetchdep.sh matrix-org matrix-react-sdk v$MATRIX_REACT_SDK_VERSION
pushd matrix-react-sdk
yarn link
yarn link matrix-js-sdk
yarn link @matrix-org/analytics-events
yarn install --pure-lockfile
popd

# Link the layers into element-web
yarn link matrix-js-sdk
yarn link matrix-react-sdk

0 comments on commit e02ec61

Please sign in to comment.