Skip to content

Commit 46603aa

Browse files
dcalavrezo-qorixAlexanderLanin
authored andcommitted
cicd: integrated reusable workflows
Integrated the reusable workflows in the module template Addresses: #6 Signed-off-by: Dan Calavrezo <[email protected]>
1 parent 0586e40 commit 46603aa

File tree

8 files changed

+88
-84
lines changed

8 files changed

+88
-84
lines changed

.github/workflows/copyright.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ on:
1919
types: [checks_requested]
2020
jobs:
2121
copyright-check:
22-
runs-on: ubuntu-latest
23-
steps:
24-
- name: Checkout repository
25-
uses: actions/[email protected]
26-
- name: Setup Bazel
27-
uses: bazel-contrib/[email protected]
28-
- name: Run copyright checks
29-
run: |
30-
bazel run //:copyright.check
22+
uses: eclipse-score/cicd-workflows/.github/workflows/copyright.yml@main
23+
with:
24+
bazel-target: "run //:copyright.check"

.github/workflows/license_check.yml

Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,16 @@ on:
1717
types: [opened, reopened, synchronize]
1818
merge_group:
1919
types: [checks_requested]
20-
jobs:
21-
license-check:
22-
runs-on: ubuntu-latest
23-
permissions:
24-
pull-requests: write
25-
issues: write
26-
steps:
27-
# ------------------------------------------------------------------------------
28-
# Checkout the correct branch safely in all scenarios (PRs, forks, merges)
29-
# ------------------------------------------------------------------------------
30-
# | Condition | Event Type | Checked Out Branch |
31-
# |----------------------------------------|--------------------|-----------------------|
32-
# | github.head_ref | pull_request_target | PR branch (source branch) |
33-
# | github.event.pull_request.head.ref | pull_request | PR branch (source branch) |
34-
# | github.ref | push, merge_group | The branch being pushed/merged |
35-
# ------------------------------------------------------------------------------
36-
# ------------------------------------------------------------------------------
37-
# Checkout the correct repository safely in all scenarios (PRs, forks, merges)
38-
# ------------------------------------------------------------------------------
39-
# | Condition | Event Type | Checked Out Repository |
40-
# |------------------------------------------------|--------------------|----------------------------------|
41-
# | github.event.pull_request.head.repo.full_name | pull_request | Forked repository (if PR is from a fork) |
42-
# | github.repository | push, merge_group | Default repository (same repo PRs, merges, pushes) |
43-
- name: Checkout repository (Handle all events)
44-
uses: actions/[email protected]
45-
with:
46-
ref: ${{ github.head_ref || github.event.pull_request.head.ref || github.ref }}
47-
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
48-
- name: Setup Bazel
49-
uses: bazel-contrib/[email protected]
50-
- name: Derive project shortname and repo URL
51-
run: |
52-
# Use a fixed shortname for the Dash project
53-
SHORTNAME="automotive.score"
54-
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
55-
echo "SHORTNAME=$SHORTNAME" >> $GITHUB_ENV
56-
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV
57-
- name: Run license checks
58-
run: |
59-
# The bash script won't fail on error. We capture the stderr and stdout and we save
60-
# the exit code of the bazel command in a variable
61-
# The output will also be stored in a file using the tee command
62-
# We save both output and exit code in the GH actions env file
63-
set +e # Ensure script does not exit on failure, even if the bazel run fails, the execution will continue
64-
OUTPUT=$(
65-
bazel run //docs:license.check.python -- \
66-
-review \
67-
-project "$SHORTNAME" \
68-
-repo "$REPO_URL" \
69-
-token "${{ secrets.ECLIPSE_GITLAB_API_TOKEN }}" 2>&1
70-
)
71-
EXIT_CODE=$?
72-
echo "$OUTPUT" | tee license-check-output.txt
73-
echo "exit_code=$EXIT_CODE" >> $GITHUB_ENV
74-
echo "output<<EOF" >> $GITHUB_ENV
75-
echo "$OUTPUT" >> $GITHUB_ENV
76-
echo "EOF" >> $GITHUB_ENV
77-
- name: Comment on PR with License Check Results
78-
if: github.event.pull_request
79-
uses: peter-evans/create-or-update-comment@v4
80-
with:
81-
issue-number: ${{ github.event.pull_request.number }}
82-
body: |
83-
### License Check Results
84-
🚀 The **license check preparation** job ran successfully.
85-
86-
**Status:** ${{ env.exit_code == 0 && '✅ Passed' || '⚠️ Needs Review' }}
8720

