Skip to content

Commit

Permalink
Merge pull request #5 from lsd-ucsc/add-github-actions
Browse files Browse the repository at this point in the history
- Added unit test actions
- Added create release actions
  • Loading branch information
zhenghaven authored May 22, 2023
2 parents 1ff2ffe + 84284f7 commit 70bfcd6
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 54 deletions.
302 changes: 302 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
name: Create release

on:
push:
branches: [ main ]
tags:
- "v*.*.*"
pull_request:
branches: [ main ]

jobs:
create_release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04 ]

python-version: [ 3.11 ]
node-version: [ 18.16.0 ]

ganache-version: [ 7.8.0 ]

solc-version: [ v0.8.20 ]

env:
SOLC_BIN: ${{ github.workspace }}/build/solc-static-linux
SOLC_FLAGS: >-
--optimize --optimize-runs 200
--revert-strings strip
--via-ir
--overwrite
--base-path ${{ github.workspace }}
--output-dir ${{ github.workspace }}/build/
SOLC_VER_CMD: >-
${{ github.workspace }}/build/solc-static-linux
--version | tail -n 1 | sed -e "s/^Version: //g"
RELE_NOTE: ${{ github.workspace }}/build/release_note.md
DECENT_PUBSUB_VER: v0.1.6
DECENT_RA_VER: v0.0.1

name: A job to create a release
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ACCESS_APP_TOKEN }}
submodules: recursive

