ci: run style unit tests only if we target develop (#27472)

Some tests assume the base branch is develop, but this branch may not
have been checked out.
This commit is contained in:
Harmen Stoppels 2021-11-18 13:00:39 +01:00 committed by GitHub
parent 7ee736a158
commit 8f7640dbef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 12 deletions

View File

@ -1,9 +1,8 @@
#!/usr/bin/env sh #!/usr/bin/env sh
git config --global user.email "spack@example.com" git config --global user.email "spack@example.com"
git config --global user.name "Test User" git config --global user.name "Test User"
# With fetch-depth: 0 we have a remote develop
# but not a local branch. Don't do this on develop # create a local pr base branch
if [ "$(git branch --show-current)" != "develop" ] if [[ -n $GITHUB_BASE_REF ]]; then
then git fetch origin "${GITHUB_BASE_REF}:${GITHUB_BASE_REF}"
git branch develop origin/develop
fi fi

View File

@ -211,6 +211,7 @@ jobs:
git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack
git fetch origin "${{ github.ref }}:test-branch" git fetch origin "${{ github.ref }}:test-branch"
git checkout test-branch git checkout test-branch
. .github/workflows/setup_git.sh
bin/spack unit-test -x bin/spack unit-test -x
- name: Run unit tests (only package tests) - name: Run unit tests (only package tests)
if: ${{ needs.changes.outputs.with_coverage == 'false' }} if: ${{ needs.changes.outputs.with_coverage == 'false' }}
@ -223,6 +224,7 @@ jobs:
git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack
git fetch origin "${{ github.ref }}:test-branch" git fetch origin "${{ github.ref }}:test-branch"
git checkout test-branch git checkout test-branch
. .github/workflows/setup_git.sh
bin/spack unit-test -x -m "not maybeslow" -k "package_sanity" bin/spack unit-test -x -m "not maybeslow" -k "package_sanity"
# Test RHEL8 UBI with platform Python. This job is run # Test RHEL8 UBI with platform Python. This job is run

View File

@ -24,8 +24,19 @@
style = spack.main.SpackCommand("style") style = spack.main.SpackCommand("style")
def has_develop_branch():
git = which('git')
if not git:
return False
git("show-ref", "--verify", "--quiet",
"refs/heads/develop", fail_on_error=False)
return git.returncode == 0
# spack style requires git to run -- skip the tests if it's not there # spack style requires git to run -- skip the tests if it's not there
pytestmark = pytest.mark.skipif(not which('git'), reason='requires git') pytestmark = pytest.mark.skipif(not has_develop_branch(),
reason='requires git with develop branch')
# The style tools have requirements to use newer Python versions. We simplify by # The style tools have requirements to use newer Python versions. We simplify by
# requiring Python 3.6 or higher to run spack style. # requiring Python 3.6 or higher to run spack style.

View File

@ -206,8 +206,12 @@ def test_prs_update_old_api():
"""Ensures that every package modified in a PR doesn't contain """Ensures that every package modified in a PR doesn't contain
deprecated calls to any method. deprecated calls to any method.
""" """
ref = os.getenv("GITHUB_BASE_REF")
if not ref:
pytest.skip("No base ref found")
changed_package_files = [ changed_package_files = [
x for x in style.changed_files() if style.is_package(x) x for x in style.changed_files(base=ref) if style.is_package(x)
] ]
failing = [] failing = []
for file in changed_package_files: for file in changed_package_files:

View File

@ -14,15 +14,15 @@
# Usage: # Usage:
# run-flake8-tests # run-flake8-tests
# #
. "$(dirname $0)/setup.sh" . "$(dirname "$0")/setup.sh"
BASE="" args=()
if [ -n "$GITHUB_BASE_REF" ]; then if [[ -n $GITHUB_BASE_REF ]]; then
BASE="--base ${GITHUB_BASE_REF}" args+=("--base" "${GITHUB_BASE_REF}")
fi fi
# verify that the code style is correct # verify that the code style is correct
spack style --root-relative $BASE spack style --root-relative "${args[@]}"
# verify that the license headers are present # verify that the license headers are present
spack license verify spack license verify