Skip to content

Commit 353e03e

Browse files
committed
Add ibex instructions to README, fix gh actions rebuild issue
1 parent 6b940f9 commit 353e03e

File tree

2 files changed

+84
-48
lines changed

2 files changed

+84
-48
lines changed

.github/workflows/verify.yml

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,107 @@ permissions:
99

1010
env:
1111
GHCR_IMAGE: ghcr.io/kastnerrg/cgra4ml-ibex
12-
IMAGE_TAG: latest
1312

1413
jobs:
1514
build-and-push-image:
1615
runs-on: ubuntu-22.04
1716

1817
outputs:
19-
docker_changed: ${{ steps.check-changes.outputs.docker_changed }}
18+
image_tag: ${{ steps.meta.outputs.image_tag }}
19+
image_exists: ${{ steps.check.outputs.image_exists }}
2020

2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 0
2626

27-
- id: check-changes
28-
name: Detect Docker / env changes
27+
- id: meta
28+
name: Compute Docker inputs hash -> image tag
2929
shell: bash
3030
run: |
31-
set -e
32-
33-
BEFORE="${{ github.event.before }}"
34-
SHA="${{ github.sha }}"
35-
36-
# First push to branch (no "before" commit)? Force rebuild.
37-
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
38-
echo "First push on this branch -> rebuild image"
39-
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
40-
exit 0
41-
fi
42-
43-
echo "Diffing $BEFORE..$SHA"
44-
45-
# If BEFORE commit is not in this clone (rebased branch / force push / shallow mismatch),
46-
# just force a rebuild instead of trying to diff.
47-
if ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
48-
echo "Base commit $BEFORE not found in local history -> rebuild image"
49-
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
50-
exit 0
51-
fi
52-
53-
files="$(git diff --name-only "$BEFORE" "$SHA")"
54-
echo "Changed files:"
55-
echo "$files"
56-
57-
if echo "$files" | grep -E '^(Dockerfile|Makefile|pyproject.toml|ibex-soc/python-requirements.txt|ibex-soc/vendor/google_riscv-dv/requirements.txt)$' >/dev/null; then
58-
echo "Docker / env inputs changed -> rebuild"
59-
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
60-
else
61-
echo "No Dockerfile/Makefile/pyproject/req changes -> reuse existing image"
62-
echo "docker_changed=false" >> "$GITHUB_OUTPUT"
63-
fi
31+
set -euo pipefail
32+
33+
# Only these files affect the image tag. Add/remove paths as desired.
34+
inputs=(
35+
Dockerfile
36+
Makefile
37+
pyproject.toml
38+
ibex-soc/python-requirements.txt
39+
ibex-soc/vendor/google_riscv-dv/requirements.txt
40+
)
41+
42+
tmp="$(mktemp)"
43+
for f in "${inputs[@]}"; do
44+
if [ -f "$f" ]; then
45+
{
46+
echo ">>>FILE:$f"
47+
cat "$f"
48+
echo
49+
} >> "$tmp"
50+
else
51+
echo "WARN: missing $f (ignored)"
52+
fi
53+
done
54+
55+
hash="$(sha256sum "$tmp" | awk '{print $1}')"
56+
short="${hash:0:16}"
57+
tag="ci-${short}"
58+
59+
echo "Computed hash: $hash"
60+
echo "Using tag: $tag"
61+
62+
echo "image_tag=$tag" >> "$GITHUB_OUTPUT"
6463
6564
- name: Log in to GHCR
66-
if: steps.check-changes.outputs.docker_changed == 'true'
6765
uses: docker/login-action@v3
6866
with:
6967
registry: ghcr.io
7068
username: ${{ github.actor }}
7169
password: ${{ secrets.GITHUB_TOKEN }}
7270

73-
- name: Build Docker image via Makefile
74-
if: steps.check-changes.outputs.docker_changed == 'true'
71+
- id: check
72+
name: Check if image tag already exists in GHCR
7573
shell: bash
7674
run: |
77-
# Build using your top-level Makefile, but tag with GHCR_IMAGE:dev
78-
make IMAGE="${GHCR_IMAGE}:dev" image
79-
docker tag "${GHCR_IMAGE}:dev" "${GHCR_IMAGE}:${IMAGE_TAG}"
75+
set -euo pipefail
76+
tag="${{ steps.meta.outputs.image_tag }}"
8077
81-
- name: Push image to GHCR
82-
if: steps.check-changes.outputs.docker_changed == 'true'
78+
if docker manifest inspect "${GHCR_IMAGE}:${tag}" >/dev/null 2>&1; then
79+
echo "Image exists: ${GHCR_IMAGE}:${tag}"
80+
echo "image_exists=true" >> "$GITHUB_OUTPUT"
81+
else
82+
echo "Image missing: ${GHCR_IMAGE}:${tag}"
83+
echo "image_exists=false" >> "$GITHUB_OUTPUT"
84+
fi
85+
86+
- name: Build Docker image (only if missing)
87+
if: steps.check.outputs.image_exists == 'false'
8388
shell: bash
84-
run: docker push "${GHCR_IMAGE}:${IMAGE_TAG}"
89+
run: |
90+
set -euo pipefail
91+
tag="${{ steps.meta.outputs.image_tag }}"
92+
93+
# Build using your Makefile; tag directly with the content-hash tag.
94+
make IMAGE="${GHCR_IMAGE}:${tag}" image
95+
96+
# Optional: also tag as "latest" whenever we build a new hash-tag.
97+
docker tag "${GHCR_IMAGE}:${tag}" "${GHCR_IMAGE}:latest"
98+
99+
- name: Push image to GHCR (only if built)
100+
if: steps.check.outputs.image_exists == 'false'
101+
shell: bash
102+
run: |
103+
set -euo pipefail
104+
tag="${{ steps.meta.outputs.image_tag }}"
105+
docker push "${GHCR_IMAGE}:${tag}"
106+
docker push "${GHCR_IMAGE}:latest"
85107
86108
smoke-test:
87109
runs-on: ubuntu-22.04
88110
needs: build-and-push-image
111+
env:
112+
IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }}
89113

90114
steps:
91115
- name: Checkout code
@@ -123,7 +147,9 @@ jobs:
123147
124148
verify-ibex-soc:
125149
runs-on: ubuntu-22.04
126-
needs: smoke-test
150+
needs: [build-and-push-image, smoke-test]
151+
env:
152+
IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }}
127153

128154
steps:
129155
- name: Checkout code

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@ source vivado_flow.tcl
8888
- Add a breakpoint at `model_setup()`. When breakpoint hits, load `run/work/vectors/wbx.bin` to the address printed.
8989
- Continue - This will run the model and print outputs & execution time
9090

91-
4. ASIC implementation with Cadence Genus & Innovus:
91+
4. Ibex SoC Integration
92+
93+
```
94+
make image start enter # build, start & enter docker container
95+
# make kill # kill and delete the container
96+
97+
# Inside the container
98+
make smoke_ibex # build, run ibex SoC simulation, verify outputs
99+
```
100+
101+
5. ASIC implementation with Cadence Genus & Innovus:
92102
```bash
93103
# First add your PDK to 'asic/pdk', change paths in the scripts and run:
94104
cd run/work

0 commit comments

Comments
 (0)