Merge pull request #541 from QIICR/dcmqi_labelmap_background #268
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: C/C++ CI Linux | |
| on: | |
| push: | |
| branches: [ "master" ] | |
| pull_request: | |
| branches: [ "master" ] | |
| release: | |
| types: [ published ] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| deployments: write | |
| packages: write | |
| jobs: | |
| build-linux: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 40 | |
| permissions: | |
| contents: write | |
| actions: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10.11' | |
| - name: "Install jsondiff" | |
| run: pip install jsondiff | |
| - name: "Install cmake" | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install rsync | |
| sudo apt-get install cmake | |
| # Set up Docker Buildx for better caching support | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Cache the build directory containing all external dependencies | |
| - name: Cache build directory | |
| id: cache-build-dir | |
| uses: actions/cache@v4 | |
| env: | |
| cache-name: cache-build-artifacts | |
| with: | |
| path: | | |
| build/ | |
| /tmp/dockcross | |
| # Cache key includes hash of CMakeExternals files and Makefile | |
| # to invalidate when dependencies or build process changes | |
| key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('CMakeExternals/DCMTK.cmake', 'CMakeExternals/ITK.cmake', 'CMakeExternals/zlib.cmake', 'docker/Makefile') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ env.cache-name }}- | |
| # Report cache status | |
| - name: Report cache status | |
| run: | | |
| if [ "${{ steps.cache-build-dir.outputs.cache-hit }}" == "true" ]; then | |
| echo "✓ Cache hit! Using cached build artifacts" | |
| echo "Cache key: ${{ steps.cache-build-dir.outputs.cache-primary-key }}" | |
| if [ -d build ]; then | |
| echo "Build directory size:" | |
| du -sh build/ 2>/dev/null || true | |
| echo "Build directory contents:" | |
| ls -lh build/ 2>/dev/null || true | |
| fi | |
| if [ -f /tmp/dockcross ]; then | |
| echo "✓ Dockcross script cached" | |
| fi | |
| else | |
| echo "✗ Cache miss. Will build all dependencies from source" | |
| fi | |
| - name: "Build dcmqi" | |
| run: | | |
| cd docker && make dcmqi | |
| - name: "Test dcmqi" | |
| run: | | |
| cd docker && make dcmqi.test | |
| - name: "Publish docker image" | |
| # Only run if the event is not a pull request and the repository owner is QIICR. | |
| # The latter is to prevent forks from publishing packages even if the owner's token | |
| # would have sufficient privileges. | |
| if: ${{ (github.event_name != 'pull_request') && (github.repository_owner == 'QIICR')}} | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} && \ | |
| docker push qiicr/dcmqi:`git describe --tags --exact-match 2> /dev/null || echo "latest"` \ | |
| || echo "skipping docker push" | |
| - name: "Upload package as artifact" | |
| id: upload-artifact | |
| uses: actions/upload-artifact@v4 | |
| continue-on-error: true | |
| with: | |
| name: dcmqi-linux-package | |
| path: build/dcmqi-build/dcmqi-*-linux*.tar.gz | |
| - name: "Upload package as artifact (retry)" | |
| if: steps.upload-artifact.outcome == 'failure' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dcmqi-linux-package | |
| path: build/dcmqi-build/dcmqi-*-linux*.tar.gz | |
| - name: "Publish linux package" | |
| # Only run if the event is not a pull request and the repository owner is QIICR. | |
| # The latter is to prevent forks from publishing packages even if the owner's token | |
| # would have sufficient privileges. | |
| if: ${{ (github.event_name != 'pull_request') && (github.repository_owner == 'QIICR')}} | |
| env: | |
| GH_TOKEN: ${{ secrets.GA_TOKEN }} | |
| run: | | |
| TAG=$(git describe --tags --exact-match 2>/dev/null || echo "") | |
| if [ -n "$TAG" ]; then | |
| gh release upload "$TAG" \ | |
| build/dcmqi-build/dcmqi-*-linux.tar.gz \ | |
| --clobber | |
| else | |
| gh release view latest --json assets --jq '.assets[].name' 2>/dev/null \ | |
| | grep "dcmqi-.*-linux-" \ | |
| | xargs -I{} gh release delete-asset latest "{}" --yes || true | |
| gh release upload latest \ | |
| build/dcmqi-build/dcmqi-*-linux*.tar.gz \ | |
| --clobber | |
| gh release edit latest --target $(git rev-parse HEAD) | |
| fi |