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

Contract actions #1

Merged
merged 26 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
156 changes: 156 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Contracts builds and tests

on:
workflow_call:
inputs:
rust-toolchain:
description: 'Rust toolchain to use'
default: 'nightly'
required: false
type: string
vmtools-version:
description: 'vmtools version to use'
default: 'latest'
required: false
type: string
pip-erdpy-args:
description: 'pip erdpy install arguments'
default: 'erdpy'
required: false
type: string
extra-build-args:
description: 'extra build arguments'
default: ''
required: false
type: string
secrets:
token:
description: 'Github token'
required: true

jobs:
wasm_test:
name: Wasm tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install rust
uses: actions-rs/toolchain@v1
with:
default: true
toolchain: "${{ inputs.rust-toolchain }}"

- name: Setup the PATH variable
run: echo "PATH=$HOME/.local/bin:$HOME/elrondsdk/vmtools:$PATH" >> $GITHUB_ENV

- name: Install prerequisites
run: |
pip3 install ${{ inputs.pip-erdpy-args }}
mkdir $HOME/elrondsdk
erdpy deps install vmtools --tag ${{ inputs.vmtools-version }}

erdpy deps install nodejs
erdpy deps install wasm-opt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--tag=...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasm-opt should use the latest version


cargo install twiggy

- name: Build the wasm contracts
run: erdpy contract build -r ${{ inputs.extra-build-args }}

- name: Run the wasm tests
run: cargo test --features elrond-wasm-debug/mandos-go-tests

- name: Generate the contract report
run: erdpy contract report --skip-build --output-format json --output-file report.json

- name: Upload the report json
uses: actions/upload-artifact@v3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also conditionally (what conditions?) upload the generated /output, as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I focused on porting the existing functionality - I think uploading the contracts from the output folder can be done in a follow-up PR.

with:
name: report
path: report.json

- name: Download the base report
uses: dawidd6/action-download-artifact@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the official action, actions/download-artifact@v2, instead?

https://github.com/ElrondNetwork/sc-dex-rs/blob/main/.github/workflows/release.yml#L58

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official action is fairly limited (only allows configuring the artifact name and destination path) and only supports downloading artifacts from the same workflow (from the current commit).
What I need is the artifact from the base branch (same workflow but a different build) - only dawidd6/action-download-artifact@v2 allows me to specify this.

if: github.event_name == 'pull_request'
continue-on-error: true
with:
workflow: actions.yml
name: report
commit: ${{ github.event.pull_request.base.sha }}
path: base-report

- name: Generate the report template
if: github.event_name == 'pull_request'
run: |
echo "Contract comparison - from {{ .base }} to {{ .head }}" > report.md
if [ ! -f base-report/report.json ]
then
echo ":warning: Warning: Could not download the report for the base branch. Displaying only the report for the current branch. :warning:" >> report.md
erdpy contract report --compare report.json --output-format github-markdown --output-file report-table.md
else
erdpy contract report --compare base-report/report.json report.json --output-format github-markdown --output-file report-table.md
fi
cat report-table.md >> report.md

- name: Render the report from the template
id: template
uses: chuhlomin/render-template@v1.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another community action. Isn't there a simple find & replace command / Python (inline script) that we can use, instead?

if: github.event_name == 'pull_request'
with:
template: report.md
vars: |
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}

- name: Upload the report markdown
uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: report-markdown
path: report.md

- name: Find the comment containing the report
id: fc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step ID? Is this name fixed or can we change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of this ID as a local variable - it's used below in one of the next steps. We can change it if you want - I'm fine with either this or another name.

uses: peter-evans/find-comment@v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we should depend on community (not Github official) actions or use our own code. @camilbancioiu, @bogdan-rosianu?

if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'Contract comparison'

- name: Create or update the report comment
uses: peter-evans/create-or-update-comment@v1
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.template.outputs.result }}
edit-mode: replace

rust_test:
name: Rust tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
default: true
toolchain: ${{ inputs.rust-toolchain }}

- name: Run the rust tests
run: cargo test

clippy_check:
name: Clippy linter check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ inputs.rust-toolchain }}
components: clippy
default: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.token }}
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# elrond-actions
Github actions for smart contracts
# Github Actions for smart contracts

A Github Action for smart contracts which:
- builds the wasm files
- runs mandos-rs and mandos-go tests
- does a clippy check
- provides a report containing details about the smart contracts

## Usage

### Standard build

See [contracts.yml](.github/workflows/contracts.yml)
This uses fixed versions of rust and vmtools.
claudiu725 marked this conversation as resolved.
Show resolved Hide resolved
Ignores `eei` checks which allows the contracts to use features which are not live on the elrond mainnet yet.

```yml
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
contracts:
name: Contracts
uses: ElrondNetwork/elrond-actions/.github/workflows/contracts.yml@v1
with:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably wasm-opt logic / version has an impact on deterministic builds, as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably erdpy version can be specified as well (optional field)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment the aim is not to make the build deterministic (anyway, this is done through docker images), but only to port the existing functionality and to integrate erdpy contract report. The latest wasm-opt should be fine.
The versions which are fixed at the moment (rust nightly, vmtools) are fixed because we've had broken builds in the past because of changes in those two.
The rust nightly is volatile and since our code depends on a lot of features. For vmtools the outputs of the mandos tests may differ - so upgrades have to be done manually.
I added the possibility to specify the erdpy version and added information about the extra option to the README.md

rust-toolchain: nightly-2022-01-17
vmtools-version: v1.4.43
extra-build-args: --ignore-eei-checks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps in a next PR, there could be a new action, more specific to deterministic builds, which would rely on the frozen docker images?

https://github.com/ElrondNetwork/sc-dex-rs/blob/main/.github/workflows/release.yml#L24

And also use a fixed location for the build:

https://github.com/ElrondNetwork/sc-dex-rs/blob/main/.github/workflows/release.yml#L31

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. In a future PR it is then 👍

secrets:
token: ${{ secrets.GITHUB_TOKEN }}
```

### Additional options

The erdpy version can be specified by providing:
```yml
pip-erdpy-args: erdpy==1.2.3
```