Skip to content

Commit

Permalink
feat(publishing): Auto publish repository to npm in CI [SIM-123] (Set…
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Mar 21, 2022
1 parent f5758d2 commit 8ddbbf1
Show file tree
Hide file tree
Showing 13 changed files with 2,615 additions and 134 deletions.
84 changes: 49 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
version: 2
version: 2.1

default_env: &default_env
working_directory: ~/set-protocol-v2
docker:
- image: circleci/node:14.18
environment:
NODE_OPTIONS: --max_old_space_size=8192

commands:
setup_job:
steps:
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}

jobs:
checkout_and_compile:
docker:
- image: circleci/node:12.16.0
environment:
NODE_OPTIONS: --max_old_space_size=8192
<<: *default_env
resource_class: large
working_directory: ~/set-protocol-v2
steps:
- checkout
- restore_cache:
Expand All @@ -30,16 +39,10 @@ jobs:
paths:
- ~/set-protocol-v2
test:
docker:
- image: circleci/node:12.16.0
working_directory: ~/set-protocol-v2
<<: *default_env
parallelism: 3
steps:
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Set Up Environment Variables
command: cp .env.default .env
- setup_job
- run:
name: Test RPC
command: yarn chain
Expand All @@ -51,35 +54,23 @@ jobs:
yarn test ${TEST_FILES}
test_forked_network:
docker:
- image: circleci/node:12.16.0
working_directory: ~/set-protocol-v2
<<: *default_env
steps:
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Set Up Environment Variables
command: cp .env.default .env
- setup_job
- run:
name: Hardhat Test
command: yarn test:fork

coverage:
docker:
- image: circleci/node:12.16.0
working_directory: ~/set-protocol-v2
<<: *default_env
# When changing the parallelism value, you also
# need to update the `persist_to_workspace` paths
# in this job (below) as well as the list of files passed
# to istanbul-combine in the `report_coverage` job
parallelism: 5
resource_class: medium+
steps:
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Set Up Environment Variables
command: cp .env.default .env
- setup_job
- run:
name: Create shared coverage outputs folder
command: mkdir -p /tmp/coverage
Expand All @@ -104,14 +95,11 @@ jobs:
- cov_4.json

report_coverage:
docker:
- image: circleci/node:12.16.0
working_directory: ~/set-protocol-v2
<<: *default_env
steps:
- setup_job
- attach_workspace:
at: /tmp/coverage
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Combine coverage reports
command: |
Expand All @@ -127,6 +115,22 @@ jobs:
command: |
cat coverage/lcov.info | node_modules/.bin/coveralls
release_latest:
<<: *default_env
steps:
- setup_job
- run:
name: Publish "latest" release
command: yarn publish:ci:latest

release_hardhat:
<<: *default_env
steps:
- setup_job
- run:
name: Publish "hardhat" release
command: yarn publish:ci:hardhat

workflows:
version: 2
build-and-test:
Expand All @@ -144,3 +148,13 @@ workflows:
- report_coverage:
requires:
- coverage

# Publish `hardhat` before `latest` second so that repo's package version is set correctly on exit
- release_hardhat:
requires:
- checkout_and_compile
- release_latest:
requires:
- release_hardhat


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
coverage.json
coverage/
.env
.releaserc.json

/.coverage_cache
/.coverage_contracts
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ perpSetup = getPerpV2Fixture(...);
[22]: https://www.npmjs.com/package/hardhat
[23]: https://www.npmjs.com/package/typechain

## Semantic Release

This repository uses [semantic-release][10] to automatically publish in CI on merge to master. To trigger
a release, use the following naming convention in your PR description (or in your squash & merge commit
description):

+ patch release (e.g 1.0.1 -> 1.0.2): `fix(topic): description`
+ example: `fix(perpV2Viewer): return uint256 instead of int256`
+ feature release (e.g 1.1.0 -> 1.2.0): `feat(feature_name): description`
+ example: `feat(PerpV2BasisTrading): Add PerpV2 Basis Trading Module`