88-
<details>
89-
<summary>Click to expand output</summary>
21+
permissions:
22+
pull-requests: write
23+
issues: write
9024

91-
```
92-
${{ env.output }}
93-
```
9425

95-
</details>
96-
reactions: eyes
26+
jobs:
27+
license-check:
28+
uses: eclipse-score/cicd-workflows/.github/workflows/license-check.yml@main
29+
with:
30+
repo-url: "${{ github.server_url }}/${{ github.repository }}"
31+
secrets:
32+
dash-api-token: ${{ secrets.ECLIPSE_GITLAB_API_TOKEN }}

BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker")
14+
load("@dash_license_checker//:dash.bzl", "dash_license_checker")
15+
load("//:project_config.bzl", "PROJECT_CONFIG")
1416

1517
copyright_checker(
1618
name = "copyright",
@@ -24,3 +26,11 @@ copyright_checker(
2426
config = "@score_cr_checker//resources:config",
2527
visibility = ["//visibility:public"],
2628
)
29+
30+
31+
dash_license_checker(
32+
visibility = ["//visibility:public"],
33+
src = "//examples:cargo_lock",
34+
file_type = "", # let it auto-detect based on project_config
35+
project_config = PROJECT_CONFIG
36+
)

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ use_repo(llvm, "llvm_toolchain")
3636
use_repo(llvm, "llvm_toolchain_llvm")
3737

3838
register_toolchains("@llvm_toolchain//:all")
39+
40+
# Dash license checker
41+
bazel_dep(name = "dash_license_checker", version = "0.1.0")

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# C++ & Rust Bazel Template Repository
23

34
This repository serves as a **template** for setting up **C++ and Rust projects** using **Bazel**.
@@ -18,10 +19,12 @@ It provides a **standardized project structure**, ensuring best practices for:
1819
| `README.md` | Short description & build instructions |
1920
| `src/` | Source files for the module |
2021
| `tests/` | Unit tests (UT) and integration tests (IT) |
22+
| `examples/` | Example files used for guidance |
2123
| `docs/` | Documentation (Doxygen for C++ / mdBook for Rust) |
2224
| `.github/workflows/` | CI/CD pipelines |
2325
| `.vscode/` | Recommended VS Code settings |
2426
| `.bazelrc`, `MODULE.bazel`, `BUILD` | Bazel configuration & settings |
27+
| `project_config.bzl` | Project-specific metadata for Bazel macros |
2528
| `LICENSE.md` | Licensing information |
2629
| `CONTRIBUTION.md` | Contribution guidelines |
2730

@@ -38,7 +41,7 @@ cd YOUR_PROJECT
3841

3942
### 2️⃣ Build the Examples of module
4043

41-
> DISCLAMER: Depending what module implements, it's possible that different
44+
> DISCLAIMER: Depending what module implements, it's possible that different
4245
> configuration flags needs to be set on command line.
4346
4447
To build all targets of the module the following command can be used:
@@ -82,3 +85,30 @@ The template integrates **tools and linters** from **centralized repositories**
8285
## 📖 Documentation
8386

8487
- A **centralized docs structure** is planned.
88+
89+
---
90+
91+
## ⚙️ `project_config.bzl`
92+
93+
This file defines project-specific metadata used by Bazel macros, such as `dash_license_checker`.
94+
95+
### 📌 Purpose
96+
97+
It provides structured configuration that helps determine behavior such as:
98+
99+
- Source language type (used to determine license check file format)
100+
- Safety level or other compliance info (e.g. ASIL level)
101+
102+
### 📄 Example Content
103+
104+
```python
105+
PROJECT_CONFIG = {
106+
"asil_level": "QM", # or "ASIL-A", "ASIL-B", etc.
107+
"source_code": ["cpp", "rust"] # Languages used in the module
108+
}
109+
```
110+
111+
### 🔧 Use Case
112+
113+
When used with macros like `dash_license_checker`, it allows dynamic selection of file types
114+
(e.g., `cargo`, `requirements`) based on the languages declared in `source_code`.

examples/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Needed for Dash tool to check python dependency licenses.
2+
filegroup(
3+
name = "cargo_lock",
4+
srcs = [
5+
"Cargo.lock",
6+
],
7+
visibility = ["//visibility:public"],
8+
)

examples/Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project_config.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# project_config.bzl
2+
PROJECT_CONFIG = {
3+
"asil_level": "QM",
4+
"source_code": ["rust"]
5+
}

0 commit comments

Comments
 (0)