Skip to content

test

test #7

Workflow file for this run

name: Push summary (single table)
on:
push:
branches:
- main
jobs:
summarize:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # nécessaire pour comparer BEFORE..AFTER [5](https://www.w3tutorials.net/blog/how-to-avoid-having-to-do-git-branch-set-upstream-and-instead-default-to-automatically-setup-remote-tracking/)[4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
- name: Résumé du push (table unique)
shell: bash
run: |
set -euo pipefail
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
echo "## Résumé (table unique)" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
# Tableau unique : même structure pour commits + stats + fichiers
echo "| Section | Commit | Contributeur | Date commit | Message | Indicateur | Valeur | Fichier | + | - |" >> "$GITHUB_STEP_SUMMARY"
echo "|---|---|---|---|---|---|---:|---|---:|---:|" >> "$GITHUB_STEP_SUMMARY"
# ----------------------------
# 1) Lignes COMMITS
# On lit commits[] depuis le payload d’événement (GITHUB_EVENT_PATH). [6](https://rdrr.io/cran/rstudioapi/src/R/commands.R)[7](https://rdrr.io/cran/rstudioapi/src/R/document-api.R)
# On échappe les retours lignes et le caractère '|' pour préserver le tableau.
jq -r '
.commits[]
| .short = (.id[0:7])
| .msg = (.message | gsub("\r\n|\n|\r"; " ") | gsub("\\|"; "\\\\|"))
| "| COMMITS | [" + .short + "](" + (.author.name // "unknown") + " | " + (.timestamp // "unknown") + " | " + .msg + " | | | | | |"
' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY"
# ----------------------------
# 2) STATS globales diff BEFORE -> AFTER
# Les champs added/removed/modified ont été retirés du payload push pour Actions,
# donc on calcule via git diff --numstat. [3](https://docs.posit.co/ide/user/ide/guide/productivity/add-ins.html)[4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
if [[ "$BEFORE" =~ ^0+$ ]]; then
echo "| STATS | | | | | Premier push (BEFORE=000…) | Diff non calculable | | | |" >> "$GITHUB_STEP_SUMMARY"
else
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")" # git diff compare deux commits [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
FILES_CHANGED="$(echo "$NUMSTAT" | wc -l | tr -d ' ')"
ADDED="$(echo "$NUMSTAT" | awk '{a+=$1} END {print a+0}')"
REMOVED="$(echo "$NUMSTAT" | awk '{d+=$2} END {print d+0}')"
MODIFIED_EST=$(( ADDED < REMOVED ? ADDED : REMOVED )) # estimation ~modifiées (approx) [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
echo "| STATS | | | | | Fichiers changés | $FILES_CHANGED | | | |" >> "$GITHUB_STEP_SUMMARY"
echo "| STATS | | | | | Lignes ajoutées (+) | $ADDED | | | |" >> "$GITHUB_STEP_SUMMARY"
echo "| STATS | | | | | Lignes supprimées (-) | $REMOVED | | | |" >> "$GITHUB_STEP_SUMMARY"
echo "| STATS | | | | | Estimation lignes modifiées (~) | $MODIFIED_EST | | | |" >> "$GITHUB_STEP_SUMMARY"
# ----------------------------
# 3) Détail par fichier (+/-)
# NUMSTAT est "added<TAB>removed<TAB>file" → on le transforme en lignes de tableau.
echo echo "$NUMSTAT" | awk -F '\t' '{printf "| FICHIERS | | | | | | | `%s` | %s | %s |\n", $3, $1, $2}' >> "$GITHUB_STEP_SUMMARY"