## Contributing
We highly encourage participation from the community to help shape the development of Set. If you are interested in developing on top of Set Protocol or have any questions, please ping us on [Discord](https://discord.gg/ZWY66aR).

Expand Down Expand Up @@ -116,3 +128,5 @@ If you follow these guidelines when reporting an issue to us, we commit to:
(including an initial confirmation of your report within 72 hours of submission).

* Grant a monetary reward based on the OWASP risk assessment methodology.

[10]: https://semantic-release.gitbook.io/semantic-release/v/beta/
1 change: 1 addition & 0 deletions contracts/lib/AddressArrayUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
Expand Down
41 changes: 28 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.1.16",
"description": "",
"main": "dist",
"types": "dist/types",
"files": [
"artifacts",
"dist",
Expand All @@ -15,13 +14,15 @@
"tsconfig.json"
],
"scripts": {
"build": "yarn clean && yarn compile && yarn build:typechain",
"build:npm": "yarn clean && yarn compile:npm && yarn build:typechain",
"build:typechain": "yarn typechain && yarn transpile-dist",
"build": "yarn clean && yarn compile && yarn build:ts:latest",
"build:npm:latest": "yarn clean && yarn compile:latest && yarn build:ts:latest",
"build:npm:hardhat": "yarn clean && yarn compile && yarn build:ts:hardhat",
"build:ts:latest": "yarn typechain && yarn transpile:dist:latest",
"build:ts:hardhat": "yarn typechain && yarn transpile:dist:hardhat",
"chain": "npx hardhat node",
"clean": "rm -rf coverage.json .coverage_cache .coverage_contracts cache coverage typechain artifacts dist",
"clean": "./scripts/clean.sh",
"compile": "npx hardhat compile",
"compile:npm": "SKIP_ABI_GAS_MODS=true npx hardhat compile",
"compile:latest": "SKIP_ABI_GAS_MODS=true npx hardhat compile",
"coverage": "yarn clean && yarn build && yarn cov:command",
"cov:command": "COVERAGE=true node --max-old-space-size=4096 ./node_modules/.bin/hardhat coverage",
"etherscan:verify": "hardhat --network kovan etherscan-verify --solc-input --license 'None'",
Expand All @@ -31,31 +32,44 @@
"lint-ts": "eslint -c .eslintrc.js --ext .ts test utils tasks --fix",
"precommit": "lint-staged",
"prepare": "yarn build",
"prepublishOnly": "yarn clean && yarn build:npm",
"prepublishOnly": "./scripts/prepublish_only.sh",
"publish:local:latest": "npm run publish",
"publish:local:hardhat": "PUBLISH_HARDHAT=true npm run publish",
"publish:ci:latest": "./scripts/release_latest.sh",
"publish:ci:hardhat": "./scripts/release_hardhat.sh",
"test": "npx hardhat test --network localhost",
"test:fork": "FORK=true npx hardhat test",
"test:fork:fast": "NO_COMPILE=true TS_NODE_TRANSPILE_ONLY=1 FORK=true npx hardhat test --no-compile",
"test:clean": "yarn clean && yarn build && yarn test",
"test:fast": "NO_COMPILE=true TS_NODE_TRANSPILE_ONLY=1 npx hardhat test --network localhost --no-compile",
"test:fast:compile": "TS_NODE_TRANSPILE_ONLY=1 npx hardhat test --network localhost",
"transpile": "tsc",
"transpile-dist": "tsc -p tsconfig.dist.json",
"typechain": "npx hardhat typechain"
"transpile:dist:latest": "tsc --project tsconfig.dist.json",
"transpile:dist:hardhat": "tsc --project tsconfig.hardhat.json",
"typechain": "npx hardhat typechain",
"semantic-release": "semantic-release"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SetProtocol/set-protocol-v2-contracts.git"
"url": "https://github.com/SetProtocol/set-protocol-v2.git"
},
"author": "felix2feng",
"license": "MIT",
"homepage": "https://github.com/SetProtocol",
"resolutions": {
"babel-code-frame/chalk": "4.1.0"
},
"engines": {
"yarn": ">=1.10.1"
},
"devDependencies": {
"@0x/utils": "^6.4.3",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^3.1.0",
"@typechain/ethers-v5": "^7.0.1",
"@typechain/hardhat": "^2.3.0",
"@semantic-release/git": "^10.0.1",
"@typechain/ethers-v5": "8.0.5",
"@typechain/hardhat": "3.1.0",
"@types/chai": "^4.2.11",
"@types/fs-extra": "^5.0.0",
"@types/lodash": "^4.14.86",
Expand All @@ -78,14 +92,15 @@
"istanbul-combine-updated": "^0.3.0",
"lint-staged": "^10.2.11",
"lodash": "^4.17.4",
"semantic-release": "^19.0.2",
"solc": "^0.6.10",
"solhint": "^3.1.0",
"solidity-coverage": "^0.7.17",
"ts-generator": "^0.1.1",
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"tslint-eslint-rules": "^5.3.1",
"typechain": "5.1.2",
"typechain": "6.1.0",
"typescript": "^4.4.3",
"web3": "^1.2.9"
},
Expand Down
12 changes: 12 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -o errexit

rm -f coverage.json
rm -rf .coverage_cache
rm -rf .coverage_contracts
rm -rf cache
rm -rf coverage
rm -rf typechain
rm -rf artifacts
rm -rf dist
20 changes: 20 additions & 0 deletions scripts/prepublish_only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Run in the `prepublishOnly npm hook`. We publish a specially built version
# of the repo to the @hardhat tag which includes hardcoded gas values in the hardhat
# artifact abis and deposits type definitions alongside the js files in the dist.
# This build is necessary for Perp fixtures to run correctly at set-v2-strategies
set -o errexit

echo "Running prepublishOnly npm hook"
echo "PUBLISH_HARDHAT = $PUBLISH_HARDHAT"

# This hook is skipped when publishing in CI because semantic-release is discarding TS products of
# npm lifecycle hooks. In CI we re-write the tsconfig on the fly to generate the correct outputs.
if [[ -v CI ]]; then
exit 0
elif [[ -v PUBLISH_HARDHAT ]]; then
yarn build:npm:hardhat
else
yarn build:npm:latest
fi
23 changes: 23 additions & 0 deletions scripts/release_hardhat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -o errexit

# Auto-publishes a specially built release to the @hardhat tag using version schema `x.x.x-hardhat.1`
# which can be installed with `yarn add @setprotocol/set-protocol-v2@hardhat`
# See scripts/prepublish_only.sh for details about this build.
#
# The `release_default...` branch config here is necessary to trick the semantic-release tool into publishing
# latest and hardhat builds from `master`. These are handled by separate jobs in CI (see circleci/config.yml)
echo '{
"branches": [
{ "name": "release_default_do_not_delete" },
{ "name": "master", "channel": "hardhat", "prerelease": "hhat"}
]
}' > .releaserc.json

