Run PR validation check only when needed & use docker cache during build (#876)

* Improve PR validation checks
This commit is contained in:
Igor Gov 2022-03-06 15:03:43 +02:00 committed by GitHub
parent dd430c31d5
commit 5e90d67b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 8 deletions

View File

@ -15,15 +15,23 @@ jobs:
name: CLI executable build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check modified files
id: modified_files
run: devops/check_modified_files.sh cli/
- name: Set up Go 1.17
if: steps.modified_files.outputs.matched == 'true'
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build CLI
if: steps.modified_files.outputs.matched == 'true'
run: make cli
build-agent:
@ -32,6 +40,23 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check modified files
id: modified_files
run: devops/check_modified_files.sh agent/ shared/ tap/ ui/ Dockerfile
- name: Build Agent
run: make agent-docker
- name: Set up Docker Buildx
if: steps.modified_files.outputs.matched == 'true'
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2
if: steps.modified_files.outputs.matched == 'true'
with:
context: .
push: false
tags: up9inc/mizu:devlatest
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@ -19,14 +19,16 @@ jobs:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Install libpcap
shell: bash
run: |
@ -40,16 +42,31 @@ jobs:
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v0'
- name: Check CLI modified files
id: cli_modified_files
run: devops/check_modified_files.sh cli/
- name: CLI Test
if: github.event_name == 'push' || steps.cli_modified_files.outputs.matched == 'true'
run: make test-cli
- name: Check Agent modified files
id: agent_modified_files
run: devops/check_modified_files.sh agent/
- name: Agent Test
if: github.event_name == 'push' || steps.agent_modified_files.outputs.matched == 'true'
run: make test-agent
- name: Shared Test
run: make test-shared
- name: Check extensions modified files
id: ext_modified_files
run: devops/check_modified_files.sh tap/extensions/
- name: Extensions Test
if: github.event_name == 'push' || steps.ext_modified_files.outputs.matched == 'true'
run: make test-extensions
- name: Upload coverage to Codecov

45
devops/check_modified_files.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
paths_arr=( "$@" )
printf "\n========== List modified files ==========\n"
echo "$(git diff --name-only HEAD^ HEAD)"
printf "\n========== List paths to match and check existence ==========\n"
for path in ${paths_arr[*]}
do
if [ -f "$path" ] || [ -d "$path" ]; then
echo "$path - found"
else
echo "$path - does not found - exiting with failure"
exit 1
fi
done
printf "\n========== Check paths of modified files ==========\n"
git diff --name-only HEAD^ HEAD > files.txt
matched=false
while IFS= read -r file
do
for path in ${paths_arr[*]}
do
if [[ $file == $path* ]]; then
echo "$file - match path: $path"
matched=true
break
fi
done
if [[ $matched == true ]]; then
break
else
echo "$file - does not match any given path"
fi
done < files.txt
printf "\n========== Result ==========\n"
if [[ $matched = true ]]; then
echo "match found"
echo "::set-output name=matched::true"
else
echo "no match found"
echo "::set-output name=matched::false"
fi