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

feat: test build only on changed code #867

Merged
merged 3 commits into from
Jun 27, 2023
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
73 changes: 30 additions & 43 deletions .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]

jobs:
check_file_changes:
name: Check file changes
name: Check file changes v2
outputs:
has_csharp_changes: ${{ steps.check_files.outputs.has_csharp_changes }}
has_go_changes: ${{ steps.check_files.outputs.has_go_changes }}
Expand All @@ -18,39 +18,58 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Check files
id: check_files
run: |
build:
needs: check_file_changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Runs docker builds with JSII superchain
run: |
echo "========== categorization of changed files =========="
buildpath=""
for file in $(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
do

IFS="/" read path1 path2 path3 <<< $file
echo $path1 $path2 $path3
if [[ "$buildpath" == "$path1/$path2" ]]; then
continue
fi
buildpath=$path1/$path2
echo "Build Path ${buildpath}"


echo -n "$file => "

case $file in
csharp/*)
case $path1 in
csharp)
echo "C#"
echo "::set-output name=has_csharp_changes::true"
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-csharp.sh $path2"
;;

go/*)
go)
echo "Go"
echo "::set-output name=has_go_changes::true"
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-go.sh $path2"
;;

java/*)
java)
echo "Java"
echo "::set-output name=has_java_changes::true"
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-java.sh $path2"
;;

python/*)
python)
echo "Python"
echo "::set-output name=has_python_changes::true"
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-python.sh $path2"
;;

typescript/*)
typescript)
echo "TypeScript"
echo "::set-output name=has_typescript_changes::true"
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-typescript.sh $path2"
;;

*)
Expand All @@ -59,35 +78,3 @@ jobs:
esac
done

build:
Copy link
Contributor

Choose a reason for hiding this comment

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

This step needs to be there for CI to work.

Find a way to get $path2 over here.

needs: check_file_changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Runs docker builds with JSII superchain
run: |
HAS_CSHARP_CHANGES="${{needs.check_file_changes.outputs.has_csharp_changes}}"
HAS_GO_CHANGES="${{needs.check_file_changes.outputs.has_go_changes}}"
HAS_JAVA_CHANGES="${{needs.check_file_changes.outputs.has_java_changes}}"
HAS_PYTHON_CHANGES="${{needs.check_file_changes.outputs.has_python_changes}}"
HAS_TYPESCRIPT_CHANGES="${{needs.check_file_changes.outputs.has_typescript_changes}}"

if [ "${HAS_CSHARP_CHANGES}" == "true" ]; then
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-csharp.sh"
fi

if [ "${HAS_GO_CHANGES}" == "true" ]; then
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-go.sh"
fi

if [ "${HAS_JAVA_CHANGES}" == "true" ]; then
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-java.sh"
fi

if [ "${HAS_PYTHON_CHANGES}" == "true" ]; then
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-python.sh"
fi

if [ "${HAS_TYPESCRIPT_CHANGES}" == "true" ]; then
docker run --rm --net=host -t -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim-node18 /bin/bash -c "scripts/build-typescript.sh"
fi
3 changes: 2 additions & 1 deletion scripts/build-csharp.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash
set -euxo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
modifieddir=$1

# install CDK CLI from npm, so that npx can find it later
cd $scriptdir/../csharp
npm install

# Find and build all CSharp projects
for projFile in $(find $scriptdir/../csharp -name cdk.json | grep -v node_modules); do
for projFile in $(find $scriptdir/../csharp/$modifieddir -name cdk.json | grep -v node_modules); do
(
echo "=============================="
echo "building project: $projFile"
Expand Down
3 changes: 2 additions & 1 deletion scripts/build-go.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash
set -euxo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
modifieddir=$1

# install CDK CLI from npm, so that npx can find it later
cd $scriptdir/../go
npm install

# Find and build all Go projects
for projFile in $(find $scriptdir/../go -name cdk.json | grep -v node_modules); do
for projFile in $(find $scriptdir/../go/$modifieddir -name cdk.json | grep -v node_modules); do
(
echo "=============================="
echo "building project: $projFile"
Expand Down
3 changes: 2 additions & 1 deletion scripts/build-java.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash
set -euxo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
modifieddir=$1

# install CDK CLI from npm, so that npx can find it later
cd $scriptdir/../java
npm install

# Find and build all Maven projects
for pomFile in $(find $scriptdir/../java -name pom.xml | grep -v node_modules); do
for pomFile in $(find $scriptdir/../java/$modifieddir -name pom.xml | grep -v node_modules); do
(
echo "=============================="
echo "building project: $(dirname $pomFile)"
Expand Down
8 changes: 3 additions & 5 deletions scripts/build-python.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
set -euxo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
modifieddir=$1

python3 -m venv /tmp/.venv

Expand All @@ -9,7 +10,7 @@ cd $scriptdir/../python
npm install

# Find and build all Python projects
for requirements in $(find $scriptdir/../python -name requirements.txt -not -path "$scriptdir/../python/node_modules/*"); do
for requirements in $(find $scriptdir/../python/$modifieddir -name requirements.txt -not -path "$scriptdir/../python/node_modules/*"); do
(
echo "=============================="
echo "building project: $requirements"
Expand All @@ -23,9 +24,6 @@ for requirements in $(find $scriptdir/../python -name requirements.txt -not -pa
pip install -r requirements.txt

$scriptdir/synth.sh

# It is critical that we clean up the pip venv before we build the next python project
# Otherwise, if anything gets pinned in a requirements.txt, you end up with a weird broken environment
pip freeze | xargs pip uninstall -y

)
done
3 changes: 2 additions & 1 deletion scripts/build-typescript.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash
set -euxo pipefail
scriptdir=$(cd $(dirname $0) && pwd)
modifieddir=$1

# Find and build all NPM projects
for pkgJson in $(find typescript -name cdk.json | grep -v node_modules | sort); do
for pkgJson in $(find $scriptdir/../typescript/$modifieddir -name cdk.json | grep -v node_modules | sort); do
(
echo "=============================="
echo "building project: $(dirname $pkgJson)"
Expand Down