- name: Installing Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Installing Python packages
run: |
python3 -m pip install --requirement ${{ github.workspace }}/utils/gas_cost_eval_requirements.txt
- name: Installing GitHubApiHelper
run: |
python3 -m pip install git+https://github.com/zhenghaven/[email protected]
- name: Installing Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Installing NPM packages
run: |
npm install -g ganache@${{ matrix.ganache-version }}
- name: Installing Solc compiler
run: |
mkdir -p ${{ github.workspace }}/build/
curl -fsSL -o ${SOLC_BIN} \
https://github.com/ethereum/solidity/releases/download/${{ matrix.solc-version }}/solc-static-linux
chmod +x ${SOLC_BIN}
- name: Compiling contracts for DecentRevoker/RevokerByVoting.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/DecentRevoker/RevokerByVoting.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/DecentRevoker/RevokerByVoting.sol
- name: Compiling contracts for DecentRevoker/RevokerByConflictMsg.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/DecentRevoker/RevokerByConflictMsg.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/DecentRevoker/RevokerByConflictMsg.sol
- name: Compiling contracts for DecentRevoker/RevokerByLeakedKey.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/DecentRevoker/RevokerByLeakedKey.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/DecentRevoker/RevokerByLeakedKey.sol
- name: Compiling contracts for KeyRevoker/KeyRevokerByVoting.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/KeyRevoker/KeyRevokerByVoting.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/KeyRevoker/KeyRevokerByVoting.sol
- name: Compiling contracts for KeyRevoker/KeyRevokerByConflictMsg.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/KeyRevoker/KeyRevokerByConflictMsg.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/KeyRevoker/KeyRevokerByConflictMsg.sol
- name: Compiling contracts for KeyRevoker/KeyRevokerByLeakedKey.sol
run: |
${SOLC_BIN} ${SOLC_FLAGS} --bin ${{ github.workspace }}/KeyRevoker/KeyRevokerByLeakedKey.sol
${SOLC_BIN} ${SOLC_FLAGS} --abi ${{ github.workspace }}/KeyRevoker/KeyRevokerByLeakedKey.sol
- name: Calculating checksums of the binary
working-directory: ${{ github.workspace }}/build
run: |
sha256sum solc-static-linux >> checksums.txt
sha256sum RevokerByVoting.bin >> checksums.txt
sha256sum RevokerByVoting.abi >> checksums.txt
sha256sum RevokerByConflictMsg.bin >> checksums.txt
sha256sum RevokerByConflictMsg.abi >> checksums.txt
sha256sum RevokerByLeakedKey.bin >> checksums.txt
sha256sum RevokerByLeakedKey.abi >> checksums.txt
sha256sum KeyRevokerByVoting.bin >> checksums.txt
sha256sum KeyRevokerByVoting.abi >> checksums.txt
sha256sum KeyRevokerByConflictMsg.abi >> checksums.txt
sha256sum KeyRevokerByConflictMsg.abi >> checksums.txt
sha256sum KeyRevokerByLeakedKey.abi >> checksums.txt
sha256sum KeyRevokerByLeakedKey.abi >> checksums.txt
- name: Prepare binaries for gas cost evaluation
working-directory: ${{ github.workspace }}/build
run: |
mkdir -p DecentRevoker
cp RevokerByVoting.bin DecentRevoker/RevokerByVoting.bin
cp RevokerByVoting.abi DecentRevoker/RevokerByVoting.abi
cp RevokerByConflictMsg.bin DecentRevoker/RevokerByConflictMsg.bin
cp RevokerByConflictMsg.abi DecentRevoker/RevokerByConflictMsg.abi
cp RevokerByLeakedKey.bin DecentRevoker/RevokerByLeakedKey.bin
cp RevokerByLeakedKey.abi DecentRevoker/RevokerByLeakedKey.abi
mkdir -p KeyRevoker
cp KeyRevokerByVoting.bin KeyRevoker/KeyRevokerByVoting.bin
cp KeyRevokerByVoting.abi KeyRevoker/KeyRevokerByVoting.abi
cp KeyRevokerByConflictMsg.bin KeyRevoker/KeyRevokerByConflictMsg.bin
cp KeyRevokerByConflictMsg.abi KeyRevoker/KeyRevokerByConflictMsg.abi
cp KeyRevokerByLeakedKey.bin KeyRevoker/KeyRevokerByLeakedKey.bin
cp KeyRevokerByLeakedKey.abi KeyRevoker/KeyRevokerByLeakedKey.abi
- name: Downloading built contracts for DecentPubSub
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_APP_TOKEN }}
run: |
mkdir -p ${{ github.workspace }}/libs/DecentPubSub/build/PubSub/
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_PUBSUB_VER} \
--asset PubSubService.bin \
--save-path ${{ github.workspace }}/libs/DecentPubSub/build/PubSub/PubSubService.bin \
--repo lsd-ucsc/decent-pubsub-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_PUBSUB_VER} \
--asset PubSubService.abi \
--save-path ${{ github.workspace }}/libs/DecentPubSub/build/PubSub/PubSubService.abi \
--repo lsd-ucsc/decent-pubsub-onchain
sha256sum ${{ github.workspace }}/libs/DecentPubSub/build/PubSub/PubSubService.bin
sha256sum ${{ github.workspace }}/libs/DecentPubSub/build/PubSub/PubSubService.abi
- name: Downloading built contracts for DecentRA
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_APP_TOKEN }}
run: |
mkdir -p ${{ github.workspace }}/libs/DecentRA/build/contracts/
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset IASRootCertMgr.bin \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/IASRootCertMgr.bin \
--repo lsd-ucsc/decent-ra-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset IASRootCertMgr.abi \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/IASRootCertMgr.abi \
--repo lsd-ucsc/decent-ra-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset IASReportCertMgr.bin \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/IASReportCertMgr.bin \
--repo lsd-ucsc/decent-ra-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset IASReportCertMgr.abi \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/IASReportCertMgr.abi \
--repo lsd-ucsc/decent-ra-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset DecentServerCertMgr.bin \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/DecentServerCertMgr.bin \
--repo lsd-ucsc/decent-ra-onchain
python3 -m GitHubApiHelper --auth-token \
api_release_asset_dl \
--version ${DECENT_RA_VER} \
--asset DecentServerCertMgr.abi \
--save-path ${{ github.workspace }}/libs/DecentRA/build/contracts/DecentServerCertMgr.abi \
--repo lsd-ucsc/decent-ra-onchain
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/IASRootCertMgr.bin
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/IASRootCertMgr.abi
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/IASReportCertMgr.bin
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/IASReportCertMgr.abi
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/DecentServerCertMgr.bin
sha256sum ${{ github.workspace }}/libs/DecentRA/build/contracts/DecentServerCertMgr.abi
- name: Run gas cost evaluation for DecentRevoker
run: |
python3 ${{ github.workspace }}/utils/GasEvalDecentRevoker.py
- name: Run gas cost evaluation for KeyRevoker
run: |
python3 ${{ github.workspace }}/utils/GasEvalKeyRevoker.py
- name: Generate release note
working-directory: ${{ github.workspace }}/build
run: |
echo "# Release note" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "## Contracts" >> ${RELE_NOTE}
echo "- DecentRevoker/RevokerByVoting.sol" >> ${RELE_NOTE}
echo "- DecentRevoker/RevokerByConflictMsg.sol" >> ${RELE_NOTE}
echo "- DecentRevoker/RevokerByLeakedKey.sol" >> ${RELE_NOTE}
echo "- KeyRevoker/KeyRevokerByVoting.sol" >> ${RELE_NOTE}
echo "- KeyRevoker/KeyRevokerByConflictMsg.sol" >> ${RELE_NOTE}
echo "- KeyRevoker/KeyRevokerByLeakedKey.sol" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "## Build configurations" >> ${RELE_NOTE}
echo "- OS: \`${{ matrix.os }}\`" >> ${RELE_NOTE}
echo "- Solc version: \`$(bash -c "${SOLC_VER_CMD}")\`" >> ${RELE_NOTE}
echo "- Compiler Flags: \`${SOLC_FLAGS}\`" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "## Checksums" >> ${RELE_NOTE}
echo "\`\`\`" >> ${RELE_NOTE}
cat checksums.txt >> ${RELE_NOTE}
echo "\`\`\`" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "## Gas Cost Evaluations" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "### Decent Revoker" >> ${RELE_NOTE}
echo "\`\`\`json" >> ${RELE_NOTE}
cat gas_cost_decent_revoker.json >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "\`\`\`" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "### Key Revoker" >> ${RELE_NOTE}
echo "\`\`\`json" >> ${RELE_NOTE}
cat gas_cost_key_revoker.json >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
echo "\`\`\`" >> ${RELE_NOTE}
echo "" >> ${RELE_NOTE}
- name: Echo release note
run: |
cat ${{ github.workspace }}/build/release_note.md
- name: Release for non-tagged commit
uses: actions/upload-artifact@v3
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
with:
name: non_tagged_release
path: |
${{ github.workspace }}/build/release_note.md
${{ github.workspace }}/build/RevokerByVoting.bin
${{ github.workspace }}/build/RevokerByVoting.abi
${{ github.workspace }}/build/RevokerByConflictMsg.bin
${{ github.workspace }}/build/RevokerByConflictMsg.abi
${{ github.workspace }}/build/RevokerByLeakedKey.bin
${{ github.workspace }}/build/RevokerByLeakedKey.abi
${{ github.workspace }}/build/KeyRevokerByVoting.bin
${{ github.workspace }}/build/KeyRevokerByVoting.abi
${{ github.workspace }}/build/KeyRevokerByConflictMsg.bin
${{ github.workspace }}/build/KeyRevokerByConflictMsg.abi
${{ github.workspace }}/build/KeyRevokerByLeakedKey.bin
${{ github.workspace }}/build/KeyRevokerByLeakedKey.abi
${{ github.workspace }}/build/gas_cost_decent_revoker.json
${{ github.workspace }}/build/gas_cost_key_revoker.json
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: ${{ github.workspace }}/build/release_note.md
files: |
${{ github.workspace }}/build/RevokerByVoting.bin
${{ github.workspace }}/build/RevokerByVoting.abi
${{ github.workspace }}/build/RevokerByConflictMsg.bin
${{ github.workspace }}/build/RevokerByConflictMsg.abi
${{ github.workspace }}/build/RevokerByLeakedKey.bin
${{ github.workspace }}/build/RevokerByLeakedKey.abi
${{ github.workspace }}/build/KeyRevokerByVoting.bin
${{ github.workspace }}/build/KeyRevokerByVoting.abi
${{ github.workspace }}/build/KeyRevokerByConflictMsg.bin
${{ github.workspace }}/build/KeyRevokerByConflictMsg.abi
${{ github.workspace }}/build/KeyRevokerByLeakedKey.bin
${{ github.workspace }}/build/KeyRevokerByLeakedKey.abi
${{ github.workspace }}/build/gas_cost_decent_revoker.json
${{ github.workspace }}/build/gas_cost_key_revoker.json
46 changes: 46 additions & 0 deletions .github/workflows/solidity-unittesting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Running Solidity Unit Tests for Decent Revoker contracts


on:
push:
branches: [ main ]
pull_request:
branches: [ main ]


jobs:
run_sol_contracts_job:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04 ]
solc-version: [ 0.8.20 ]
chain-fork: [ shanghai ]
opt-runs: [ 200 ]

name: A job to run solidity unit tests on github actions CI
steps:

- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ACCESS_APP_TOKEN }}
submodules: recursive

- name: Run Solidity Unit Testing for DecentRevoker Tests
uses: EthereumRemix/[email protected]
with:
test-path: 'tests/DecentRevoker'
compiler-version: ${{ matrix.solc-version }}
optimize: true
optimizer-runs: ${{ matrix.opt-runs }}
hard-fork: ${{ matrix.chain-fork }}

- name: Run Solidity Unit Testing for KeyRevoker Tests
uses: EthereumRemix/[email protected]
with:
test-path: 'tests/KeyRevoker'
compiler-version: ${{ matrix.solc-version }}
optimize: true
optimizer-runs: ${{ matrix.opt-runs }}
hard-fork: ${{ matrix.chain-fork }}
Loading

0 comments on commit 70bfcd6

Please sign in to comment.