Skip to content

Commit

Permalink
Add CI (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-bubu authored Nov 15, 2024
1 parent eb66401 commit a49a933
Show file tree
Hide file tree
Showing 24 changed files with 2,216 additions and 2,895 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

29 changes: 0 additions & 29 deletions .eslintrc.json

This file was deleted.

76 changes: 76 additions & 0 deletions .github/workflows/publish-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Publish on tag
on:
pull_request:
push:
tags: [v*]
workflow_dispatch:

env:
HTTPS_REMOTE: "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"

jobs:
publish:
name: Publish Release
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Dependencies
run: npm i
- name: Set up version
run: |
# Extract package name and version
NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "//registry.npmjs.org/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" > .npmrc
- name: publish-stream
run: |
npm i
npm run build
# Publish to NPM registry
npm publish --access public
bump-version:
needs: [publish]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
name: Bump SDK Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: "main"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install tools
run: npm i -g semver
- name: Configure Git
run: |
git config --global user.name "galachain-release-bot"
git config --global user.email "[email protected]"
- name: Set a new version
run: |
VERSION="$(semver "$(< package.json jq -r '.version')" -i)"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Create a new branch
run: |
BRANCH_NAME="bump-version-to-$VERSION"
git checkout -b $BRANCH_NAME main
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Bump version and commit changes
run: |
npm version $VERSION
npm i
git commit -am "Bump version to $VERSION"
git push --set-upstream origin bump-version-to-$VERSION
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
run: gh pr create --title "Bump Version to $VERSION" --body "Bump Version to $VERSION" --label "bump-version-pr" --head "bump-version-to-$VERSION" --base main
71 changes: 71 additions & 0 deletions .github/workflows/test-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Test on push
on:
push:
tags: [v*]
pull_request:
workflow_dispatch:

jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Verify copyright
run: ./verify_copyright.sh
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm i
- name: Build
run: npm run build
- name: Lint
run: npm run lint

e2e-ci:
name: Run e2e test
runs-on: ubuntu-latest
needs: [ci]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.20.5
- name: Cache Docker images
uses: ScribeMD/[email protected]
with:
key: docker-${{ runner.os }}-${{ github.ref_name }}
- name: Install local CLI
run: npm install -g @gala-chain/cli
- name: Create test project
run: galachain init ./test-chaincode
- name: Install dependencies
run: |
unset npm_config_prefix
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 18.20.5
npm i
npm i --prefix ./test-chaincode
(cd test-chaincode && npm run network:up && cd ..)
- name: Run e2e tests
run: npm run test:e2e --prefix ./test-chaincode
- name: Stream blocks from the network
run:
timeout 15s npx ts-node src/sample.ts || true
- name: Test
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 22
npm run build
npm run test
- name: Clean-up
run: (cd test-chaincode && npm run network:prune)
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
22
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ galachain init test-chaincode

**Step 4**: Run the e2e tests for the chaincode to populate the network with some data
```bash
npm run test:e2e --prefix test-chaincode
(cd .. && npm run test:e2e --prefix test-chaincode)
```

**Step 5**: Stream blocks or transactions from the network
Expand Down
57 changes: 57 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) Gala Games Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import js from "@eslint/js";
import * as tsPlugin from "@typescript-eslint/eslint-plugin";
import * as tsParser from "@typescript-eslint/parser";
import prettierPlugin from "eslint-plugin-prettier";
import globals from "globals";

export default [
{
ignores: ["lib/*", "node_modules/*", "src/cli.ts", "**/*.d.ts"]
},
{
files: ["*.js", "*.jsx", "*.ts", "*.tsx"],
languageOptions: {
parser: tsParser,
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.es2021,
...globals.node
}
},
plugins: {
"@typescript-eslint": tsPlugin,
prettier: prettierPlugin
},
rules: {
...js.configs.recommended.rules,
...tsPlugin.configs["eslint-recommended"].overrides[0].rules,
...tsPlugin.configs.recommended.rules,
...prettierPlugin.configs.recommended.rules,
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": "warn"
}
},
{
files: ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
languageOptions: {
globals: {
...globals.jest
}
}
}
];
Loading

0 comments on commit a49a933

Please sign in to comment.