Skip to content

Commit

Permalink
chore(cicd): setup ci/cd (#12)
Browse files Browse the repository at this point in the history
* wip: two workflow files

* feat: first check diffed file

* chore: build and deploy ci on push to main

* chore: build test ci on pr

* chore: finalize build script

* chore: finalize check

* chore: check all supported languages

* chore: add label
  • Loading branch information
henrylee97 authored Nov 8, 2023
1 parent 59d7448 commit 447a2bd
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build benchmark images

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io

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

permissions:
contents: read

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- id: find-targets
run: |
projects=$(git diff --name-only HEAD^ HEAD | 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/,*$//')
echo "targets=[$projects]" >> ${GITHUB_OUTPUT}
outputs:
targets: ${{ steps.find-targets.outputs.targets }}

build-and-deploy:

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

needs:
- find-targets

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

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

steps:
- uses: actions/checkout@v3
- name: Read metadata
id: read-metadata
run: |
content=$(cat ${{ matrix.target }}/metadata.json)
content="${content//$'\n'/''}"
echo "language=$(echo $content | jq -r .language)" >> ${GITHUB_OUTPUT}
echo "id=$(echo $content | jq -r .id)" >> ${GITHUB_OUTPUT}
- run: |
echo "${{steps.read-metadata.outputs.metadata}}"
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: ${{ matrix.target }}
file: ${{ matrix.target }}/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ env.REGISTRY }}/kupl/starlab-benchmarks/${{ steps.read-metadata.outputs.language }}:${{ steps.read-metadata.outputs.id }}
labels: |
org.opencontainers.image.source="https://github.com/kupl/starlab-benchmarks"
59 changes: 59 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build benchmark images

on:
pull_request:
branches:
- main

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

permissions:
contents: read

steps:
- uses: actions/checkout@v3
- id: find-targets
run: |
projects=$(git diff --name-only 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/,*$//')
echo "targets=[$projects]" >> ${GITHUB_OUTPUT}
outputs:
targets: ${{ steps.find-targets.outputs.targets }}


build-test:
runs-on: ubuntu-latest

permissions:
contents: read

needs:
- find-targets

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

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

steps:
- uses: actions/checkout@v3
- name: Read metadata
id: read-metadata
run: |
content=$(cat ${{ matrix.target }}/metadata.json)
content="${content//$'\n'/''}"
echo "buildCommand=$(echo $content | jq -r .buildCommand)" >> ${GITHUB_OUTPUT}
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: ${{ matrix.target }}
file: ${{ matrix.target }}/Dockerfile
platforms: linux/amd64
push: false
tags: benchmark:latest
- name: Smoke test
run: |
docker run --rm benchmark:latest ${{ steps.read-metadata.outputs.buildCommand }}

0 comments on commit 447a2bd

Please sign in to comment.