Skip to content

Commit

Permalink
Update Github workflows to run unit tests (#1)
Browse files Browse the repository at this point in the history
There is a unit test workflow for gating pull requests.
Then there is also a workflow that runs tests then builds/pushes to
docker if the tests pass.
  • Loading branch information
pvaneck authored Aug 9, 2021
1 parent 9eaddeb commit 079073f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
12 changes: 12 additions & 0 deletions .github/install-etcd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Fail on any error
set -e

ETCD_VERSION=v3.5.0
INSTALL_DIR="/usr/local/bin"

wget -q https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz
mkdir -p ${INSTALL_DIR}
tar xzf etcd-*-linux-amd64.tar.gz -C ${INSTALL_DIR} --strip-components=1
rm -rf etcd*.gz
41 changes: 24 additions & 17 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
name: Build and Push

on:
pull_request:
push:
branches: [ main ]
types: [closed]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Install etcd
run: sudo ./.github/install-etcd.sh
- name: Build with Maven
run: mvn -B package --file pom.xml
build:
if: github.event.pull_request.merged == true
needs: test
runs-on: ubuntu-latest

env:
IMAGE_NAME: kserve/modelmesh
IMAGE_TAG: latest
steps:
- uses: actions/checkout@v2
- name: Build runtime image
- name: Build runtime image
run: |
GIT_COMMIT=$(git rev-parse HEAD)
BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5)
IMAGE_TAG=main_${BUILD_ID}
BASE_IMAGE_TAG=$(cat BASE_IMAGE_TAG | awk -F= '{print $2}')
docker build -t modelmesh:${IMAGE_TAG} \
docker build -t ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
--build-arg imageVersion=${IMAGE_TAG} \
--build-arg buildId=${BUILD_ID} \
--build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} \
--build-arg commitSha=${GIT_COMMIT} .
- name: Log in to docker hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: Push to docker hub
- name: Push to Docker Hub
run: |
IMAGE_NAME=modelmesh
IMAGE_ID=kserve/$IMAGE_NAME
IMAGE_VERSION=latest
docker push $IMAGE_ID:$IMAGE_VERSION
docker push ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
29 changes: 11 additions & 18 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
name: Unit Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [ main ]

jobs:
build:

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build and test
run: |
GIT_COMMIT=$(git rev-parse HEAD)
BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5)
IMAGE_TAG=main_${BUILD_ID}
BASE_IMAGE_TAG=$(cat BASE_IMAGE_TAG | awk -F= '{print $2}')
docker build -t modelmesh:${IMAGE_TAG} \
--build-arg imageVersion=${IMAGE_TAG} \
--build-arg buildId=${BUILD_ID} \
--build-arg BASE_IMAGE_TAG=${BASE_IMAGE_TAG} \
--build-arg commitSha=${GIT_COMMIT} .
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Install etcd
run: sudo ./.github/install-etcd.sh
- name: Build with Maven
run: mvn -B package --file pom.xml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LABEL image="build"

COPY / /build

RUN mvn -Dmaven.repo.local=repo -DskipTests=true -B clean install
RUN mvn -B package -DskipTests=true --file pom.xml

###############################################################################
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,6 @@ public static int getPID(Process process) throws Exception {

public static int killProcess(Process process) throws Exception {
int pid = getPID(process);
return Runtime.getRuntime().exec("command kill -9 " + pid).waitFor();
return Runtime.getRuntime().exec("kill -9 " + pid).waitFor();
}
}

0 comments on commit 079073f

Please sign in to comment.