Skip to content

Commit

Permalink
CI optimization: build workflow matrix dynamically (#47)
Browse files Browse the repository at this point in the history
* ci build workflow matrix dynamically

* add skip check condition and little nits
  • Loading branch information
sergejparity authored Nov 8, 2023
1 parent b5a5a55 commit e4a75d2
Showing 1 changed file with 82 additions and 36 deletions.
118 changes: 82 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- '**.gitignore'
- '.images/**'
- '**README.md'
- 'LICENSE'

pull_request:
branches:
Expand All @@ -18,50 +19,95 @@ on:
- '**.gitignore'
- '.images/**'
- '**README.md'
- 'LICENSE'


jobs:
prepare_matrix:
name:
runs-on: ubuntu-latest
env:
# constant values for matrix
platform: '[\"ubuntu-latest\", \"macos-latest\"]'
toolchain: '[\"stable\"]'
outputs:
MATRIX: ${{ steps.build_matrix.outputs.MATRIX }}
SKIP_CHECKS: ${{ steps.build_matrix.outputs.SKIP_CHECKS }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Look for changes in standalone contracts
id: CHANGED_CONTRACTS
uses: tj-actions/changed-files@v39
with:
dir_names: "true"
dir_names_exclude_current_dir: "true"
dir_names_max_depth: 1
files_ignore: |
.github/**
**/.gitignore
**/*.md
multi-contract-caller/**
upgradeable-contracts/**
json: true

- name: Look for changes in multi and upgradable contracts
id: CHANGED_MULTI_AND_UPGRADEABLE_CONTRACTS
uses: tj-actions/changed-files@v39
with:
dir_names: "true"
dir_names_exclude_current_dir: "true"
dir_names_max_depth: 2
files: |
multi-contract-caller/**
upgradeable-contracts/**
files_ignore: |
**/.gitignore
**/*.md
json: true

- name: Build matrix
id: build_matrix
run: |
ALL_CHANGED_CONTRACTS=$(jq -s 'add' \
<(echo "${{ steps.CHANGED_CONTRACTS.outputs.all_changed_files }}") \
<(echo "${{ steps.CHANGED_MULTI_AND_UPGRADEABLE_CONTRACTS.outputs.all_changed_files }}"))
if [ $ALL_CHANGED_CONTRACTS = "[]" ]
then
echo "Nothing important changed. Checks job will be skipped."
echo "SKIP_CHECKS=true" >> $GITHUB_OUTPUT
else
echo "There are changes in following contracts: $ALL_CHANGED_CONTRACTS"
echo "SKIP_CHECKS=false" >> $GITHUB_OUTPUT
fi
echo "MATRIX={\"platform\":${{env.platform}},\
\"toolchain\":${{env.toolchain}},\
\"contract\":"$ALL_CHANGED_CONTRACTS"}"\
>> $GITHUB_OUTPUT
- name: Show resulting matrix
run: |
echo "Following matrix will be used to generate test jobs."
echo ${{ toJson(steps.build_matrix.outputs.MATRIX) }} | jq
check:
name: examples
needs: prepare_matrix
if: ${{ needs.prepare_matrix.outputs.SKIP_CHECKS == 'false' }}
env:
RUST_BACKTRACE: full

strategy:
matrix:
platform:
- ubuntu-latest
- macos-latest
toolchain:
- stable
contract:
- basic-contract-caller
- call-runtime
- conditional-compilation
- contract-terminate
- custom-allocator
- custom-environment
- dns
- e2e-call-runtime
- erc20
- erc721
- erc1155
- flipper
- incrementer
- multi-contract-caller
- multi-contract-caller/accumulator
- multi-contract-caller/adder
- multi-contract-caller/subber
- multisig
- payment-channel
- psp22-extension
- rand-extension
- trait-dyn-cross-contract-calls
- trait-erc20
- trait-flipper
- trait-incrementer
- upgradeable-contracts/delegator
- upgradeable-contracts/set-code-hash
- vesting
${{ fromJson(needs.prepare_matrix.outputs.MATRIX) }}

runs-on: ${{ matrix.platform }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout sources & submodules
uses: actions/checkout@v4
Expand Down

0 comments on commit e4a75d2

Please sign in to comment.