Skip to content

Commit

Permalink
chore(cicd): make base image build step
Browse files Browse the repository at this point in the history
  • Loading branch information
henrylee97 committed Nov 28, 2023
1 parent 10ba1d4 commit 3bf00cd
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,105 @@ on:
- main

jobs:
find-targets:
find-updated-benchmarks:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- uses: actions/checkout@v4
- run: |
git fetch origin
- id: find-base-updates
run: |
bases=$(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep -e "^OCaml-base/" -e "^Java-base/" -e "^C-base/" -e "^Solidity-base/" | cut -d '/' -f 1-2 | sort | uniq)
{
for base in $base; do
base=$(echo $base | sed 's/-base//')
ls $base-*
done
} > updated.txt
- id: find-benchmark-updates
run: |
git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep -e "^OCaml/" -e "^Java/" -e "^C/" -e "^Solidity/" | cut -d '/' -f 1-2 | sort | uniq > updated.txt
- id: find-targets
run: |
git fetch origin
projects=$(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep -e "^OCaml/" -e "^Java/" -e "^C/" -e "^Solidity/" | cut -d '/' -f 1-2 | sort | uniq | xargs -I{prj} echo \"{prj}\" | tr '\n' ',' | sed 's/,*$//')
targets=$(cat updated.txt | xargs -I{prj} echo \"{prj}\" | tr '\n' ',' | sed 's/,*$//')
echo "targets=[$projects]" >> ${GITHUB_OUTPUT}
outputs:
targets: ${{ steps.find-targets.outputs.targets }}


build-test:
benchmarks-build-test:
runs-on: ubuntu-latest

permissions:
contents: read

needs:
- find-targets
- find-updated-benchmarks

if: always() && needs.find-targets.outputs.targets != '[]'
if: needs.find-updated-benchmarks.outputs.targets != '[]'

strategy:
matrix:
target: ${{ fromJSON(needs.find-targets.outputs.targets) }}
target: ${{ fromJSON(needs.find-updated-benchmarks.outputs.targets) }}

steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3

- name: Check if base image exists
id: check-if-base-image-exists
run: |
lang=$(echo ${{ matrix.target }} | cut -d '-' -f 1)
proj=$(echo ${{ matrix.target }} | cut -d '-' -f 2)
if [ -d ${lang}-base/${proj} ]; then
echo "base=${lang}-base/${proj}" >> ${GITHUB_OUTPUT}
else
echo "base=" >> ${GITHUB_OUTPUT}
fi
- name: Build base image
id: build-base-image
if: steps.check-if-base-image-exists.outputs.base != ''
uses: docker/build-push-action@v5
with:
context: ${{ steps.check-if-base-image-exists.outputs.base }}
file: ${{ steps.check-if-base-image-exists.outputs.base }}/Dockerfile
platforms: linux/amd64
push: false
tags: base:latest
outputs: type=docker,dest=./base.tar

- name: Read metadata
id: read-metadata
run: |
content=$(cat ${{ matrix.target }}/metadata.json)
content="${content//$'\n'/''}"
echo "location=$(echo $content | jq -r .buggyPath)" >> ${GITHUB_OUTPUT}
echo "buildCommand=$(echo $content | jq -r .buildCommand)" >> ${GITHUB_OUTPUT}
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
if: steps.check-if-base-image-exists.outputs.base == ''
with:
context: ${{ matrix.target }}
file: ${{ matrix.target }}/Dockerfile
platforms: linux/amd64
push: false
tags: benchmark:latest
outputs: type=docker,dest=./image.tar
- uses: docker/build-push-action@v5
if: steps.check-if-base-image-exists.outputs.base != ''
with:
context: ${{ matrix.target }}
file: ${{ matrix.target }}/Dockerfile
platforms: linux/amd64
push: false
tags: benchmark:latest
outputs: type=docker,dest=./image.tar
cache-from: type=local,src=./base.tar

- name: Smoke test
run: |
docker load --input ./image.tar
Expand All @@ -69,7 +117,7 @@ jobs:
pull-requests: write

needs:
- build-test
- benchmarks-build-test

if: always()

Expand Down

0 comments on commit 3bf00cd

Please sign in to comment.