Skip to content

Commit

Permalink
chore: run library generation jobs conditionally (#2698)
Browse files Browse the repository at this point in the history
In this PR:
- Add a job to get changed directories in pull request.
- Run library generation tests only if the changed directories contains
`library_generation`.

Verified in
- [Run
tests](https://github.com/googleapis/sdk-platform-java/actions/runs/8887270660/job/24402267953)
- [Don't run
tests](https://github.com/googleapis/sdk-platform-java/actions/runs/8887279933/job/24402294618)

The goal is to make library generation tests as a required check.
Moreover, we don't want these tests run against every pull requests
because only pull requests change library_generation directory should be
tested.

Currently, the workflow can only run if the files changed are within
`paths`. Therefore, we can't set this workflow as required because it
will get stuck and prevent merging for pull requests that don't change
files within paths.

Using this approach, this workflow runs on every pull request and only
run actual tests when the condition is met (determined by the first
job).

Official docs:
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks

We can make the workflow required after merging this PR and the tests in
the workflow will only run if the changed directories contains
`library_generation`.
  • Loading branch information
JoeWang1127 authored Apr 30, 2024
1 parent 712af4b commit b45eb84
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,38 @@ on:
branches:
- main
pull_request:
paths:
- library_generation/**

workflow_dispatch:
name: verify_library_generation
jobs:
integration_tests:
should-run-library-generation-tests:
runs-on: ubuntu-22.04
outputs:
should_run: ${{ steps.get_changed_directories.outputs.should_run }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: get changed directories in the pull request
id: get_changed_directories
shell: bash
run: |
set -ex
git checkout "${base_ref}"
git checkout "${head_ref}"
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
if [[ ${changed_directories} =~ "library_generation/" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
env:
base_ref: ${{ github.event.pull_request.base.ref }}
head_ref: ${{ github.event.pull_request.head.ref }}
library-generation-integration-tests:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -41,12 +65,14 @@ jobs:
run: |
set -x
python -m unittest library_generation/test/integration_tests.py
unit_tests:
library-generation-unit-tests:
runs-on: ${{ matrix.os }}
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
strategy:
matrix:
java: [ 8 ]
os: [ ubuntu-22.04, macos-12 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: install utils (macos)
Expand Down Expand Up @@ -88,8 +114,10 @@ jobs:
run: |
set -x
python -m unittest discover -s library_generation/test/ -p "*unit_tests.py"
lint-shell:
library-generation-lint-shell:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
Expand All @@ -98,8 +126,10 @@ jobs:
scandir: 'library_generation'
format: tty
severity: error
lint-python:
library-generation-lint-python:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- name: install python dependencies
Expand Down

0 comments on commit b45eb84

Please sign in to comment.