Skip to content

Commit a4c1ce4

Browse files
ci: adding clean Git history checking (#12)
1 parent 0b5f6a8 commit a4c1ce4

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

.github/workflows/git-history.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Git History
2+
3+
on: pull_request
4+
5+
env:
6+
# Forcing Earthly to use colours, to make reading output easier.
7+
FORCE_COLOR: 1
8+
9+
jobs:
10+
clean:
11+
name: Clean
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Download Earthly v0.8.6.
15+
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.6/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
16+
- name: Checkout code.
17+
uses: actions/checkout@v3
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
20+
fetch-depth: 0
21+
- name: Check clean Git history.
22+
run: earthly --ci +check-clean-git-history --from_reference "origin/${{ github.base_ref }}"

Earthfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ COPY_CI_DATA:
66
COPY --dir "ci/" ".github/" "./"
77

88

9+
COPY_METADATA:
10+
COMMAND
11+
DO +COPY_CI_DATA
12+
COPY --dir ".git/" "./"
13+
14+
15+
rust-base:
16+
FROM rust:1.70.0
17+
WORKDIR "/nasm-x86-shellcode-generator"
18+
19+
20+
check-clean-git-history:
21+
FROM +rust-base
22+
RUN cargo install clean_git_history --version 0.1.2 --locked
23+
DO +COPY_METADATA
24+
ARG from_reference="origin/HEAD"
25+
RUN ./ci/check-clean-git-history.sh --from-reference "${from_reference}"
26+
27+
928
check-github-actions-workflows-linting:
1029
FROM golang:1.20.13
1130
RUN go install github.com/rhysd/actionlint/cmd/[email protected]

ci/check-clean-git-history.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# ARG_OPTIONAL_SINGLE([from-reference],[],[],[origin/HEAD])
4+
# ARGBASH_GO()
5+
# needed because of Argbash --> m4_ignore([
6+
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
7+
# Argbash is a bash code generator used to get arguments parsing right.
8+
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
9+
# Generated online by https://argbash.io/generate
10+
11+
die() {
12+
local _ret="${2:-1}"
13+
test "${_PRINT_HELP:-no}" = yes && print_help >&2
14+
echo "$1" >&2
15+
exit "${_ret}"
16+
}
17+
18+
begins_with_short_option() {
19+
local first_option all_short_options=''
20+
first_option="${1:0:1}"
21+
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
22+
}
23+
24+
# THE DEFAULTS INITIALIZATION - OPTIONALS
25+
_arg_from_reference="origin/HEAD"
26+
27+
print_help() {
28+
printf 'Usage: %s [--from-reference <arg>]\n' "$0"
29+
}
30+
31+
parse_commandline() {
32+
while test $# -gt 0; do
33+
_key="$1"
34+
case "$_key" in
35+
--from-reference)
36+
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
37+
_arg_from_reference="$2"
38+
shift
39+
;;
40+
--from-reference=*)
41+
_arg_from_reference="${_key##--from-reference=}"
42+
;;
43+
*)
44+
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
45+
;;
46+
esac
47+
shift
48+
done
49+
}
50+
51+
parse_commandline "$@"
52+
53+
# OTHER STUFF GENERATED BY Argbash
54+
55+
### END OF CODE GENERATED BY Argbash (sortof) ### ])
56+
# [ <-- needed because of Argbash
57+
set -o errexit
58+
set -o xtrace
59+
60+
"${CARGO_HOME}/bin/clean_git_history" --from-reference "${_arg_from_reference}"
61+
# ] <-- needed because of Argbash

0 commit comments

Comments
 (0)