Skip to content

CI Build

CI Build #56

Workflow file for this run

name: CI Build
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- develop
env:
GRADLE_VERSION: 8.1.1
JAVA_DISTRIBUTION: "temurin"
JAVA_VERSION: "17"
run-name: ${{ github.ref == 'refs/heads/develop' && 'Develop Build' || 'CI Build' }}
jobs:
build-java:
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/develop' }}
steps:
- uses: actions/checkout@v3
- name: Setup Java 17
uses: actions/setup-java@v3
with:
distribution: $JAVA_DISTRIBUTION
java-version: $JAVA_VERSION
cache: "maven"
- name: Build all Java packages
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: build
- name: Resolve OpenEMS bundles
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: resolve
- name: Validate Bndrun files
run: |
git diff --exit-code io.openems.edge.application/EdgeApp.bndrun
git diff --exit-code io.openems.backend.application/BackendApp.bndrun
- name: Build JaCoCo Code-coverage-report
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: jacocoTestReport
- name: Summarize JaCoCo Report
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: "io.openems.*/generated/reports/jacoco/**/*.csv"
generate-summary: true
- name: Generate JaCoCo Badge
id: jacoco-badge
env:
PR_NUMBER: ${{ github.event.number }}
run: |
coverage=$(echo "scale=2; ${{ steps.jacoco.outputs.coverage }} * 100" | bc | cut -c1-4);
color=red;
if (( $(echo "$coverage > 95" | bc -l) )); then
color=success;
elif (( $(echo "$coverage > 80" | bc -l) )); then
color=green;
elif (( $(echo "$coverage > 95" | bc -l) )); then
color=yellow;
fi;
mkdir -p ./pr
echo '![Code Coverage]'"(https://img.shields.io/badge/Code%20Coverage-${coverage}%25-${color}?style=flat)" > ./pr/pr_badge
echo $PR_NUMBER > ./pr/pr_number
- name: Save JaCoCo Report
if: ${{ github.ref != 'refs/heads/develop' }}
uses: actions/upload-artifact@v3
with:
name: pr_comment
path: pr/
#
# Is this a Tag? Prepare release assets
#
- name: Prepare Edge+Backend assets
if: startsWith(github.ref, 'refs/tags/')
run: ./gradlew buildEdge buildBackend
- name: Save build-artifacts
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
build/openems-edge.jar
build/openems-backend.jar
build-ui:
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/develop' }}
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"
cache-dependency-path: "ui/package-lock.json"
- name: Build OpenEMS UI
run: |
cd ui
npm ci --prefer-offline --cache .npm
node_modules/.bin/ng config cli.cache.path .ng
node_modules/.bin/ng build -c "openems,openems-edge-prod,prod"
node_modules/.bin/ng lint
export CHROME_BIN=/usr/bin/google-chrome-stable
npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
#
# Is this a Tag? Prepare release assets
#
- name: Prepare UI asset
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir build
cd ui/target
zip -r ../../build/openems-ui.zip ./*
- name: Save build-artifacts
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: build/openems-ui.zip
#
# Is this a Tag? Create a draft release
#
release:
runs-on: ubuntu-latest
needs: [build-java, build-ui]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Load build-artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: build
- name: Create draft Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: |
build/openems-edge.jar
build/openems-backend.jar
build/openems-ui.zip
build-develop:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/develop' }}
steps:
- uses: actions/checkout@v3
- name: Setup Java 17
uses: actions/setup-java@v3
with:
distribution: $JAVA_DISTRIBUTION
java-version: $JAVA_VERSION
cache: "maven"
- name: Build all Java packages
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
cache-read-only: false
arguments: build --rerun-tasks
- name: Build JaCoCo Code-coverage-report
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: jacocoTestReport
- name: Summarize JaCoCo Report
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: "io.openems.*/generated/reports/jacoco/**/*.csv"
generate-summary: true
- name: Build Javadocs
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: buildAggregatedJavadocs --continue
- name: Build Antora-docs for openems.io
uses: gradle/gradle-build-action@v2
with:
gradle-version: $GRADLE_VERSION
arguments: buildAntoraDocs --continue
- name: Deploy to GitHub pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.DOCS }}
external_repository: OpenEMS/openems.io
publish_branch: master
publish_dir: build/www