forked from Imulion/MHFZ_Overlay
-
Notifications
You must be signed in to change notification settings - Fork 2
144 lines (122 loc) · 4.58 KB
/
automate-git-stats.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Automate Git Stats
on:
workflow_dispatch:
schedule:
- cron: '0 0 1 */3 *' # Run every 3 months at 00:00 UTC on the 1st day of the month
# https://stackoverflow.com/questions/63612155/how-do-i-trigger-a-scheduled-action-on-a-specific-branch
jobs:
run_scripts:
runs-on: ubuntu-latest
name: Update Git stats images with the latest commits
permissions:
pull-requests: write
contents: write
steps:
# https://stackoverflow.com/questions/62334460/git-history-in-a-github-action
- name: Check out repository
uses: actions/checkout@v4
with:
ref: release
fetch-depth: 0 # get full stats instead of last commit
- name: Set up Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git switch release
- name: Check if commit was made by github-actions[bot]
id: check_last_commit_author
run: |
LAST_COMMIT_AUTHOR=$(git log -1 --format="%cn")
echo "Last commit author: $LAST_COMMIT_AUTHOR"
if [ "$LAST_COMMIT_AUTHOR" = "github-actions[bot]" ]; then
echo "Last commit was already made by github-actions[bot]. Cancelling the workflow."
exit 1
fi
shell: bash
- name: Generate git.txt
run: |
mkdir -p ./scripts/input
git log --numstat > ./scripts/input/git.txt
- name: Count lines from git.txt
run: |
echo "Total lines in git text file: "
wc -l < ./scripts/input/git.txt
- name: Install LuaJIT
run: |
sudo apt-get update
sudo apt-get install -y luajit
- name: Install Lua development files
run: sudo apt-get install liblua5.1-dev
- name: Install LuaRocks
run : |
wget https://luarocks.org/releases/luarocks-3.8.0.tar.gz
tar zxpf luarocks-3.8.0.tar.gz
cd luarocks-3.8.0
./configure --with-lua-include=/usr/include/lua5.1/
make
sudo make install
# https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash/
- name: Install Luarocks rocks
working-directory: ./scripts/dependencies
run: |
echo "Contents of rocks.txt:"
cat rocks.txt
while IFS="" read -r rock || [ -n "$rock" ]
do
sudo luarocks install "$rock"
done < rocks.txt
shell: bash
- name: Anonymize emails
run: luajit ./rename_emails.lua
working-directory: ./scripts
- name: Create git_anonymized.txt artifact
uses: actions/upload-artifact@v4
with:
name: git-text-file-anonymized
path: ./scripts/input/git_anonymized.txt
retention-days: 1
- name: Remove git.txt
run: rm ./scripts/input/git.txt
- name: Install Ruby and ruby gems
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0' # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
working-directory: ./scripts/dependencies
- name: Generate Gemfile.lock
run: |
cd ./scripts/dependencies
bundle config set --local deployment 'true'
bundle install
# TODO: Remove?
- name: Cache Ruby gems
uses: actions/cache@v4
with:
path: ./scripts/dependencies/vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- run: bundle exec rake
working-directory: ./scripts/dependencies
- name: Install Python packages
run: make -C ./scripts/dependencies install_packages
- name: Generate images using Python
run: make -C ./scripts/dependencies generate_images
- name: Remove git_anonymized.txt
run: rm ./scripts/input/git_anonymized.txt
- name: Generate image artifacts
uses: actions/upload-artifact@v4
with:
name: generated-git-stats-images
path: ./scripts/output
retention-days: 1
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: 'chore(bot): update git statistics images'
title: 'Update git statistics images'
reviewers: DorielRivalet
branch: create-pull-request/automate-git-stats
base: release
add-paths: |
./scripts/output/*.png