-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
118 lines (113 loc) · 4.12 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Define the pipeline stages
stages:
# Stage for validating code formatting
- check
# Stage for validating firmware compilation
- build
# Workflow rules determine when the pipeline should run
workflow:
rules:
# Run pipeline on merge requests
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
# Run pipeline on tagged commits
- if: $CI_COMMIT_TAG
# Run pipeline on commits to the default branch
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Job to check code formatting
check_formatting:
# Docker image with formatting tools
image: registry.gitlab.leaflabs.com/internal-projects/holiday-widget/code-format
# Job can be interrupted by other jobs
interruptible: true
# Assign job to the 'check' stage
stage: check
variables:
# Directory in which to enforce formatting
ENFORCE_FORMAT_DIR: 'firmware'
script:
# Fetch the latest changes from the remote repository
- git fetch
# Check formatting against the target branch
- git-clang-format -v --commit origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME -q --diff -- $ENFORCE_FORMAT_DIR
only:
# Only run this job for merge requests
- merge_requests
# Job to build the firmware
build_firmware:
# Docker image with build tools
image: registry.gitlab.leaflabs.com/internal-projects/holiday-widget/build-firmware
# Assign job to the 'build' stage
stage: build
tags:
# Tag to specify runner with Linux environment
- linux
before_script:
# Generate a unique fixed-length submodule hash:
# - Gather the name and current commit hash of each
# submodule and concatenate them into a single string
# - Generate a SHA-256 hash of the concatenated string
# - Extract the hash and assign it to the $SUBMODULE_HASH variable
#
# This is done to ensure a consistent format and length for the cache key
- |
SUBMODULE_HASH=$(git submodule foreach 'echo $name `git rev-parse HEAD`' | sha256sum | cut -d' ' -f1)
echo "Submodule hash: $SUBMODULE_HASH"
cache:
# Unique fixed-length cache key based on the submodule hash
key: "submodule-cache-${SUBMODULE_HASH}"
paths:
# Cache the Git submodules
- .git/modules/
# Cache the Git configuration
- .git/config
artifacts:
paths:
# Artifact: compiled firmware binary
- blink.elf
# Artifact: lookup table generator binary
- lut_generator
script:
# Recursively initialize and update submodules
- git submodule update --init --recursive
# Enter the 'firmware' directory
- cd firmware
# Clean previous build artifacts
- make clean
# Build the firmware
- make
# Copy the firmware binary to the root directory
- cp build/blink.elf ../blink.elf
# Copy the generated lookup tables to the root directory
- cp build/lut_generator ../lut_generator
# Generate diffs for PCB project
.generate_hardware_diffs_template: &generate_hardware_diffs_template
image:
name: leoheck/kiri:latest
docker:
user: root
stage: check
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
changes:
- $PROJECT_DIR/**/*
artifacts:
paths:
- $PROJECT_DIR/.kiri
before_script:
- export PATH=$PATH:/home/kiri/.local/share/kiri/bin/:/home/kiri/.local/share/kiri/submodules/KiCad-Diff/bin:/home/kiri/bin
- export TERM=xterm
- apt update && apt install -y curl
- export
script:
- kiri --no-server -o $(git rev-parse --short $CI_MERGE_REQUEST_DIFF_BASE_SHA) $PROJECT_DIR/$PROJECT_FILE
- >-
curl --location \
--request POST "https://gitlab.leaflabs.com/api/v4/projects/$CI_MERGE_REQUEST_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes" \
--header "PRIVATE-TOKEN: $PROJECT_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data-raw "{ \"body\": \"Board Diff for [$PROJECT_DIR - $CI_PIPELINE_ID](https://$CI_PROJECT_NAMESPACE.pages.leaflabs.com/-/holiday-widget/-/jobs/$CI_JOB_ID/artifacts/$PROJECT_DIR/.kiri/web/index.html)\" }"
generate_widget_diffs:
<<: *generate_hardware_diffs_template
variables:
PROJECT_DIR: hardware
PROJECT_FILE: holiday-widget.kicad_pro