|
| 1 | +# documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions |
| 2 | +name: Test version for tarball without git metadata |
| 3 | +on: [push, pull_request, workflow_dispatch] |
| 4 | +permissions: read-all |
| 5 | +jobs: |
| 6 | + test_versioning_from_tarball: |
| 7 | + # ubuntu <= 20.04 is required for python 3.6 |
| 8 | + runs-on: ubuntu-20.04 |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11'] |
| 13 | + steps: |
| 14 | +# - name: Check out repository |
| 15 | +# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 16 | +# with: |
| 17 | +# persist-credentials: false |
| 18 | +# fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + |
| 25 | + - name: Install setuptools |
| 26 | + run: | |
| 27 | + if [[ "${{ matrix.python-version }}" == "3.6" ]]; then |
| 28 | + # system installed setuptools version in RHEL8 and CO7 |
| 29 | + python -m pip install --user setuptools==39.2.0 |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Install setuptools_scm |
| 33 | + run: | |
| 34 | + if [[ "${{ matrix.python-version }}" == "3.6" ]]; then |
| 35 | + python -m pip install --user 'setuptools_scm>=4.0.0,<=4.1.2' |
| 36 | + else |
| 37 | + python -m pip install --user setuptools_scm |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Check python and setuptools versions |
| 41 | + run: | |
| 42 | + python --version |
| 43 | + python -m pip --version |
| 44 | + python -c 'import setuptools; print("setuptools", setuptools.__version__)' |
| 45 | + python -m pip show setuptools_scm | grep Version |
| 46 | +
|
| 47 | + - name: Download and extract tarball for current commit |
| 48 | + run: | |
| 49 | + wget "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.tar.gz" |
| 50 | + tar -xzf "$GITHUB_SHA.tar.gz" |
| 51 | + # Check current directory contents |
| 52 | + find . |
| 53 | +
|
| 54 | + - name: Check version when running against uninstalled git clone |
| 55 | + run: | |
| 56 | + echo "importing eessi.testsuite from:" |
| 57 | + original_pythonpath=$PYTHONPATH |
| 58 | + export PYTHONPATH="$PWD/test-suite-$GITHUB_SHA:$PYTHONPATH" |
| 59 | + echo "PYTHONPATH: $PYTHONPATH" |
| 60 | + python3 -c "import eessi.testsuite; print(eessi.testsuite.__file__)" |
| 61 | +
|
| 62 | + uninstalled_version=$(python3 -c "import eessi.testsuite; print(eessi.testsuite.__version__)") |
| 63 | + echo "Version from uninstalled git clone: $uninstalled_version" |
| 64 | + fallback_version=$(grep -oP 'fallback_version\s*=\s*"\K[^"]+' "test-suite-$GITHUB_SHA/pyproject.toml") |
| 65 | +
|
| 66 | + echo "Testing if this version is the fallback version from pyproject.toml ..." |
| 67 | + if [[ "$uninstalled_version" != "$fallback_version" ]]; then |
| 68 | + echo "Version $uninstalled_version not equal to $fallback_version" |
| 69 | + exit 1 |
| 70 | + else |
| 71 | + echo "... yes!" |
| 72 | + fi |
| 73 | +
|
| 74 | + export PYTHONPATH="$original_pythonpath" |
| 75 | +
|
| 76 | + - name: Install from extracted tarball |
| 77 | + run: | |
| 78 | + # Make sure we get the fallback version from the pyprject.toml before changing workdir |
| 79 | + fallback_version=$(grep -oP 'fallback_version\s*=\s*"\K[^"]+' "test-suite-$GITHUB_SHA/pyproject.toml") |
| 80 | +
|
| 81 | + # Make it easier to figure out CI issues in case of CI failures related to SCM versioning |
| 82 | + export SETUPTOOLS_SCM_DEBUG=1 |
| 83 | +
|
| 84 | + # Change dir to the extracted tarball |
| 85 | + cd "test-suite-$GITHUB_SHA" |
| 86 | +
|
| 87 | + python -m pip install . --user |
| 88 | +
|
| 89 | + echo "Checking contents of .local" |
| 90 | + find $HOME/.local |
| 91 | +
|
| 92 | + # make sure we are not in the source directory |
| 93 | + cd $HOME |
| 94 | +
|
| 95 | + echo "Checking if file 'eessi/testsuite/_version.py' was generated by setuptools_scm": |
| 96 | + cat $HOME/.local/lib/python${{ matrix.python-version}}/site-packages/eessi/testsuite/_version.py |
| 97 | +
|
| 98 | + echo "Checking if version can be imported directly from the version file" |
| 99 | + if [[ "${{ matrix.python-version }}" == "3.6" ]]; then |
| 100 | + versionfile_version=$(python -c 'from eessi.testsuite._version import version; print(version)') |
| 101 | + else |
| 102 | + versionfile_version=$(python -c 'from eessi.testsuite._version import __version__; print(__version__)') |
| 103 | + fi |
| 104 | + echo "Version from version file: $versionfile_version" |
| 105 | +
|
| 106 | + echo "Checking if we can import the __version__ from eessi.testsuite" |
| 107 | + installed_version=$(python -c 'import eessi.testsuite; print(eessi.testsuite.__version__)') |
| 108 | + echo "Version from installed testsuite: $installed_version" |
| 109 | +
|
| 110 | + # Read the fallback version from the pyproject.toml |
| 111 | + echo "Testing if this is the fallback version from pyproject.toml ..." |
| 112 | + if [[ "$installed_version" != "$fallback_version" ]]; then |
| 113 | + echo "Version $installed_version not equal to $fallback_version" |
| 114 | + exit 1 |
| 115 | + else |
| 116 | + echo "... yes!" |
| 117 | + fi |
| 118 | +
|
| 119 | + echo "Checking if the version imported from eessi.testsuite matches that from the version file ..." |
| 120 | + if [[ "$versionfile_version" != "$installed_version" ]]; then |
| 121 | + echo "Version $versionfile_version not equal to $installed_version" |
| 122 | + exit 1 |
| 123 | + else |
| 124 | + echo "... yes!" |
| 125 | + fi |
| 126 | +
|
0 commit comments