Skip to content

Commit 5d6969d

Browse files
retour en arriere
1 parent 67edb11 commit 5d6969d

File tree

1 file changed

+88
-26
lines changed

1 file changed

+88
-26
lines changed

.github/workflows/push.yml

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
name: Push summary (single table)
2+
name: Push summary (Job Summary only)
33

44
on:
55
push:
@@ -9,58 +9,120 @@ on:
99
jobs:
1010
summarize:
1111
runs-on: ubuntu-latest
12+
1213
steps:
14+
# Checkout avec historique, indispensable pour diff BEFORE..AFTER.
15+
# Par défaut, actions/checkout ne fetch qu'un commit ; fetch-depth: 0 fetch tout l'historique. [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)
1316
- name: Checkout repository
1417
uses: actions/checkout@v4
1518
with:
16-
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)
19+
fetch-depth: 0
1720

18-
- name: Résumé du push (table unique)
21+
# Génère le résumé complet dans le Job Summary via GITHUB_STEP_SUMMARY. [1](https://nhsdigital.github.io/rap-community-of-practice/training_resources/R/git_with_RStudio/)[2](https://github.com/rstudio/rstudioapi/issues/14)
22+
- name: Résumé du push (commits + dates + stats)
1923
shell: bash
2024
run: |
2125
set -euo pipefail
2226
27+
REPO="${{ github.repository }}"
28+
REF="${{ github.ref }}"
29+
ACTOR="${{ github.actor }}"
2330
BEFORE="${{ github.event.before }}"
2431
AFTER="${{ github.sha }}"
32+
RUN_TS_UTC="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
33+
34+
# Pusher depuis le payload (souvent dispo), sinon fallback sur actor. [8](https://rdrr.io/cran/rstudioapi/src/R/commands.R)[7](https://docs.posit.co/ide/server-pro/admin/reference/rstudio_ide_commands.html)
35+
PUSHER_NAME="$(jq -r '.pusher.name // .sender.login // empty' "$GITHUB_EVENT_PATH")"
36+
[ -z "${PUSHER_NAME:-}" ] && PUSHER_NAME="$ACTOR"
37+
38+
# ------------------------------------------------------------
39+
# 1) En-tête
40+
# ------------------------------------------------------------
41+
{
42+
echo "## Résumé du push"
43+
echo ""
44+
echo "**Repo :** \`${REPO}\`"
45+
echo ""
46+
echo "**Branche :** \`${REF}\`"
47+
echo ""
48+
echo "**Actor (déclencheur) :** \`${ACTOR}\`"
49+
echo ""
50+
echo "**Pusher (payload) :** \`${PUSHER_NAME}\`"
51+
echo ""
52+
echo "**Date d'exécution (UTC) :** \`${RUN_TS_UTC}\`"
53+
echo ""
54+
echo "**Range :** \`${BEFORE} .. ${AFTER}\`"
55+
echo ""
56+
} >> "$GITHUB_STEP_SUMMARY"
2557
26-
echo "## Résumé (table unique)" >> "$GITHUB_STEP_SUMMARY"
58+
# ------------------------------------------------------------
59+
# 2) Table de tous les commits du push (SHA / auteur / date / message)
60+
# Le payload push est lisible via $GITHUB_EVENT_PATH ; utile pour commits[]. [8](https://rdrr.io/cran/rstudioapi/src/R/commands.R)[6](https://rdrr.io/cran/rstudioapi/src/R/document-api.R)
61+
# ------------------------------------------------------------
62+
COUNT="$(jq '.commits | length' "$GITHUB_EVENT_PATH")"
63+
echo "### Commits inclus dans ce push (${COUNT})" >> "$GITHUB_STEP_SUMMARY"
2764
echo "" >> "$GITHUB_STEP_SUMMARY"
2865
29-
# Tableau unique : même structure pour commits + stats + fichiers
30-
echo "| Section | Commit | Contributeur | Date commit | Message | Indicateur | Valeur | Fichier | + | - |" >> "$GITHUB_STEP_SUMMARY"
31-
echo "|---|---|---|---|---|---|---:|---|---:|---:|" >> "$GITHUB_STEP_SUMMARY"
66+
{
67+
echo "| Commit | Contributeur (auteur) | Date du commit | Message |"
68+
echo "|---|---|---|---|"
69+
} >> "$GITHUB_STEP_SUMMARY"
3270
33-
# ----------------------------
34-
# 1) Lignes COMMITS
35-
# 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)
36-
# On échappe les retours lignes et le caractère '|' pour préserver le tableau.
3771
jq -r '
3872
.commits[]
3973
| .short = (.id[0:7])
4074
| .msg = (.message | gsub("\r\n|\n|\r"; " ") | gsub("\\|"; "\\\\|"))
41-
| "| COMMITS | [" + .short + "](" + (.author.name // "unknown") + " | " + (.timestamp // "unknown") + " | " + .msg + " | | | | | |"
75+
| "| " + .short + " | " + (.author.name // "unknown") + " | " + (.timestamp // "unknown") + " | " + .msg + " |"
4276
' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY"
4377
44-
# ----------------------------
45-
# 2) STATS globales diff BEFORE -> AFTER
46-
# Les champs added/removed/modified ont été retirés du payload push pour Actions,
78+
echo "" >> "$GITHUB_STEP_SUMMARY"
79+
80+
# ------------------------------------------------------------
81+
# 3) Stats globales ajoutées/supprimées (diff BEFORE -> AFTER)
82+
# IMPORTANT: les champs added/removed/modified ont été retirés du payload push pour Actions,
4783
# 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)
84+
# BEFORE est dispo dans l'event push via github.event.before. [6](https://rdrr.io/cran/rstudioapi/src/R/document-api.R)[7](https://docs.posit.co/ide/server-pro/admin/reference/rstudio_ide_commands.html)
85+
# ------------------------------------------------------------
86+
echo "### Statistiques globales (diff BEFORE → AFTER)" >> "$GITHUB_STEP_SUMMARY"
87+
echo "" >> "$GITHUB_STEP_SUMMARY"
88+
4889
if [[ "$BEFORE" =~ ^0+$ ]]; then
49-
echo "| STATS | | | | | Premier push (BEFORE=000…) | Diff non calculable | | | |" >> "$GITHUB_STEP_SUMMARY"
90+
echo "> ⚠️ Premier push sur une nouvelle branche : BEFORE=000… (diff global non calculable)." >> "$GITHUB_STEP_SUMMARY"
91+
echo "" >> "$GITHUB_STEP_SUMMARY"
5092
else
51-
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")" # git diff compare deux commits [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
93+
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")"
5294
5395
FILES_CHANGED="$(echo "$NUMSTAT" | wc -l | tr -d ' ')"
5496
ADDED="$(echo "$NUMSTAT" | awk '{a+=$1} END {print a+0}')"
5597
REMOVED="$(echo "$NUMSTAT" | awk '{d+=$2} END {print d+0}')"
56-
MODIFIED_EST=$(( ADDED < REMOVED ? ADDED : REMOVED )) # estimation ~modifiées (approx) [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
5798
58-
echo "| STATS | | | | | Fichiers changés | $FILES_CHANGED | | | |" >> "$GITHUB_STEP_SUMMARY"
59-
echo "| STATS | | | | | Lignes ajoutées (+) | $ADDED | | | |" >> "$GITHUB_STEP_SUMMARY"
60-
echo "| STATS | | | | | Lignes supprimées (-) | $REMOVED | | | |" >> "$GITHUB_STEP_SUMMARY"
61-
echo "| STATS | | | | | Estimation lignes modifiées (~) | $MODIFIED_EST | | | |" >> "$GITHUB_STEP_SUMMARY"
99+
# Estimation "modifiées" : Git ne donne pas un compteur natif "modified".
100+
# Une modif est souvent 1 suppression + 1 ajout => min(added, removed). [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
101+
MODIFIED_EST=$(( ADDED < REMOVED ? ADDED : REMOVED ))
102+
103+
{
104+
echo "| Indicateur | Valeur |"
105+
echo "|---|---:|"
106+
echo "| Fichiers changés | ${FILES_CHANGED} |"
107+
echo "| Lignes ajoutées (+) | ${ADDED} |"
108+
echo "| Lignes supprimées (-) | ${REMOVED} |"
109+
echo "| Estimation lignes modifiées (~) | ${MODIFIED_EST} |"
110+
} >> "$GITHUB_STEP_SUMMARY"
111+
112+
echo "" >> "$GITHUB_STEP_SUMMARY"
113+
114+
# Détail par fichier en section repliable (pour éviter de surcharger).
115+
echo "<details><summary>Détail par fichier (+/-)</summary>" >> "$GITHUB_STEP_SUMMARY"
116+
echo "" >> "$GITHUB_STEP_SUMMARY"
117+
echo "" >> "$GITHUB_STEP_SUMMARY"
118+
echo "| Fichier | + | - |" >> "$GITHUB_STEP_SUMMARY"
119+
echo "|---|---:|---:|" >> "$GITHUB_STEP_SUMMARY"
120+
echo "$NUMSTAT" | awk 'BEGIN{FS="\t"} {printf "| `%s` | %s | %s |\n", $3, $1, $2}' >> "$GITHUB_STEP_SUMMARY"
121+
echo "" >> "$GITHUB_STEP_SUMMARY"
122+
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
123+
echo "" >> "$GITHUB_STEP_SUMMARY"
124+
fi
62125
63-
# ----------------------------
64-
# 3) Détail par fichier (+/-)
65-
# NUMSTAT est "added<TAB>removed<TAB>file" → on le transforme en lignes de tableau.
66-
echo echo "$NUMSTAT" | awk -F '\t' '{printf "| FICHIERS | | | | | | | `%s` | %s | %s |\n", $3, $1, $2}' >> "$GITHUB_STEP_SUMMARY"
126+
# ------------------------------------------------------------
127+
# ⚠️ # ⚠️ Limite de taille Job Summary : si énorme push (beaucoup de fichiers/commits),
128+
# le summary peut dépasser ~1024k et échouer. [5](https://www.w3tutorials.net/blog/how-to-avoid-having-to-do-git-branch-set-upstream-and-instead-default-to-automatically-setup-remote-tracking/)[1](https://nhsdigital.github.io/rap-community-of-practice/training_resources/R/git_with_RStudio/)

0 commit comments

Comments
 (0)