Skip to content

Commit 7223fa6

Browse files
authored
GitHub actions (#3)
* Add github workflow * Move fileTree call out of doLast * Add license header * Remove author and description in actions
1 parent 4275bbf commit 7223fa6

4 files changed

Lines changed: 179 additions & 3 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: create-build-tag
6+
7+
outputs:
8+
build_tag:
9+
description: 'The generated build tag'
10+
value: ${{ steps.create-build-tag.outputs.build_tag }}
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Create build tag
15+
id: create-build-tag
16+
env:
17+
# head_ref is available when a pull request triggers workflow, ref_name contains branch name outside of pull requests
18+
BRANCH_NAME_RAW: ${{ github.head_ref || github.ref_name }}
19+
COMMIT_SHA_RAW: ${{ github.sha }}
20+
run: |
21+
DATETIME=`date -u +"%Y-%m-%dT%H-%M-%S"`
22+
BRANCH_NAME=`echo "${BRANCH_NAME_RAW}" | cut -c1-20 | sed 's|/|-|g'`
23+
COMMIT_SHA=`echo "${COMMIT_SHA_RAW}" | cut -c 1-7`
24+
echo "build_tag=${BRANCH_NAME}-${DATETIME}-${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
25+
shell: bash
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Java & Gradle Setup
6+
description: Setup runtime
7+
8+
inputs:
9+
java_version:
10+
description: 'The Java version to install.'
11+
required: false
12+
default: '25'
13+
gradle_version:
14+
description: 'The Gradle version to install. It do not force using this gradle version in other workflow steps, normally the installed gradle version of the project will be used.'
15+
required: false
16+
default: '9.1.0'
17+
fetch-depth:
18+
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
19+
default: '1'
20+
enable_caching:
21+
description: 'If build and configuration caching should be enabled or disabled.'
22+
default: 'true'
23+
enable_daemon:
24+
description: 'If build should be done using a separate gradle daemon.'
25+
default: 'false'
26+
27+
runs:
28+
using: "composite"
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
32+
with:
33+
fetch-depth: ${{ inputs.fetch-depth }}
34+
35+
- name: Set up JDK
36+
uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # 5.6.0
37+
with:
38+
java-version: ${{ inputs.java_version }}
39+
distribution: 'zulu'
40+
41+
- name: Setup Gradle
42+
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # 6.2.0
43+
with:
44+
gradle-version: ${{ inputs.gradle_version }}
45+
46+
- name: Cache Gradle
47+
if: ${{ inputs.enable_caching == 'true' }}
48+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0
49+
with:
50+
path: |
51+
~/.gradle/caches
52+
~/.gradle/wrapper
53+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/settings.gradle*') }}
54+
restore-keys: |
55+
${{ runner.os }}-gradle-
56+
57+
- name: Configure Gradle properties
58+
shell: bash
59+
env:
60+
CACHING: ${{ inputs.enable_caching }}
61+
DAEMON: ${{ inputs.enable_daemon }}
62+
run: |
63+
set -euo pipefail
64+
mkdir -p ~/.gradle
65+
{
66+
echo "ci=true"
67+
echo "org.gradle.caching=${CACHING}"
68+
echo "org.gradle.configuration-cache=${CACHING}"
69+
echo "org.gradle.daemon=${DAEMON}"
70+
} >> ~/.gradle/gradle.properties
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Java CI with Gradle for library
6+
7+
on:
8+
push:
9+
workflow_dispatch:
10+
inputs:
11+
local_image_tag:
12+
description: Local image tag used before push
13+
required: false
14+
type: string
15+
default: application:0.0.1-SNAPSHOT
16+
deploy_branch:
17+
description: Branch required to push image
18+
required: false
19+
type: string
20+
default: main
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
build-and-test:
28+
name: Build & Test
29+
runs-on: ubuntu-latest
30+
permissions:
31+
id-token: write # Needed to load credentials
32+
contents: read # Needed to read repository (content)
33+
outputs:
34+
build_tag: ${{ steps.create_tag.outputs.build_tag }}
35+
environment:
36+
name: ci
37+
env:
38+
LOCAL_IMAGE_TAG: ${{ inputs.local_image_tag }}
39+
DEPLOY_BRANCH: ${{ inputs.deploy_branch }}
40+
IMAGE_REPOSITORY_PREFIX: ${{ inputs.image_repository_prefix }}${{ inputs.namespace }}
41+
IS_TAG: ${{ github.ref_type == 'tag' }}
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
45+
with:
46+
fetch-depth: 1
47+
persist-credentials: false
48+
49+
- name: Setup runtime
50+
uses: ./.github/actions/setup-runtime
51+
52+
- name: Cache Gradle
53+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0
54+
with:
55+
path: |
56+
~/.gradle/caches
57+
~/.gradle/wrapper
58+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/settings.gradle*') }}
59+
60+
- name: Optimize Gradle
61+
shell: bash
62+
run: |
63+
mkdir -p ~/.gradle
64+
echo "org.gradle.caching=true" >> ~/.gradle/gradle.properties
65+
echo "org.gradle.configuration-cache=true" >> ~/.gradle/gradle.properties
66+
67+
- name: Build & Run Tests
68+
run: ./gradlew build --configuration-cache
69+
70+
- name: Create Build Tag
71+
id: create_tag
72+
uses: ./.github/actions/create-build-tag
73+
74+
- name: Repository Name
75+
id: repo
76+
shell: bash
77+
run: |
78+
echo "name=${GITHUB_REPOSITORY#*/}" >> "$GITHUB_OUTPUT"

build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ tasks.register("generatePGMBindings") {
266266
headersDir.file("power_grid_model_c/dataset_definitions.h")
267267
)
268268
outputs.dir(generatedJavaDir)
269+
def jextractExecutables = fileTree(jextractDir) {
270+
include "**/bin/*"
271+
}
269272
doLast {
270273
def jextractBin
271274
if (localJextractBin) {
@@ -274,9 +277,9 @@ tasks.register("generatePGMBindings") {
274277
def executableName = osName.contains("windows")
275278
? "jextract.exe"
276279
: "jextract"
277-
def jextractBins = fileTree(jextractDir) {
278-
include "**/bin/$executableName"
279-
}.files
280+
def jextractBins = jextractExecutables.files.findAll() {
281+
it.name == executableName
282+
}
280283
if (jextractBins.size() != 1) {
281284
throw new GradleException(
282285
"Expected exactly one Jextract executable, " +

0 commit comments

Comments
 (0)