Update makefile, change actions into matrix #588
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: Verify | ||
| on: | ||
| push: | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| env: | ||
| GHCR_IMAGE: ghcr.io/kastnerrg/cgra4ml-ibex | ||
| jobs: | ||
| build-and-push-image: | ||
| runs-on: ubuntu-22.04 | ||
| outputs: | ||
| image_tag: ${{ steps.meta.outputs.image_tag }} | ||
| image_exists: ${{ steps.check.outputs.image_exists }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - id: meta | ||
| name: Compute Docker inputs hash -> image tag | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| # Only these files affect the image tag. Add/remove paths as desired. | ||
| inputs=( | ||
| Dockerfile | ||
| Makefile | ||
| pyproject.toml | ||
| ibex-soc/python-requirements.txt | ||
| ) | ||
| tmp="$(mktemp)" | ||
| for f in "${inputs[@]}"; do | ||
| if [ -f "$f" ]; then | ||
| { | ||
| echo ">>>FILE:$f" | ||
| cat "$f" | ||
| echo | ||
| } >> "$tmp" | ||
| else | ||
| echo "WARN: missing $f (ignored)" | ||
| fi | ||
| done | ||
| hash="$(sha256sum "$tmp" | awk '{print $1}')" | ||
| short="${hash:0:16}" | ||
| tag="ci-${short}" | ||
| echo "Computed hash: $hash" | ||
| echo "Using tag: $tag" | ||
| echo "image_tag=$tag" >> "$GITHUB_OUTPUT" | ||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - id: check | ||
| name: Check if image tag already exists in GHCR | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| tag="${{ steps.meta.outputs.image_tag }}" | ||
| if docker manifest inspect "${GHCR_IMAGE}:${tag}" >/dev/null 2>&1; then | ||
| echo "Image exists: ${GHCR_IMAGE}:${tag}" | ||
| echo "image_exists=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "Image missing: ${GHCR_IMAGE}:${tag}" | ||
| echo "image_exists=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| - name: Build Docker image (only if missing) | ||
| if: steps.check.outputs.image_exists == 'false' | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| tag="${{ steps.meta.outputs.image_tag }}" | ||
| # Build using your Makefile; tag directly with the content-hash tag. | ||
| make IMAGE="${GHCR_IMAGE}:${tag}" image | ||
| # Optional: also tag as "latest" whenever we build a new hash-tag. | ||
| docker tag "${GHCR_IMAGE}:${tag}" "${GHCR_IMAGE}:latest" | ||
| - name: Push image to GHCR (only if built) | ||
| if: steps.check.outputs.image_exists == 'false' | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| tag="${{ steps.meta.outputs.image_tag }}" | ||
| docker push "${GHCR_IMAGE}:${tag}" | ||
| docker push "${GHCR_IMAGE}:latest" | ||
| smoke-test: | ||
| runs-on: ubuntu-22.04 | ||
| needs: build-and-push-image | ||
| env: | ||
| IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Free disk space on runner | ||
| run: | | ||
| echo "Before cleanup:"; df -h | ||
| sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true | ||
| sudo apt-get clean || true | ||
| sudo rm -rf /var/lib/apt/lists/* || true | ||
| docker system prune -af || true | ||
| echo "After cleanup:"; df -h | ||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Pull CI image | ||
| run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}" | ||
| - name: Smoke test (param_test) | ||
| run: | | ||
| docker run --rm \ | ||
| -v "$PWD":/work \ | ||
| -w /work \ | ||
| "${GHCR_IMAGE}:${IMAGE_TAG}" \ | ||
| bash -c ' | ||
| make smoke_test TEST=param_test | ||
| ' | ||
| unit-tests: | ||
| runs-on: ubuntu-22.04 | ||
| needs: [build-and-push-image, smoke-test] | ||
| env: | ||
| IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - name: example | ||
| cmd: | | ||
| mkdir -p run/work | ||
| cd run/work | ||
| python ../example.py | ||
| - name: pointnet | ||
| cmd: make clean smoke_test TEST=pointnet | ||
| # - name: resnet50 | ||
| # cmd: make clean smoke_test TEST=resnet50 | ||
| # - name: resnet18 | ||
| # cmd: make clean smoke_test TEST=resnet18 | ||
| # - name: jettagger | ||
| # cmd: make clean smoke_test TEST=jettagger | ||
| - name: verify-ibex-soc | ||
| cmd: | | ||
| fusesoc library add sa_ip "$(pwd -P)" || true | ||
| make smoke_ibex | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Free disk space on runner | ||
| run: | | ||
| echo "Before cleanup:"; df -h | ||
| sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true | ||
| sudo apt-get clean || true | ||
| sudo rm -rf /var/lib/apt/lists/* || true | ||
| docker system prune -af || true | ||
| echo "After cleanup:"; df -h | ||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Pull CI image | ||
| run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}" | ||
| - name: Run ${{ matrix.name }} | ||
| run: | | ||
| docker run --rm \ | ||
| -v "$PWD":/work \ | ||
| -w /work \ | ||
| "${GHCR_IMAGE}:${IMAGE_TAG}" \ | ||
| bash -c '${{ matrix.cmd }}' | ||