Skip to content

Commit 81138b8

Browse files
committed
filter based on frameworks
Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
1 parent 35aee5c commit 81138b8

File tree

2 files changed

+102
-84
lines changed

2 files changed

+102
-84
lines changed

.github/workflows/build_changed_images.yml

Lines changed: 49 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ on:
66
branches:
77
- ref_build_from_changed_files
88

9-
env:
10-
REGISTRY: ghcr.io
11-
framework: unikraft
12-
monitor: qemu
13-
149
jobs:
1510
get-changed-files:
16-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1712
outputs:
1813
apps: ${{ steps.filter.outputs.changes }}
19-
hello-world: ${{ steps.filter.outputs.hello-world }}
20-
hello-world_files: ${{ steps.filter.outputs.hello-world_files }}
14+
changed_json: ${{ steps.format.outputs.build }}
2115
steps:
2216
- name: Checkout code
2317
uses: actions/checkout@v3
@@ -30,89 +24,60 @@ jobs:
3024
token: ${{ secrets.GITHUB_TOKEN }}
3125
filters: |
3226
hello-world:
33-
- 'hello-world/src/**'
34-
- 'hello-world/rumprun/**'
35-
- 'hello-world/mirage/**'
36-
- 'hello-world/mewz/**'
37-
- 'hello-world/unikraft/**'
38-
- 'hello-world/linux/**'
27+
- 'hello-world/**'
28+
hello-env:
29+
- 'hello-env/**'
30+
hello-exec-env:
31+
- 'hello-exec-env/**'
32+
hello-server:
33+
- 'hello-server/**'
34+
httpreply:
35+
- 'httpreply/**'
36+
nginx:
37+
- 'nginx/**'
38+
redis:
39+
- 'redis/**'
40+
net:
41+
- 'net/**'
42+
block-test:
43+
- 'block-test/**'
44+
whoami:
45+
- 'whoami/**'
46+
busybox:
47+
- 'busybox/**'
48+
49+
- name: Format build json
50+
id: format
51+
run: |
52+
DIRS_TO_JSON=$(echo '${{ steps.filter.outputs.hello-world_files }}' | \
53+
jq -c 'reduce .[] as $path (
54+
{};
55+
($path | split("/")) as $parts |
56+
($parts[0:-1]) as $dirs |
57+
($parts[-1]) as $file |
58+
59+
reduce range(0; $dirs | length) as $i (
60+
.;
61+
setpath($dirs[0:$i+1]; getpath($dirs[0:$i+1]) // (if $i == (($dirs | length) - 1) then [] else {} end))
62+
) |
63+
setpath($dirs; (getpath($dirs) + [$file]))
64+
)'
65+
)
66+
echo "build=$DIRS_TO_JSON" >> "$GITHUB_OUTPUT"
3967
4068
- name: Show changed files
4169
run: |
42-
echo "Files in hello-world: ${{ steps.filter.outputs.hello-world_files }}"
4370
echo "Changes: ${{ steps.filter.outputs.changes }}"
71+
echo "Changed files in json: ${{ steps.format.outputs.build }}"
4472
45-
for-KVM-based-monitors:
46-
name: Build changed apps
73+
for-each-app:
74+
name: Track changes for each app
4775
needs: get-changed-files
48-
if: |
49-
needs.get-changed-files.outputs.hello-world_files != '' &&
50-
(
51-
contains(needs.get-changed-files.outputs.hello-world_files, 'src') ||
52-
contains(needs.get-changed-files.outputs.hello-world_files, 'unikraft')
53-
)
5476
strategy:
5577
fail-fast: false
5678
matrix:
57-
monitor: [qemu, firecracker]
58-
##apps: ${{ fromJSON(needs.get-chnaged-files.outputs.apps) }}
59-
uses: ./.github/workflows/build_and_manifest.yml
79+
app: ${{ fromJSON(needs.get-chnaged-files.outputs.apps) }}
80+
uses: ./.github/workflows/separate_apps.yml
6081
with:
61-
monitor: ${{ matrix.monitor }}
62-
secrets: inherit
63-
64-
## build-image:
65-
## name: Build and push image
66-
## needs: get-changed-files
67-
## if: |
68-
## needs.get-changed-files.outputs.hello-world_files != '' &&
69-
## (
70-
## contains(needs.get-changed-files.outputs.hello-world_files, 'src') ||
71-
## contains(needs.get-changed-files.outputs.hello-world_files, 'unikraft')
72-
## )
73-
## strategy:
74-
## matrix:
75-
## include:
76-
## - arch: amd64
77-
## runner: ubuntu-22.04
78-
## - arch: arm64
79-
## runner: ubuntu-22.04-arm
80-
## runs-on: ${{ matrix.runner }}
81-
## steps:
82-
## - name: Checkout code
83-
## uses: actions/checkout@v4
84-
## with:
85-
## fetch-depth: 0
86-
##
87-
## - name: Set short SHA
88-
## run: echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
89-
##
90-
## - name: Set up Docker Buildx
91-
## uses: docker/setup-buildx-action@v3
92-
##
93-
## - name: Log into registry ${{ env.REGISTRY }}
94-
## uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
95-
## with:
96-
## registry: ${{ env.REGISTRY }}
97-
## username: ${{ github.actor }}
98-
## password: ${{ secrets.GITHUB_TOKEN }}
99-
##
100-
## - name: Extract Docker metadata
101-
## id: meta
102-
## uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
103-
## with:
104-
## images: ${{ env.REGISTRY }}/${{ github.repository }}/hello-world-${{ env.monitor }}-${{ env.framework }}
105-
## tags: |
106-
## type=sha,prefix=${{ matrix.arch }}-,format=long
107-
##
108-
## - name: Build and push
109-
## id: build-and-push
110-
## uses: docker/build-push-action@v6
111-
## with:
112-
## context: ./hello-world/${{ env.framework }}
113-
## tags: ${{ steps.meta.outputs.tags }}
114-
## labels: ${{ steps.meta.outputs.labels }}
115-
## platforms: linux/${{ matrix.arch }}
116-
## push: true
117-
## provenance: false
118-
## file: ./hello-world/${{ env.framework }}/bunnyfile-${{ env.monitor }}-${{ matrix.arch }}
82+
app: ${{ matrix.app }}
83+
changed: ${{ needs.get-chnaged-files.outputs.changed_json }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Find the frameworks to build for an application
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
app:
7+
description: "The target application to build"
8+
type: string
9+
required: true
10+
changed:
11+
description: "The JSON object with all information for changed files"
12+
type: string
13+
required: true
14+
15+
jobs:
16+
get-changed-files:
17+
runs-on: ubuntu-22.04
18+
outputs:
19+
frameworks: ${{ steps.filter.outputs.frameworks }}
20+
frameworks_json: ${{ steps.filter.outputs.frameworks_json }}
21+
steps:
22+
- name: Get frameworks to build against
23+
id: filter
24+
run: |
25+
APP=${{ inputs.app }}
26+
FRAMEWORKS_JSON=$(echo '${{ inputs.changed }}' | \
27+
jq --arg app "$APP" '.[$app]'
28+
)
29+
FRAMEWORKS=$(echo '${{ inputs.changed }}' | \
30+
jq --arg app "$APP" '.[$app] | keys'
31+
)
32+
echo "frameworks=$FRAMEWORKS" >> "$GITHUB_OUTPUT"
33+
echo "frameworks_json=$FRAMEWORKS_JSON" >> "$GITHUB_OUTPUT"
34+
35+
- name: Show changed files
36+
run: |
37+
echo "Frameworks to build: ${{ steps.filter.outputs.frameworks }}"
38+
echo "frameworks json: ${{ steps.filter.outputs.frameworks_json }}"
39+
40+
for-KVM-based-monitors:
41+
name: Build changed apps
42+
needs: get-changed-files
43+
if: |
44+
needs.get-changed-files.outputs.frameworks != '' &&
45+
contains(needs.get-changed-files.outputs.frameworks 'unikraft')
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
monitor: [qemu, firecracker]
50+
##apps: ${{ fromJSON(needs.get-chnaged-files.outputs.apps) }}
51+
uses: ./.github/workflows/build_and_manifest.yml
52+
with:
53+
monitor: ${{ matrix.monitor }}

0 commit comments

Comments
 (0)