summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-11-18 13:00:39 +0100
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-12-23 16:02:09 +0100
commit654f6839ebe33d64710b5e7f3c388539e84f8e35 (patch)
tree96ece0bd8ed778665a890c3e54119f7d748784cc
parentc8daa7218de7904151e61f2d9a1458e63b0e3363 (diff)
downloadspack-654f6839ebe33d64710b5e7f3c388539e84f8e35.tar.gz
spack-654f6839ebe33d64710b5e7f3c388539e84f8e35.tar.bz2
spack-654f6839ebe33d64710b5e7f3c388539e84f8e35.tar.xz
spack-654f6839ebe33d64710b5e7f3c388539e84f8e35.zip
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.
-rwxr-xr-x.github/workflows/setup_git.sh9
-rw-r--r--.github/workflows/unit_tests.yaml2
-rw-r--r--lib/spack/spack/test/cmd/style.py13
-rw-r--r--lib/spack/spack/test/package_sanity.py6
-rwxr-xr-xshare/spack/qa/run-style-tests10
5 files changed, 28 insertions, 12 deletions
diff --git a/.github/workflows/setup_git.sh b/.github/workflows/setup_git.sh
index bd79daf268..e319e07512 100755
--- a/.github/workflows/setup_git.sh
+++ b/.github/workflows/setup_git.sh
@@ -1,9 +1,8 @@
#!/usr/bin/env sh
git config --global user.email "spack@example.com"
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
-if [ "$(git branch --show-current)" != "develop" ]
-then
- git branch develop origin/develop
+
+# create a local pr base branch
+if [[ -n $GITHUB_BASE_REF ]]; then
+ git fetch origin "${GITHUB_BASE_REF}:${GITHUB_BASE_REF}"
fi
diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml
index 35722b9137..764a9cdcf0 100644
--- a/.github/workflows/unit_tests.yaml
+++ b/.github/workflows/unit_tests.yaml
@@ -211,6 +211,7 @@ jobs:
git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack
git fetch origin "${{ github.ref }}:test-branch"
git checkout test-branch
+ . .github/workflows/setup_git.sh
bin/spack unit-test -x
- name: Run unit tests (only package tests)
if: ${{ needs.changes.outputs.with_coverage == 'false' }}
@@ -223,6 +224,7 @@ jobs:
git clone "${{ github.server_url }}/${{ github.repository }}.git" && cd spack
git fetch origin "${{ github.ref }}:test-branch"
git checkout test-branch
+ . .github/workflows/setup_git.sh
bin/spack unit-test -x -m "not maybeslow" -k "package_sanity"
# Test RHEL8 UBI with platform Python. This job is run
diff --git a/lib/spack/spack/test/cmd/style.py b/lib/spack/spack/test/cmd/style.py
index af0fc47d24..29cde14400 100644
--- a/lib/spack/spack/test/cmd/style.py
+++ b/lib/spack/spack/test/cmd/style.py
@@ -24,8 +24,19 @@ style_data = os.path.join(spack.paths.test_path, 'data', '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
-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
# requiring Python 3.6 or higher to run spack style.
diff --git a/lib/spack/spack/test/package_sanity.py b/lib/spack/spack/test/package_sanity.py
index 35840d85da..dd2f4b425f 100644
--- a/lib/spack/spack/test/package_sanity.py
+++ b/lib/spack/spack/test/package_sanity.py
@@ -206,8 +206,12 @@ def test_prs_update_old_api():
"""Ensures that every package modified in a PR doesn't contain
deprecated calls to any method.
"""
+ ref = os.getenv("GITHUB_BASE_REF")
+ if not ref:
+ pytest.skip("No base ref found")
+
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 = []
for file in changed_package_files:
diff --git a/share/spack/qa/run-style-tests b/share/spack/qa/run-style-tests
index 72c47ff055..9f0cbdb266 100755
--- a/share/spack/qa/run-style-tests
+++ b/share/spack/qa/run-style-tests
@@ -14,15 +14,15 @@
# Usage:
# run-flake8-tests
#
-. "$(dirname $0)/setup.sh"
+. "$(dirname "$0")/setup.sh"
-BASE=""
-if [ -n "$GITHUB_BASE_REF" ]; then
- BASE="--base ${GITHUB_BASE_REF}"
+args=()
+if [[ -n $GITHUB_BASE_REF ]]; then
+ args+=("--base" "${GITHUB_BASE_REF}")
fi
# verify that the code style is correct
-spack style --root-relative $BASE
+spack style --root-relative "${args[@]}"
# verify that the license headers are present
spack license verify