|
1 | 1 |
|
2 | | -name: Push summary (single table) |
| 2 | +name: Push summary (Job Summary only) |
3 | 3 |
|
4 | 4 | on: |
5 | 5 | push: |
|
9 | 9 | jobs: |
10 | 10 | summarize: |
11 | 11 | runs-on: ubuntu-latest |
| 12 | + |
12 | 13 | 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) |
13 | 16 | - name: Checkout repository |
14 | 17 | uses: actions/checkout@v4 |
15 | 18 | 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 |
17 | 20 |
|
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) |
19 | 23 | shell: bash |
20 | 24 | run: | |
21 | 25 | set -euo pipefail |
22 | 26 |
|
| 27 | + REPO="${{ github.repository }}" |
| 28 | + REF="${{ github.ref }}" |
| 29 | + ACTOR="${{ github.actor }}" |
23 | 30 | BEFORE="${{ github.event.before }}" |
24 | 31 | 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" |
25 | 57 |
|
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" |
27 | 64 | echo "" >> "$GITHUB_STEP_SUMMARY" |
28 | 65 |
|
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" |
32 | 70 |
|
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. |
37 | 71 | jq -r ' |
38 | 72 | .commits[] |
39 | 73 | | .short = (.id[0:7]) |
40 | 74 | | .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 + " |" |
42 | 76 | ' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY" |
43 | 77 |
|
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, |
47 | 83 | # 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 | +
|
48 | 89 | 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" |
50 | 92 | 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")" |
52 | 94 |
|
53 | 95 | FILES_CHANGED="$(echo "$NUMSTAT" | wc -l | tr -d ' ')" |
54 | 96 | ADDED="$(echo "$NUMSTAT" | awk '{a+=$1} END {print a+0}')" |
55 | 97 | 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) |
57 | 98 |
|
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 |
62 | 125 |
|
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