Automate Git Stats #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
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@v3 | |
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@v3 | |
with: | |
name: generated-git-stats-images | |
path: ./scripts/output | |
retention-days: 1 | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
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 |