Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: e2e + 3rd party-lib watcher #388

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6cf5b99
ci: add an action that checks for version
nicolasbrugneaux Oct 9, 2024
1e95416
ci: fix if first run
nicolasbrugneaux Oct 9, 2024
4e3104e
ci: fix syntax
nicolasbrugneaux Oct 9, 2024
2309604
ci: fix fetching
nicolasbrugneaux Oct 9, 2024
91a7050
ci: more info
nicolasbrugneaux Oct 9, 2024
93cb53b
ci: names
nicolasbrugneaux Oct 9, 2024
8d0290e
feat: add e2e tests
nicolasbrugneaux Oct 16, 2024
8ef00d2
feat: trigger action from cron
nicolasbrugneaux Oct 16, 2024
cbca23d
Merge branch 'master' into nicolasbrugneaux/ci-watcher
nicolasbrugneaux Oct 17, 2024
8b754f9
fix: typo
nicolasbrugneaux Oct 17, 2024
c50721b
fix: branch for testing
nicolasbrugneaux Oct 17, 2024
6cd8140
fix: change script name
nicolasbrugneaux Oct 17, 2024
58f68ea
fix: path
nicolasbrugneaux Oct 17, 2024
534b941
refactor: action->workflow
nicolasbrugneaux Oct 17, 2024
bd1d4f7
fix: workflow->action
nicolasbrugneaux Oct 17, 2024
4108ef0
fix: shell
nicolasbrugneaux Oct 17, 2024
c0f4419
fix: cache
nicolasbrugneaux Oct 17, 2024
29f179e
fix: inputs
nicolasbrugneaux Oct 17, 2024
e1cbe8b
fix: inputs
nicolasbrugneaux Oct 17, 2024
63e5424
feat: access repo secrets
nicolasbrugneaux Oct 17, 2024
72a1fed
fix: secrets isn't available in composite actions
nicolasbrugneaux Oct 17, 2024
6f8b223
fix: ethers nonce
nicolasbrugneaux Oct 17, 2024
9e3c0cd
fix: typo
nicolasbrugneaux Oct 17, 2024
d7dbec4
fix: cache
nicolasbrugneaux Oct 17, 2024
1e0caac
feat: network as action input
nicolasbrugneaux Oct 18, 2024
f68a029
fix: eaccess permission error
nicolasbrugneaux Oct 18, 2024
e654176
fix: path
nicolasbrugneaux Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": [],
"ignore": [
"@celo/e2e"
],
"snapshot": {
"useCalculatedVersion": true,
"prereleaseTemplate": "{tag}-{commit}"
Expand Down
59 changes: 59 additions & 0 deletions .github/actions/third-party-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 'Test a third party library'
inputs:
lib:
type: string
required: true
version:
type: string
default: 'latest'
network:
type: string
required: true

runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
with:
node-version: '18'
- name: 'enable corepack for yarn'
run: sudo corepack enable yarn
shell: bash --login -eo pipefail {0}

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
- name: Restore node cache
uses: actions/cache@v4
id: cache_node
with:
# We need to cache all the artifacts generated by yarn install+build
# Update this list also in .github/actions/sync-workspace/action.yml with exactly the same list
path: |
./.yarn/cache
./.yarn/install-state.gz
node_modules
packages/**/node_modules
key: node-${{ runner.os }}-${{ runner.arch }}-${{ env.NODE_MODULE_CACHE_VERSION }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
node-${{ runner.os }}-${{ runner.arch }}-${{ env.NODE_MODULE_CACHE_VERSION }}-
- name: Install yarn dependencies
run: git config --global url."https://".insteadOf ssh:// && yarn install
shell: bash --login -eo pipefail {0}
if: steps.cache_node.outputs.cache-hit != 'true'
- name: Run yarn postinstall if cache hitted
run: yarn run postinstall
shell: bash --login -eo pipefail {0}
if: steps.cache_node.outputs.cache-hit == 'true'

- run: |
cd packages/e2e
yarn
yarn add ${{ inputs.lib }}@${{ inputs.version }}
yarn run test-e2e:${{ inputs.lib }}
shell: bash --login -eo pipefail {0}
env:
TEST_ACCOUNT: ${{ env.TEST_ACCOUNT }}
NETWORK: ${{ inputs.network }}
100 changes: 100 additions & 0 deletions .github/workflows/cron-third-party.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Third party libraries testing workflow
# By default the sha where it runs is latest commit on default branch
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
on:
schedule:
# hourly
- cron: 0 * * * *
workflow_dispatch:
pull_request:

jobs:
compare-versions:
name: check if new version of ${{ matrix.lib }} is out
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lib:
- 'viem'
- 'web3'
- 'ethers'

steps:
- uses: actions/checkout@v4
with:
# TODO: REMOVE THIS
ref: nicolasbrugneaux/ci-watcher
sparse-checkout: |
.github
- uses: actions/download-artifact@v4
name: Download last version tested
with:
name: cache-last-version-${{ matrix.lib }}
path: ${{ github.workspace }}/
continue-on-error: true

- uses: actions/setup-node@v4
name: Setup NPM

- id: npm-version
name: Fetch latest available version from NPM
run: |
echo "result=$(npm info ${{ matrix.lib }} --json | jq -r ".version")" >> "$GITHUB_OUTPUT"

- name: Install semver-tool
run: |
# https://github.com/fsaintjacques/semver-tool
# Download the script and save it to /usr/local/bin
wget -O /usr/local/bin/semver \
https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver

# Make script executable
chmod +x /usr/local/bin/semver

# Prove it works
semver --version

- id: compare-version
name: Compare last version with NPM's version
run: |
LAST_VERSION=$(cat ${{ github.workspace }}/cache-last-version-${{ matrix.lib }}2>/dev/null || echo '0.0.0')
FETCHED_VERSION="${{ steps.npm-version.outputs.result }}"

echo "Validating last version: $LAST_VERSION ..."
semver validate $LAST_VERSION

echo "Validating fetched version: $FETCHED_VERSION ..."
semver validate $FETCHED_VERSION

echo "result=$(semver compare $LAST_VERSION $FETCHED_VERSION)" >> "$GITHUB_OUTPUT"

- run: ls -lA .

- id: trigger-tests
name: Trigger tests if NPM's version was higher than tested version
if: ${{ steps.compare-version.outputs.result }} == -1
uses: ./.github/actions/third-party-tests
with:
lib: ${{ matrix.lib }}
version: ${{ steps.npm-version.outputs.result }}
network: alfajores
env:
# Increment these to force cache rebuilding
NODE_MODULE_CACHE_VERSION: 5
NODE_OPTIONS: '--max-old-space-size=4096'
TERM: dumb
TEST_ACCOUNT: ${{ secrets.TEST_ACCOUNT }}

- id: save-version
name: Save the tested version
run: |
echo $VERSION_TO_SAVE >> ${{ github.workspace }}/cache-last-version-${{ matrix.lib }}
env:
VERSION_TO_SAVE: ${{ steps.npm-version.outputs.result }}

- uses: actions/upload-artifact@v4
name: Upload version
with:
name: cache-last-version-${{ matrix.lib }}
path: ${{ github.workspace }}/cache-last-version-${{ matrix.lib }}
34 changes: 34 additions & 0 deletions .github/workflows/third-party-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Trigger manually third party libraries testing workflow
on:
workflow_dispatch:
inputs:
lib:
type: choice
options:
- viem
- web3
- ethers
version:
type: string
default: 'latest'
description: Version to test again or 'latest'
network:
type: string
default: alfajores

jobs:
third-party-test-workflow:
runs-on: ['self-hosted', 'org', '8-cpu']
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/third-party-tests
with:
lib: ${{ inputs.lib }}
version: ${{ inputs.version }}
network: ${{ inputs.network }}
env:
# Increment these to force cache rebuilding
NODE_MODULE_CACHE_VERSION: 5
NODE_OPTIONS: '--max-old-space-size=4096'
TERM: dumb
TEST_ACCOUNT: ${{ secrets.TEST_ACCOUNT }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"reset-rn": "watchman watch-del-all; rm -rf $TMPDIR/metro-cache-*; rm -rf $TMPDIR/haste-map-*; rm -rf $TMPDIR/metro-symbolicate*",
"reset-yarn": "yarn cache clean",
"test": "yarn test-pure && yarn test-needing-ganache",
"test-pure": "yarn workspaces foreach -piv --all --exclude celo --exclude \"@celo/{celocli,contractkit,transactions-uri}\" run test",
"test-pure": "yarn workspaces foreach -piv --all --exclude celo --exclude \"@celo/{celocli,contractkit,transactions-uri,e2e}\" run test",
"test-needing-ganache": "yarn workspace @celo/contractkit test && yarn workspace @celo/celocli test && yarn workspace @celo/transactions-uri test",
"build": "yarn workspaces foreach -piv --all --topological-dev run build",
"clean": "yarn workspaces foreach -piv --all run clean",
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_ACCOUNT="0x123..."
NETWORK="alfajores"
3 changes: 3 additions & 0 deletions packages/e2e/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '../../.eslintrc.js',
}
4 changes: 4 additions & 0 deletions packages/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
tmp/
.tmp/
.env
16 changes: 16 additions & 0 deletions packages/e2e/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/.devchain/
/.devchain.tar.gz
/coverage/
/node_modules/
/src/
/tmp/
/.tmp/

/tsconfig.*
/jest.config.*
*.tgz

/src

/lib/**/*.test.*
/lib/test-utils
Empty file added packages/e2e/CHANGELOG.md
Empty file.
3 changes: 3 additions & 0 deletions packages/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @celo/e2e

TODO
4 changes: 4 additions & 0 deletions packages/e2e/eslint.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
}
35 changes: 35 additions & 0 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@celo/e2e",
"version": "0.0.1",
"description": "TODO",
"types": "./lib/index.d.ts",
"author": "cLabs",
"license": "Apache-2.0",
"homepage": "https://docs.celo.org/developer/tools",
"repository": "https://github.com/celo-org/developer-tooling/tree/master/packages/e2e",
"keywords": [],
"type": "module",
"exports": {
".": "./lib/index.js"
},
"scripts": {
"test-e2e": "yarn run vitest",
"test-e2e:viem": "yarn run vitest viem",
"test-e2e:ethers": "yarn run vitest ethers",
"test-e2e:web3": "yarn run vitest web3"
},
"dependencies": {
"@celo/abis": "^11.0.0",
"@celo/typescript": "workspace:^",
"@celo/web3-plugin-transaction-types": "^1.0.2",
"@vitest/coverage-v8": "2.1.2",
"dotenv": "^8.2.0",
"ethers": "^6.13.4",
"viem": "^2.21.27",
"vitest": "^2.1.2",
"web3": "^4.13.0"
},
"engines": {
"node": ">=18"
}
}
53 changes: 53 additions & 0 deletions packages/e2e/tests/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { createPublicClient, extractChain, Hex, http } from 'viem'
import { celo, celoAlfajores } from 'viem/chains'

