Skip to content

Commit 32fa576

Browse files
committed
ci: using earthly locally and in CICD
1 parent e958363 commit 32fa576

File tree

2 files changed

+88
-35
lines changed

2 files changed

+88
-35
lines changed

.gitlab-ci.yml

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,65 @@ stages:
77
- unit-testing
88

99

10+
services:
11+
- docker:dind
12+
13+
14+
variables:
15+
DOCKER_HOST: tcp://docker:2375
16+
EARTHLY_EXEC_CMD: "/bin/sh"
17+
18+
19+
image: earthly/earthly:v0.6.22
20+
21+
1022
clean-git-history-checking:
1123
stage: clean-git-history-checking
12-
image: rust
13-
before_script:
14-
- cargo install clean_git_history
1524
script:
16-
# Check all the commits in the branch.
17-
- /usr/local/cargo/bin/clean_git_history --from-reference "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
25+
- earthly --ci +clean-git-history-checking --from "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
1826
rules:
1927
- if: $CI_MERGE_REQUEST_ID
2028

2129

2230
conventional-commits-linting:
2331
stage: conventional-commits-linting
24-
image: rust
25-
before_script:
26-
- cargo install conventional_commits_linter
2732
script:
28-
# Lint all the commits in the branch.
29-
- /usr/local/cargo/bin/conventional_commits_linter --from-reference "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" --allow-angular-type-only
33+
- earthly --ci +conventional-commits-linting --from "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
3034
rules:
3135
- if: $CI_MERGE_REQUEST_ID
3236

3337

3438
formatting:
3539
stage: formatting
36-
image: archlinux:base
37-
before_script:
38-
- pacman -Sy --noconfirm
39-
- pacman -S clang diffutils gawk grep --noconfirm
4040
script:
41-
- for i in $( du -a src/ tests | awk '{print $2}' | grep -i "[.]c$" ); do
42-
- clang-format $i > temp.txt
43-
- cmp $i temp.txt
44-
- done
41+
- earthly --ci +check-formatting
4542
rules:
4643
- if: $CI_MERGE_REQUEST_ID
44+
- if: $CI_COMMIT_BRANCH == "master"
4745

4846

4947
linting:
5048
stage: linting
51-
image: archlinux:base
52-
before_script:
53-
- pacman -Sy --noconfirm
54-
- pacman -S clang cunit gawk grep --noconfirm
5549
script:
56-
- for i in $( du -a src/ tests | awk '{print $2}' | grep -i "[.]c$" ); do
57-
- clang-tidy $i --checks="*,-llvmlibc-restrict-system-libc-headers,-altera-id-dependent-backward-branch,-altera-unroll-loops" --warnings-as-errors="*"
58-
- done
50+
- earthly --ci +linting
5951
rules:
6052
- if: $CI_MERGE_REQUEST_ID
53+
- if: $CI_COMMIT_BRANCH == "master"
6154

6255

6356
compiling:
6457
stage: compiling
65-
image: archlinux:base-devel
66-
before_script:
67-
- pacman -Sy --noconfirm
68-
- pacman -S lib32-gcc-libs lib32-glibc make --noconfirm
6958
script:
70-
- make
59+
- earthly --ci +compiling
7160
rules:
7261
- if: $CI_MERGE_REQUEST_ID
7362
- if: $CI_COMMIT_BRANCH == "master"
7463

7564

7665
unit-testing:
7766
stage: unit-testing
78-
image: archlinux:base-devel
79-
before_script:
80-
- pacman -Sy --noconfirm
81-
- pacman -S lib32-gcc-libs lib32-glibc make cunit --noconfirm
8267
script:
83-
- make test
68+
- earthly --ci +unit-testing
8469
rules:
8570
- if: $CI_MERGE_REQUEST_ID
8671
- if: $CI_COMMIT_BRANCH == "master"

Earthfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
VERSION 0.6
2+
3+
4+
clean-git-history-checking:
5+
FROM rust
6+
RUN cargo install clean_git_history
7+
COPY ".git" "."
8+
ARG from="origin/HEAD"
9+
RUN /usr/local/cargo/bin/clean_git_history --from-reference "${from}"
10+
11+
12+
conventional-commits-linting:
13+
FROM rust
14+
RUN cargo install conventional_commits_linter
15+
COPY ".git" "."
16+
ARG from="origin/HEAD"
17+
RUN /usr/local/cargo/bin/conventional_commits_linter --from-reference "${from}" --allow-angular-type-only
18+
19+
20+
clang-base:
21+
FROM archlinux:base
22+
RUN pacman -Sy --noconfirm
23+
RUN pacman -S clang cunit --noconfirm
24+
COPY "./src" "./src"
25+
COPY "./tests" "./tests"
26+
27+
28+
check-formatting:
29+
FROM +clang-base
30+
RUN find "./src" "./tests" -type f -name "*.c" | xargs -I {} clang-format --dry-run --Werror "{}"
31+
32+
33+
fix-formatting:
34+
FROM +clang-base
35+
RUN find "./src" "./tests" -type f -name "*.c" | xargs -I {} clang-format -i "{}"
36+
SAVE ARTIFACT "./src" AS LOCAL "./src"
37+
SAVE ARTIFACT "./tests" AS LOCAL "./tests"
38+
39+
40+
linting:
41+
FROM +clang-base
42+
RUN find "./src" "./tests" -type f -name "*.c" | xargs -I {} clang-tidy --checks="*,-llvmlibc-restrict-system-libc-headers,-altera-id-dependent-backward-branch,-altera-unroll-loops" --warnings-as-errors="*" "{}"
43+
44+
45+
archlinux-base:
46+
FROM archlinux:base-devel
47+
RUN pacman -Sy --noconfirm
48+
RUN pacman -S lib32-gcc-libs lib32-glibc cunit --noconfirm
49+
COPY "./src" "./src"
50+
COPY "./tests" "./tests"
51+
52+
53+
compiling:
54+
FROM +archlinux-base
55+
RUN gcc -o "./shellcode-generator" "./src/shellcode-generator.c"
56+
57+
58+
unit-testing:
59+
FROM +archlinux-base
60+
RUN gcc -lcunit -o "./shellcode-generator-tests" "./tests/shellcode-generator-tests.c"
61+
RUN "./shellcode-generator-tests"
62+
63+
64+
payload-compiling:
65+
FROM +archlinux-base
66+
COPY "./output.c" "./output.c"
67+
RUN gcc -o "./output" "./output.c" -m32 -fno-stack-protector -z execstack
68+
RUN "./output"

0 commit comments

Comments
 (0)