Skip to content

checkout v3 to v4 and echos #1194

checkout v3 to v4 and echos

checkout v3 to v4 and echos #1194

Workflow file for this run

name: Test functions
on:
pull_request:
types: [opened,synchronize]
branches-ignore:
- testing
jobs:
build_strategy_matrix:
runs-on: ubuntu-latest
steps:
- name: Get the current branch name
shell: bash
run: echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
id: myref
- uses: actions/checkout@v3
- id: set-matrix
# This is very hacky, but it goes like that:
# 1) Associate base_ref with origin/base_ref since actions/checkout doesn't do it, if we don't do that we won't be able to check the actual diff
# 2) Build JSON string
# 2.1) Add beginning of JSON
# 2.2) Get diff between origin/base_ref and the checked-out repo => git diff ${{ github.base_ref }} --name-only
# 2.3) Clean the file name and leave us only with directories => sed 's,/*[^/]\+/*$,,'
# 2.4) Sort and keep only unique directories => sort | uniq
# 2.5) Remove directories starting with '.' => grep -v '^\.'
# 2.6) Add quotation marks to all strings => sed 's/.*/"&"/'
# 2.7) Add comma suffix to all strings excluding the last one => sed '$!s/.*/&,/'
# 2.8) Close JSON
# 3) Save matrix JSON to output
# This is previous fetch command that stopped working (wile invetsigating added WA bello in run sectiong): git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
# This is old git diff version: git diff ${{ github.base_ref }} --name-only | sed 's,/*[^/]\+/*$,,' | sort | uniq | grep -v '^\.' | sed 's/.*/"&"/' | sed '$!s/.*/&,/'
# Based on instructions regarding https://docs.github.com/en/actions/learn-github-actions/contexts#github-context , github.base_ref triggers a workflow run is either pull_request or pull_request_target
run: |
git fetch --no-tags --prune --depth=1 origin ${{ github.base_ref }}:${{ github.base_ref }}
matrix=$((
echo '{ "package" : ['
git diff ${{ github.base_ref }} --name-only | sed 's,/*[^/]\+/*$,,' | sort | uniq | grep -v '^\.' | sed 's/.*/"&"/' | sed '$!s/.*/&,/'
echo " ]}"
) | jq 'del(.[][] | select(. == ""))' -c)
echo "::set-output name=matrix::$matrix"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
check_matrix:
runs-on: ubuntu-latest
needs: build_strategy_matrix
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml
- name: Check matrix definition
run: |
matrix='${{ needs.build_strategy_matrix.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml
run_monorepo_tests:
needs: build_strategy_matrix
runs-on: ubuntu-latest
strategy:
# matrix: [{"package": some package that changed}, {...}, ...]
matrix: ${{fromJson(needs.build_strategy_matrix.outputs.matrix)}}
steps:
- name: Checkout current repo
uses: actions/checkout@v3
with:
path: functions
# Install python 3.9
- name: Install python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9
# Install dependencies
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('functions/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
pip install --upgrade pip
pip install -r functions/requirements.txt
- name: Run py tests
run: python functions/functions.py run-tests -r functions -s py -fn ${{ matrix.package }}
- name: Clean
run: |
rm -rf functions