export const celoBaklava = {
...celoAlfajores,
id: 62_320,
name: 'Baklava',
nativeCurrency: {
decimals: 18,
name: 'CELO',
symbol: 'B-CELO',
},
rpcUrls: {
default: {
http: ['https://baklava-forno.celo-testnet.org'],
},
},
blockExplorers: {
default: {
name: 'Celo Baklava Explorer',
url: 'https://celo-baklava.blockscout.com/',
apiUrl: 'https://celo-baklava.blockscout.com/api',
},
},
}

export const TEST_PRIVATE_KEY = process.env.TEST_ACCOUNT as Hex

const network = (process.env.NETWORK as string).toLowerCase()
let RPC_URL: string
if (network === 'celo' || network === 'mainnet') {
RPC_URL = celo.rpcUrls.default.http[0]
} else if (network === 'alfajores') {
RPC_URL = celoAlfajores.rpcUrls.default.http[0]
} else if (network === 'baklava') {
RPC_URL = celoBaklava.rpcUrls.default.http[0]
} else {
throw new Error(
`Unrecognized network ${network}. Valid networks are celo, mainnet, alfajores, baklava`
)
}

const transport = http(RPC_URL)
const intermediateClient = createPublicClient({
transport,
})
export const CHAIN = extractChain({
chains: [celo, celoAlfajores, celoBaklava],
id: (await intermediateClient.getChainId()) as
| typeof celo.id
| typeof celoAlfajores.id
| typeof celoBaklava.id,
})
Loading
Loading