# `semantic-release` discards any dist changes generated by npm lifecycle hooks so we need to copy the custom
# config into the default config to produce correct build. This change *IS NOT* committed to the repo and
# this script does not update the package.json version.
cp tsconfig.hardhat.json tsconfig.json

npx semantic-release --debug
23 changes: 23 additions & 0 deletions scripts/release_latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -o errexit

# Auto-publishes `latest` from master, updates package version on github
# Version format is `x.x.x` and installs with `yarn add @setprotocol/set-protocol-v2`
# `package.json` version field is updated and pushed to Github
echo '{
"branches": [
{ "name": "master" }
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/git"
]
}' > .releaserc.json

# Regenerate artifacts to strip out hardcoded gas values in artifact ABIs
yarn build:npm:latest

npx semantic-release --debug
2 changes: 2 additions & 0 deletions semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
titleOnly: true

29 changes: 29 additions & 0 deletions tsconfig.hardhat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"strictPropertyInitialization": false,
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"baseUrl": ".",
"moduleResolution": "node",
"paths": {
"@utils/*": ["utils/*"],
"@typechain/*": ["typechain/*"]
}
},
"include": [
"./utils/**/*.ts",
"./deploy/**/*.ts",
"./typechain/**/*.ts",
"./tasks/**/*.ts"
],
"files": [
"hardhat.config.ts",
]
}
Loading

0 comments on commit 8ddbbf1

Please sign in to comment.