test.yml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. name: Build tests
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. workflow_dispatch:
  8. env:
  9. LLVM_PROFILE_FILE: ${{ github.workspace }}/target/solang-%p-%10m.profraw
  10. jobs:
  11. repolinter:
  12. name: Repolinter
  13. runs-on: solang-ubuntu-latest
  14. steps:
  15. - name: Checkout sources
  16. uses: actions/checkout@v4
  17. - name: Run repolinter
  18. run: npx repolinter --rulesetUrl https://raw.githubusercontent.com/hyperledger-labs/hyperledger-community-management-tools/master/repo_structure/repolint.json
  19. - uses: enarx/spdx@master
  20. with:
  21. licenses: Apache-2.0 MIT
  22. docs:
  23. name: Docs
  24. runs-on: solang-ubuntu-latest
  25. container: ubuntu:22.04
  26. steps:
  27. - name: Install Python and git
  28. run: |
  29. apt-get update
  30. apt-get install -y python3-pip git pkg-config libcairo-dev latexmk
  31. - name: Checkout sources
  32. uses: actions/checkout@v4
  33. with:
  34. # docs/conf.py uses `git describe --tags` which requires full history
  35. fetch-depth: 0
  36. - name: Build docs
  37. working-directory: ./docs
  38. run: |
  39. # Without the --add safe.directory we get the following error:
  40. # fatal: detected dubious ownership in repository at '/__w/solang/solang'
  41. # actions/checkout@v4 is supposed to fix this, but it does not work
  42. git config --global --add safe.directory "${GITHUB_WORKSPACE}"
  43. pip install -r requirements.txt
  44. make html epub
  45. linux-x86-64:
  46. name: Linux x86-64
  47. runs-on: solang-ubuntu-latest
  48. container: ghcr.io/hyperledger/solang-llvm:ci-7
  49. env:
  50. RUSTFLAGS: -C instrument-coverage -C llvm-args=--instrprof-atomic-counter-update-all --cfg=coverage --cfg=trybuild_no_target
  51. CARGO_INCREMENTAL: 0
  52. CARGO_LLVM_COV: 1
  53. CARGO_LLVM_COV_TARGET_DIR: ${{ github.workspace }}/target
  54. steps:
  55. - name: Checkout sources
  56. uses: actions/checkout@v4
  57. with:
  58. submodules: recursive
  59. - name: Install Rust
  60. uses: dtolnay/rust-toolchain@master
  61. with:
  62. toolchain: 1.74.0
  63. components: |
  64. llvm-tools
  65. clippy
  66. rustfmt
  67. - name: cargo install cargo-llvm-cov
  68. uses: taiki-e/install-action@cargo-llvm-cov
  69. - name: Run cargo clippy
  70. run: cargo clippy --workspace --tests --bins -- -D warnings
  71. - name: Run cargo clippy without wasm_opt feature
  72. run: cargo clippy --workspace --no-default-features --features language_server,llvm,soroban --bins -- -D warnings
  73. - name: Run cargo clippy without llvm feature
  74. run: cargo clippy --workspace --no-default-features --lib -- -D warnings
  75. - name: Run cargo clippy with only soroban feature
  76. run: cargo clippy --workspace --no-default-features --features soroban,llvm --lib -- -D warnings
  77. - name: Run cargo doc
  78. run: cargo doc --workspace --bins
  79. - name: Run cargo fmt
  80. run: cargo fmt --all -- --check
  81. - name: Configure llvm-cov and build
  82. if: always()
  83. run: |
  84. cargo llvm-cov clean --workspace
  85. cargo build
  86. - name: Run tests
  87. if: always()
  88. run: cargo llvm-cov --all-features --workspace --no-report --jobs 2
  89. - name: Upload binary
  90. uses: actions/upload-artifact@v4.4.0
  91. with:
  92. name: solang-linux-x86-64
  93. path: ./target/debug/solang
  94. - name: Compress test coverage files
  95. run: |
  96. rm -r bpf wasm tmp cxxbridge CACHEDIR.TAG
  97. rm -r debug/build debug/deps debug/examples debug/incremental
  98. tar -czvf rust-tests.tar.gz *
  99. working-directory: ./target
  100. - name: Upload test coverage files
  101. uses: actions/upload-artifact@v4.4.0
  102. with:
  103. name: rust-tests.tar.gz
  104. path: ./target/rust-tests.tar.gz
  105. linux-arm:
  106. name: Linux Arm
  107. runs-on: solang-arm
  108. if: ${{ github.repository_owner == 'hyperledger-solang' }}
  109. steps:
  110. - name: Checkout sources
  111. uses: actions/checkout@v4
  112. with:
  113. submodules: recursive
  114. - name: Basic build tools
  115. run: |
  116. sudo apt-get update
  117. sudo apt-get install -y gcc g++ make
  118. - uses: dtolnay/rust-toolchain@1.74.0
  119. - name: Get LLVM
  120. run: curl -sSL --output llvm16.0-linux-arm64.tar.xz https://github.com/hyperledger-solang/solang-llvm/releases/download/llvm16-0/llvm16.0-linux-arm64.tar.xz
  121. - name: Extract LLVM
  122. run: tar Jxf llvm16.0-linux-arm64.tar.xz
  123. - name: Add LLVM to Path
  124. run: echo "$(pwd)/llvm16.0/bin" >> $GITHUB_PATH
  125. - name: Build
  126. run: cargo build --verbose
  127. - name: Run tests
  128. run: cargo test --verbose --workspace
  129. - uses: actions/upload-artifact@v4.4.0
  130. with:
  131. name: solang-linux-arm64
  132. path: ./target/debug/solang
  133. windows:
  134. name: Windows
  135. runs-on: windows-latest
  136. steps:
  137. - name: Checkout sources
  138. uses: actions/checkout@v4
  139. with:
  140. submodules: recursive
  141. - name: Download LLVM
  142. run: curl -sSL -o c:\llvm.zip https://github.com/hyperledger-solang/solang-llvm/releases/download/llvm16-0/llvm16.0-win.zip
  143. - name: Extract LLVM
  144. run: unzip c:\llvm.zip -d c:/
  145. - name: Add LLVM to Path
  146. run: echo "c:\llvm16.0\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
  147. # Use C:\ as D:\ might run out of space
  148. - name: "Use C: for rust temporary files"
  149. run: echo "CARGO_TARGET_DIR=C:\target" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
  150. - uses: dtolnay/rust-toolchain@1.74.0
  151. with:
  152. components: clippy
  153. # We run clippy on Linux in the lint job above, but this does not check #[cfg(windows)] items
  154. - name: Run cargo clippy
  155. run: cargo clippy --workspace --tests --bins -- -D warnings -D clippy::inconsistent-struct-constructor
  156. - name: Build
  157. run: cargo build --verbose
  158. - name: Run tests
  159. run: cargo test --verbose --workspace
  160. - uses: actions/upload-artifact@v4.4.0
  161. with:
  162. name: solang.exe
  163. path: C:/target/debug/solang.exe
  164. # Print disk usage to debug disk space problems
  165. - run: Get-PSDrive
  166. if: always()
  167. mac-arm:
  168. name: Mac Arm
  169. runs-on: macos-13-xlarge
  170. steps:
  171. - name: Checkout sources
  172. uses: actions/checkout@v4
  173. with:
  174. submodules: recursive
  175. - uses: dtolnay/rust-toolchain@1.74.0
  176. - name: Get LLVM
  177. run: curl -sSL --output llvm16.0-mac-arm.tar.xz https://github.com/hyperledger-solang/solang-llvm/releases/download/llvm16-0/llvm16.0-mac-arm.tar.xz
  178. - name: Extract LLVM
  179. run: tar Jxf llvm16.0-mac-arm.tar.xz
  180. - name: Add LLVM to Path
  181. run: echo "$(pwd)/llvm16.0/bin" >> $GITHUB_PATH
  182. - name: Build
  183. run: cargo build --verbose
  184. - name: Run tests
  185. run: cargo test --verbose --workspace
  186. - name: Run tests without wasm_opt
  187. run: cargo test --verbose --workspace --no-default-features --features language_server,llvm,soroban
  188. - uses: actions/upload-artifact@v4.4.0
  189. with:
  190. name: solang-mac-arm
  191. path: ./target/debug/solang
  192. mac-intel:
  193. name: Mac Intel
  194. runs-on: macos-12
  195. steps:
  196. - name: Checkout sources
  197. uses: actions/checkout@v4
  198. with:
  199. submodules: recursive
  200. - uses: dtolnay/rust-toolchain@1.74.0
  201. - name: Get LLVM
  202. run: wget -q -O llvm16.0-mac-intel.tar.xz https://github.com/hyperledger-solang/solang-llvm/releases/download/llvm16-0/llvm16.0-mac-intel.tar.xz
  203. - name: Extract LLVM
  204. run: tar Jxf llvm16.0-mac-intel.tar.xz
  205. - name: Add LLVM to Path
  206. run: echo "$(pwd)/llvm16.0/bin" >> $GITHUB_PATH
  207. - name: Build
  208. run: cargo build --verbose
  209. - name: Run tests
  210. run: cargo test --verbose --workspace
  211. - uses: actions/upload-artifact@v4.4.0
  212. with:
  213. name: solang-mac-intel
  214. path: ./target/debug/solang
  215. mac-universal:
  216. name: Mac Universal Binary
  217. runs-on: macos-12
  218. needs: [mac-arm, mac-intel]
  219. steps:
  220. - uses: actions/download-artifact@v4.1.8
  221. with:
  222. name: solang-mac-intel
  223. - run: mv solang solang-mac-intel
  224. - uses: actions/download-artifact@v4.1.8
  225. with:
  226. name: solang-mac-arm
  227. - run: mv solang solang-mac-arm
  228. - run: lipo -create -output solang-mac solang-mac-intel solang-mac-arm
  229. - uses: actions/upload-artifact@v4.4.0
  230. with:
  231. name: solang-mac
  232. path: solang-mac
  233. container:
  234. name: Container Image
  235. runs-on: solang-ubuntu-latest
  236. steps:
  237. - name: Checkout sources
  238. uses: actions/checkout@v4
  239. - run: echo "push=--push" >> $GITHUB_OUTPUT
  240. id: push
  241. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  242. - run: |
  243. echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
  244. docker buildx build . \
  245. ${{steps.push.outputs.push}} \
  246. --tag ghcr.io/${GITHUB_REPOSITORY}:latest \
  247. --label org.opencontainers.image.description="Solidity Compiler for Solana and Polkadot version $(git describe --tags)"
  248. anchor:
  249. name: Anchor Integration test
  250. runs-on: solang-ubuntu-latest
  251. container: ghcr.io/hyperledger/solang-llvm:ci-7
  252. needs: linux-x86-64
  253. steps:
  254. - name: Checkout sources
  255. uses: actions/checkout@v4
  256. - uses: actions/setup-node@v4
  257. with:
  258. node-version: '16'
  259. - uses: dtolnay/rust-toolchain@1.74.0
  260. - name: Setup yarn
  261. run: npm install -g yarn
  262. - uses: actions/download-artifact@v4.1.8
  263. with:
  264. name: solang-linux-x86-64
  265. path: bin
  266. - name: Solang Compiler
  267. run: |
  268. chmod 755 ./bin/solang
  269. echo "$(pwd)/bin" >> $GITHUB_PATH
  270. # Ensure nohup writes output to a file, not the terminal.
  271. # If we don't, solana-test-validator might not be able to write its
  272. # output and exit
  273. - run: nohup solana-test-validator -q > validator.out &
  274. - name: Build Anchor test program
  275. run: |
  276. yarn install
  277. anchor build
  278. working-directory: ./integration/anchor
  279. - name: Deploy Anchor program
  280. run: |
  281. solana -ul airdrop -k id.json 10
  282. anchor deploy
  283. working-directory: ./integration/anchor
  284. - name: Create Solidity interface file for Anchor
  285. run: yarn parse-idl
  286. working-directory: ./integration/anchor
  287. - name: Build Solang contracts
  288. run: yarn build
  289. working-directory: ./integration/anchor
  290. - name: Test Anchor
  291. run: anchor test --skip-local-validator
  292. working-directory: ./integration/anchor
  293. - name: Upload test coverage files
  294. uses: actions/upload-artifact@v4.4.0
  295. with:
  296. name: anchor-tests
  297. path: ./target/*.profraw
  298. soroban:
  299. name: Soroban Integration test
  300. runs-on: solang-ubuntu-latest
  301. container: ghcr.io/hyperledger/solang-llvm:ci-7
  302. needs: linux-x86-64
  303. steps:
  304. - name: Checkout sources
  305. uses: actions/checkout@v4
  306. - uses: actions/setup-node@v4
  307. with:
  308. node-version: '16'
  309. - uses: dtolnay/rust-toolchain@1.74.0
  310. - uses: actions/download-artifact@v4.1.8
  311. with:
  312. name: solang-linux-x86-64
  313. path: bin
  314. - name: Solang Compiler
  315. run: |
  316. chmod 755 ./bin/solang
  317. echo "$(pwd)/bin" >> $GITHUB_PATH
  318. - name: Install Soroban
  319. run: cargo install --locked soroban-cli --version 21.0.0-rc.1
  320. - name: Add cargo install location to PATH
  321. run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
  322. - run: npm install
  323. working-directory: ./integration/soroban
  324. - name: Build Solang contracts
  325. run: npm run build
  326. working-directory: ./integration/soroban
  327. - name: Setup Soroban enivronment
  328. run: npm run setup
  329. working-directory: ./integration/soroban
  330. - name: Deploy and test contracts
  331. run: npm run test
  332. working-directory: ./integration/soroban
  333. - name: Upload test coverage files
  334. uses: actions/upload-artifact@v4.4.0
  335. with:
  336. name: soroban-tests
  337. path: ./target/*.profraw
  338. solana:
  339. name: Solana Integration test
  340. runs-on: solang-ubuntu-latest
  341. container: ghcr.io/hyperledger/solang-llvm:ci-7
  342. needs: linux-x86-64
  343. steps:
  344. - name: Checkout sources
  345. uses: actions/checkout@v4
  346. - uses: actions/setup-node@v4
  347. with:
  348. node-version: '16'
  349. - uses: dtolnay/rust-toolchain@1.74.0
  350. - uses: actions/download-artifact@v4.1.8
  351. with:
  352. name: solang-linux-x86-64
  353. path: bin
  354. - name: Solang Compiler
  355. run: |
  356. chmod 755 ./bin/solang
  357. echo "$(pwd)/bin" >> $GITHUB_PATH
  358. # Ensure nohup writes output to a file, not the terminal.
  359. # If we don't, solana-test-validator might not be able to write its
  360. # output and exit
  361. - run: nohup solana-test-validator -q > validator.out &
  362. - run: npm install
  363. working-directory: ./integration/solana
  364. - name: Build Solang contracts
  365. run: npm run build
  366. working-directory: ./integration/solana
  367. - name: Deploy and test contracts
  368. run: npm run test
  369. working-directory: ./integration/solana
  370. - name: Upload test coverage files
  371. uses: actions/upload-artifact@v4.4.0
  372. with:
  373. name: solana-tests
  374. path: ./target/*.profraw
  375. polkadot:
  376. name: Polkadot Integration test
  377. runs-on: solang-ubuntu-latest
  378. needs: linux-x86-64
  379. steps:
  380. - name: Checkout sources
  381. uses: actions/checkout@v4
  382. with:
  383. submodules: recursive
  384. # We can't run substrate node as a github actions service, since it requires
  385. # command line arguments. See https://github.com/actions/runner/pull/1152
  386. - name: Start substrate contracts node
  387. run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:62a8a6c substrate-contracts-node --dev --rpc-external -lwarn,runtime::contracts=trace) >> $GITHUB_OUTPUT
  388. id: substrate
  389. - uses: actions/download-artifact@v4.1.8
  390. with:
  391. name: solang-linux-x86-64
  392. path: bin
  393. - run: |
  394. chmod 755 ./bin/solang
  395. echo "$(pwd)/bin" >> $GITHUB_PATH
  396. - uses: actions/setup-node@v4
  397. with:
  398. node-version: '16'
  399. - run: npm install
  400. working-directory: ./integration/polkadot
  401. - name: Build ink! contracts
  402. run: npm run build-ink
  403. working-directory: ./integration/polkadot
  404. - name: Build Solang contracts
  405. run: npm run build
  406. working-directory: ./integration/polkadot
  407. - name: Deploy and test contracts
  408. run: npm run test
  409. working-directory: ./integration/polkadot
  410. - name: Upload test coverage files
  411. uses: actions/upload-artifact@v4.4.0
  412. with:
  413. name: polkadot-tests
  414. path: ./target/*.profraw
  415. - name: cleanup
  416. if: always()
  417. run: docker kill ${{steps.substrate.outputs.id}}
  418. polkadot-subxt:
  419. name: Polkadot Integration test with subxt
  420. runs-on: ubuntu-22.04
  421. needs: linux-x86-64
  422. steps:
  423. - name: Checkout sources
  424. uses: actions/checkout@v4
  425. # We can't run substrate node as a github actions service, since it requires
  426. # command line arguments. See https://github.com/actions/runner/pull/1152
  427. - name: Start substrate
  428. run: echo id=$(docker run -d -p 9944:9944 ghcr.io/hyperledger/solang-substrate-ci:62a8a6c substrate-contracts-node --dev --rpc-external -lwarn,runtime::contracts=trace) >> $GITHUB_OUTPUT
  429. id: substrate
  430. - uses: actions/download-artifact@v4.1.8
  431. with:
  432. name: solang-linux-x86-64
  433. path: bin
  434. - run: |
  435. chmod 755 ./bin/solang
  436. echo "$(pwd)/bin" >> $GITHUB_PATH
  437. - name: Install latest rust toolchain
  438. uses: dtolnay/rust-toolchain@stable
  439. with:
  440. toolchain: stable
  441. - run: 'parallel solang compile -v --target polkadot --wasm-opt z -o ./contracts/ ::: ../polkadot/*.sol ../polkadot/test/*.sol'
  442. working-directory: ./integration/subxt-tests
  443. - name: Deploy and test contracts
  444. run: cargo test -- --test-threads=1
  445. working-directory: ./integration/subxt-tests
  446. - name: cleanup
  447. if: always()
  448. run: docker kill ${{steps.substrate.outputs.id}}
  449. - name: Upload test coverage files
  450. uses: actions/upload-artifact@v4.4.0
  451. with:
  452. name: polkadot-subxt-tests
  453. path: ./target/*.profraw
  454. vscode:
  455. name: Visual Code Extension
  456. runs-on: solang-ubuntu-latest
  457. needs: linux-x86-64
  458. steps:
  459. - name: Checkout
  460. uses: actions/checkout@v4
  461. - uses: actions/download-artifact@v4.1.8
  462. with:
  463. name: solang-linux-x86-64
  464. path: bin
  465. - run: |
  466. chmod 755 ./bin/solang
  467. echo "$(pwd)/bin" >> $GITHUB_PATH
  468. - name: Install Node.js
  469. uses: actions/setup-node@v4
  470. with:
  471. node-version: '>=18.17'
  472. - run: npm install
  473. working-directory: ./vscode
  474. - run: npm run compile
  475. working-directory: ./vscode
  476. - name: Run headless test
  477. run: xvfb-run npm test
  478. working-directory: ./vscode
  479. - run: npm install -g vsce
  480. working-directory: ./vscode
  481. - run: vsce package
  482. working-directory: ./vscode
  483. - name: Upload test coverage files
  484. uses: actions/upload-artifact@v4.4.0
  485. with:
  486. name: vscode-tests
  487. path: ./target/*.profraw
  488. std-lib-tests:
  489. name: Stdlib
  490. runs-on: solang-ubuntu-latest
  491. steps:
  492. - name: Checkout sources
  493. uses: actions/checkout@v4
  494. - name: Lints for stdlib
  495. run: |
  496. make lint
  497. working-directory: ./stdlib
  498. - name: Stdlib tests
  499. run: |
  500. make test
  501. ./test
  502. working-directory: ./stdlib
  503. coverage:
  504. runs-on: ubuntu-latest
  505. name: Coverage report
  506. container: ghcr.io/hyperledger/solang-llvm:ci-7
  507. needs: [linux-x86-64, solana, anchor, polkadot, polkadot-subxt, vscode]
  508. env:
  509. RUSTFLAGS: -C instrument-coverage -C llvm-args=--instrprof-atomic-counter-update-all --cfg=coverage --cfg=trybuild_no_target
  510. CARGO_INCREMENTAL: 0
  511. CARGO_LLVM_COV: 1
  512. CARGO_LLVM_COV_TARGET_DIR: ${{ github.workspace }}/target
  513. steps:
  514. - name: Checkout
  515. uses: actions/checkout@v4
  516. with:
  517. submodules: recursive
  518. - name: Install Rust
  519. uses: dtolnay/rust-toolchain@master
  520. with:
  521. toolchain: 1.74.0
  522. components: llvm-tools
  523. - name: Install cargo-llvm-cov
  524. uses: taiki-e/install-action@cargo-llvm-cov
  525. - name: Download Rust coverage files
  526. uses: actions/download-artifact@v4.1.8
  527. with:
  528. name: rust-tests.tar.gz
  529. path: ./target
  530. - name: Download Solana coverage files
  531. uses: actions/download-artifact@v4.1.8
  532. with:
  533. name: solana-tests
  534. path: ./target
  535. - name: Download Polkadot coverage files
  536. uses: actions/download-artifact@v4.1.8
  537. with:
  538. name: polkadot-tests
  539. path: ./target
  540. - name: Download Polkadot subxt coverage files
  541. uses: actions/download-artifact@v4.1.8
  542. with:
  543. name: polkadot-subxt-tests
  544. path: ./target
  545. - name: Download Anchor coverage files
  546. uses: actions/download-artifact@v4.1.8
  547. with:
  548. name: anchor-tests
  549. path: ./target
  550. - name: Download VSCode coverage files
  551. uses: actions/download-artifact@v4.1.8
  552. with:
  553. name: vscode-tests
  554. path: ./target
  555. - name: Unpack test coverage files
  556. run: tar -xf rust-tests.tar.gz
  557. working-directory: ./target
  558. - name: Generate code report
  559. run: cargo llvm-cov report --lcov --output-path lcov.info
  560. - name: Upload coverage report to codecov.io
  561. uses: codecov/codecov-action@v3
  562. env:
  563. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  564. with:
  565. fail_ci_if_error: false