-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (108 loc) · 6.71 KB
/
push.yml
File metadata and controls
128 lines (108 loc) · 6.71 KB
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
name: Push summary (Job Summary only)
on:
push:
branches:
- main
jobs:
summarize:
runs-on: ubuntu-latest
steps:
# Checkout avec historique, indispensable pour diff BEFORE..AFTER.
# 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)
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# 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)
- name: Résumé du push (commits + dates + stats)
shell: bash
run: |
set -euo pipefail
REPO="${{ github.repository }}"
REF="${{ github.ref }}"
ACTOR="${{ github.actor }}"
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
RUN_TS_UTC="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
# 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)
PUSHER_NAME="$(jq -r '.pusher.name // .sender.login // empty' "$GITHUB_EVENT_PATH")"
[ -z "${PUSHER_NAME:-}" ] && PUSHER_NAME="$ACTOR"
# ------------------------------------------------------------
# 1) En-tête
# ------------------------------------------------------------
{
echo "## Résumé du push"
echo ""
echo "**Repo :** \`${REPO}\`"
echo ""
echo "**Branche :** \`${REF}\`"
echo ""
echo "**Actor (déclencheur) :** \`${ACTOR}\`"
echo ""
echo "**Pusher (payload) :** \`${PUSHER_NAME}\`"
echo ""
echo "**Date d'exécution (UTC) :** \`${RUN_TS_UTC}\`"
echo ""
echo "**Range :** \`${BEFORE} .. ${AFTER}\`"
echo ""
} >> "$GITHUB_STEP_SUMMARY"
# ------------------------------------------------------------
# 2) Table de tous les commits du push (SHA / auteur / date / message)
# 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)
# ------------------------------------------------------------
COUNT="$(jq '.commits | length' "$GITHUB_EVENT_PATH")"
echo "### Commits inclus dans ce push (${COUNT})" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
{
echo "| Commit | Contributeur (auteur) | Date du commit | Message |"
echo "|---|---|---|---|"
} >> "$GITHUB_STEP_SUMMARY"
jq -r '
.commits[]
| .short = (.id[0:7])
| .msg = (.message | gsub("\r\n|\n|\r"; " ") | gsub("\\|"; "\\\\|"))
| "| " + .short + " | " + (.author.name // "unknown") + " | " + (.timestamp // "unknown") + " | " + .msg + " |"
' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
# ------------------------------------------------------------
# 3) Stats globales ajoutées/supprimées (diff BEFORE -> AFTER)
# IMPORTANT: 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)
# 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)
# ------------------------------------------------------------
echo "### Statistiques globales (diff BEFORE → AFTER)" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [[ "$BEFORE" =~ ^0+$ ]]; then
echo "> ⚠️ Premier push sur une nouvelle branche : BEFORE=000… (diff global non calculable)." >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
else
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")"
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}')"
# Estimation "modifiées" : Git ne donne pas un compteur natif "modified".
# Une modif est souvent 1 suppression + 1 ajout => min(added, removed). [4](https://cran.r-project.org/web/packages/rstudioapi/vignettes/introduction.html)
MODIFIED_EST=$(( ADDED < REMOVED ? ADDED : REMOVED ))
{
echo "| Indicateur | Valeur |"
echo "|---|---:|"
echo "| Fichiers changés | ${FILES_CHANGED} |"
echo "| Lignes ajoutées (+) | ${ADDED} |"
echo "| Lignes supprimées (-) | ${REMOVED} |"
echo "| Estimation lignes modifiées (~) | ${MODIFIED_EST} |"
} >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
# Détail par fichier en section repliable (pour éviter de surcharger).
echo "<details><summary>Détail par fichier (+/-)</summary>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Fichier | + | - |" >> "$GITHUB_STEP_SUMMARY"
echo "|---|---:|---:|" >> "$GITHUB_STEP_SUMMARY"
echo "$NUMSTAT" | awk 'BEGIN{FS="\t"} {printf "| `%s` | %s | %s |\n", $3, $1, $2}' >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
fi
# ------------------------------------------------------------
# ⚠️ # ⚠️ Limite de taille Job Summary : si énorme push (beaucoup de fichiers/commits),
# 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/)