|
| 1 | +# This workflow will test cpac |
| 2 | + |
| 3 | +name: Test cpac |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + paths-ignore: |
| 8 | + - README.rst |
| 9 | + |
| 10 | +jobs: |
| 11 | + set_docker_image: |
| 12 | + outputs: |
| 13 | + docker_image: ${{ steps.set_docker_image.outputs.docker_image }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - id: set_docker_image |
| 17 | + name: set tag name |
| 18 | + run: | |
| 19 | + DOCKER_IMAGE="ghcr.io/${{ github.repository }}/api-test" |
| 20 | + DOCKER_IMAGE="${DOCKER_IMAGE@L}" |
| 21 | + echo "docker_image=${DOCKER_IMAGE}" >> "${GITHUB_OUTPUT}" |
| 22 | +
|
| 23 | + build_dry_run_image: |
| 24 | + needs: set_docker_image |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Set up Docker Buildx |
| 28 | + |
| 29 | + - name: Log in to GitHub Container Registry |
| 30 | + |
| 31 | + with: |
| 32 | + registry: ghcr.io |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + - name: Build and push |
| 39 | + |
| 40 | + with: |
| 41 | + context: . |
| 42 | + file: ./.github/Dockerfiles/c-pac_api.${{ matrix.tag }}.Dockerfile |
| 43 | + provenance: false |
| 44 | + sbom: false |
| 45 | + push: true |
| 46 | + tags: | |
| 47 | + ${{ needs.set_docker_image.outputs.docker_image }}:${{ matrix.tag }} |
| 48 | + strategy: |
| 49 | + matrix: |
| 50 | + tag: [latest, nightly] |
| 51 | + |
| 52 | + test_cpac: |
| 53 | + env: |
| 54 | + APPTAINER_CACHEDIR: ${{ github.workspace }}/.apptainer/cache |
| 55 | + APPTAINER_TMPDIR: ${{ github.workspace }}/.apptainer/tmp |
| 56 | + needs: |
| 57 | + - build_dry_run_image |
| 58 | + - set_docker_image |
| 59 | + runs-on: ubuntu-latest |
| 60 | + strategy: |
| 61 | + matrix: |
| 62 | + apptainer: [1.0.0, 1.3.0] |
| 63 | + go: [1.14] |
| 64 | + platform: [apptainer, docker] |
| 65 | + python: ['3.10', 3.11, 3.12] |
| 66 | + tag: [latest, nightly] |
| 67 | + exclude: |
| 68 | + - platform: apptainer |
| 69 | + python: 3.11 |
| 70 | + - platform: apptainer |
| 71 | + python: 3.12 |
| 72 | + steps: |
| 73 | + - name: Clear up some space on runner |
| 74 | + run: | |
| 75 | + sudo rm -rf /usr/share/dotnet |
| 76 | + sudo rm -rf /opt/ghc |
| 77 | + sudo rm -rf "/usr/local/share/boost" |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + - name: Set up Go |
| 80 | + uses: actions/setup-go@v5 |
| 81 | + with: |
| 82 | + cache: false |
| 83 | + go-version: ${{ matrix.go }} |
| 84 | + - name: Set up Python |
| 85 | + uses: actions/setup-python@v5 |
| 86 | + with: |
| 87 | + python-version: ${{ matrix.python }} |
| 88 | + - name: Install --upgrade pip setuptools wheel |
| 89 | + run: python -m pip install --upgrade pip setuptools wheel |
| 90 | + - name: Setup apptainer |
| 91 | + if: ${{ matrix.platform == 'apptainer' }} |
| 92 | + uses: eWaterCycle/setup-apptainer@v2 |
| 93 | + with: |
| 94 | + apptainer-version: ${{ matrix.apptainer }} |
| 95 | + - name: Install cpac |
| 96 | + run: cd $GITHUB_WORKSPACE && pip install -e ".[dev,testing,tsconcat]" |
| 97 | + - name: Pull images |
| 98 | + if: ${{ matrix.platform == 'apptainer' }} |
| 99 | + run: | |
| 100 | + mkdir -p ${{ env.APPTAINER_CACHEDIR }} |
| 101 | + mkdir -p ${{ env.APPTAINER_TMPDIR }} |
| 102 | + export APPTAINER_CACHEDIR=${{ env.APPTAINER_CACHEDIR }} |
| 103 | + export SINGULARITY_CACHEDIR=${{ env.APPTAINER_CACHEDIR }} |
| 104 | + export APPTAINER_TMPDIR=${{ env.APPTAINER_TMPDIR }} |
| 105 | + export SINGULARITY_TMPDIR=${{ env.APPTAINER_TMPDIR }} |
| 106 | + cpac --platform ${{ matrix.platform }} pull --image ${{ needs.set_docker_image.outputs.docker_image }} --tag ${{ matrix.tag }} |
| 107 | + - name: Test cpac, platform and tag specified |
| 108 | + run: | |
| 109 | + coverage run --append -m pytest --basetemp=${PWD}/tmp --doctest-modules --image=${{ needs.set_docker_image.outputs.docker_image }} --platform ${{ matrix.platform }} --tag ${{ matrix.tag }} . |
| 110 | + coverage report -m |
| 111 | + - name: Test cpac, platform specified, tag unspecified |
| 112 | + if: ${{ matrix.tag == 'latest' }} and ${{ matrix.platform == 'docker' }} |
| 113 | + run: | |
| 114 | + coverage run --append -m pytest --basetemp=${PWD}/tmp --doctest-modules --image=${{ needs.set_docker_image.outputs.docker_image }} --platform ${{ matrix.platform }} . |
| 115 | + coverage report -m |
| 116 | + - name: Test cpac, platform unspecified, tag specified |
| 117 | + if: ${{ matrix.platform == 'docker' }} |
| 118 | + run: | |
| 119 | + coverage run --append -m pytest --basetemp=${PWD}/tmp --doctest-modules --image=${{ needs.set_docker_image.outputs.docker_image }} --tag ${{ matrix.tag }} . |
| 120 | + coverage report -m |
| 121 | + - name: Test cpac, platform and tag unspecified |
| 122 | + if: ${{ matrix.platform == 'docker' }} && ${{ matrix.tag }} == 'latest' |
| 123 | + run: | |
| 124 | + coverage run --append -m pytest --basetemp=${PWD}/tmp --doctest-modules --image=${{ needs.set_docker_image.outputs.docker_image }} . |
| 125 | + coverage report -m |
| 126 | + - name: Report coverage |
| 127 | + uses: AndreMiras/coveralls-python-action@v20201129 |
| 128 | + with: |
| 129 | + parallel: true |
| 130 | + flag-name: Test cpac ${{ matrix.platform }} with Python ${{ matrix.python }} |
| 131 | + continue-on-error: true |
| 132 | + finalize_coverage-report: |
| 133 | + needs: |
| 134 | + - test_cpac |
| 135 | + runs-on: ubuntu-latest |
| 136 | + steps: |
| 137 | + - name: Finalize coverage report |
| 138 | + uses: AndreMiras/coveralls-python-action@v20201129 |
| 139 | + with: |
| 140 | + parallel-finished: true |
| 141 | + continue-on-error: true |
| 142 | + update_README: |
| 143 | + # Only update README if tests succeed |
| 144 | + needs: |
| 145 | + - test_cpac |
| 146 | + runs-on: ubuntu-latest |
| 147 | + steps: |
| 148 | + - uses: actions/checkout@v4 |
| 149 | + with: |
| 150 | + fetch-depth: 0 |
| 151 | + - name: Install cpac |
| 152 | + run: | |
| 153 | + export DEB_PYTHON_INSTALL_LAYOUT=deb_system |
| 154 | + cd $GITHUB_WORKSPACE |
| 155 | + pip install . |
| 156 | + - name: Configure Git credentials |
| 157 | + uses: oleksiyrudenko/[email protected] |
| 158 | + with: |
| 159 | + global: true |
| 160 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + - name: Update README |
| 162 | + run: | |
| 163 | + (head -n $(read -d : <<< $(less README.rst | grep ".. BEGIN USAGE" -n); expr $REPLY + 1) README.rst; \ |
| 164 | + printf ".. code-block:: shell\n\n cpac --help\n"; \ |
| 165 | + cpac --help | sed 's/^/ /'; \ |
| 166 | + tail --lines=+$(read -d : <<< $(less README.rst | grep ".. END USAGE" -n); expr $REPLY - 1) README.rst\ |
| 167 | + ) > tempREADME && |
| 168 | + mv tempREADME README.rst & |
| 169 | + wait %1 |
| 170 | + if [[ $(git diff --numstat README.rst) ]]; then |
| 171 | + git add README.rst |
| 172 | + git commit -m ":memo: Update usage from helpstring" |
| 173 | + git push origin HEAD:${GITHUB_REF} |
| 174 | + fi |
| 175 | + shell: bash |
0 commit comments