-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
89 lines (82 loc) · 3.31 KB
/
action.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
name: "git-log to CSV"
description: "Export a CSV of the history of the main branch"
author: "Natalie Somersall (@some-natalie)"
branding:
color: purple
icon: file-text
inputs:
repository:
description: "The repository to audit"
required: true
default: ${{ github.repository }}
branch:
description: "The branch to audit"
required: true
default: "main"
gpg:
description: "Report git commit signing (GPG) signatures, set to 'true' to enable"
required: true
default: "false"
token:
description: "GitHub token to use if not running on the current repository"
required: true
default: ${{ github.token }}
include_diffs:
description: "Include diffs in the output, added to the zip file"
required: true
default: "false"
runs:
using: "composite"
steps:
- name: "Checkout the repo"
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
token: ${{ inputs.token }}
fetch-depth: 0
- name: "Make a CSV file out of the git log"
shell: bash
run: |
# set the commit URL
COMMIT_URL="${{ github.server_url }}/${{ inputs.repository }}/commit/"
# git log print
if [ ${{ inputs.gpg }} = "true" ]; then
git log ${{ inputs.branch }} --date=local --pretty="%x40%H%x2C%h%x2C%an%x2C%G?%x2C%GS%x2C%GK%x2C%ad%x2C%x22%s%x22%x2C" --shortstat | tr "\n" " " | tr "@" "\n" >> log.csv
else
git log ${{ inputs.branch }} --date=local --pretty="%x40%H%x2C%h%x2C%an%x2C%ad%x2C%x22%s%x22%x2C" --shortstat | tr "\n" " " | tr "@" "\n" >> log.csv
fi
# sed magics to make the files changed and lines inserted/deleted columns plain numbers
sed -i.bak 's/ files changed//g' log.csv
sed -i.bak 's/ file changed//g' log.csv
sed -i.bak 's/ insertions(+)//g' log.csv
sed -i.bak 's/ insertion(+)//g' log.csv
sed -i.bak 's/ deletions(-)//g' log.csv
sed -i.bak 's/ deletion(-)//g' log.csv
# download diffs if needed
if [ ${{ inputs.include_diffs }} = "true" ]; then
sed -i.bak -e "1d" log.csv
initial_commit_id=$(git rev-list --max-parents=0 HEAD)
initial_commit_short_id=$(git rev-list --max-parents=0 HEAD | cut -c 1-7)
git show "$initial_commit_id" > "$initial_commit_short_id".diff
while read -r line; do
commit_id=$(echo "$line" | awk -F"," '{print $1}')
short_commit_id=$(echo "$line" | awk -F"," '{print $2}')
git show "$commit_id" > "$short_commit_id".diff
done < log.csv
fi
# add in the url to see the detailed commit with awk
awk -F"," 'OFS = ", " {$1 = "'"$COMMIT_URL"'"$1; print}' log.csv > history.csv
# add the header line in
if [ ${{ inputs.gpg }} = "true" ]; then
sed -i.bak '1s/.*/url,commit id,author,commit signature status,name of signer,key used to sign,date,comment,changed files,lines added,lines deleted/' history.csv
else
sed -i.bak '1s/.*/url,commit id,author,date,comment,changed files,lines added,lines deleted/' history.csv
fi
- name: "Upload that CSV file and diffs if needed"
uses: actions/upload-artifact@v4
with:
name: "git-audit-log"
path: |
history.csv
*.diff
if-no-files-found: error