Skip to content

Commit f974db3

Browse files
test new yaml
1 parent 5e20f6b commit f974db3

File tree

1 file changed

+67
-127
lines changed

1 file changed

+67
-127
lines changed

.github/workflows/push.yml

Lines changed: 67 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,68 @@
11

2-
name: Push summary (Job Summary only)
3-
4-
on:
5-
push:
6-
branches:
7-
- main
8-
9-
jobs:
10-
summarize:
11-
runs-on: ubuntu-latest
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)
16-
- name: Checkout repository
17-
uses: actions/checkout@v4
18-
with:
19-
fetch-depth: 0
20-
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)
23-
shell: bash
24-
run: |
25-
set -euo pipefail
26-
27-
REPO="${{ github.repository }}"
28-
REF="${{ github.ref }}"
29-
ACTOR="${{ github.actor }}"
30-
BEFORE="${{ github.event.before }}"
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"
57-
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"
64-
echo "" >> "$GITHUB_STEP_SUMMARY"
65-
66-
{
67-
echo "| Commit | Contributeur (auteur) | Date du commit | Message |"
68-
echo "|---|---|---|---|"
69-
} >> "$GITHUB_STEP_SUMMARY"
70-
71-
jq -r '
72-
.commits[]
73-
| .short = (.id[0:7])
74-
| .msg = (.message | gsub("\r\n|\n|\r"; " ") | gsub("\\|"; "\\\\|"))
75-
| "| " + .short + " | " + (.author.name // "unknown") + " | " + (.timestamp // "unknown") + " | " + .msg + " |"
76-
' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY"
77-
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,
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-
89-
if [[ "$BEFORE" =~ ^0+$ ]]; then
90-
echo "> ⚠️ Premier push sur une nouvelle branche : BEFORE=000… (diff global non calculable)." >> "$GITHUB_STEP_SUMMARY"
91-
echo "" >> "$GITHUB_STEP_SUMMARY"
92-
else
93-
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")"
94-
95-
FILES_CHANGED="$(echo "$NUMSTAT" | wc -l | tr -d ' ')"
96-
ADDED="$(echo "$NUMSTAT" | awk '{a+=$1} END {print a+0}')"
97-
REMOVED="$(echo "$NUMSTAT" | awk '{d+=$2} END {print d+0}')"
98-
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
125-
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/)
2+
- name: Checkout repository
3+
uses: actions/checkout@v4
4+
with:
5+
fetch-depth: 0
6+
7+
- name: Résumé du push (table unique + message complet + liens)
8+
shell: bash
9+
run: |
10+
set -euo pipefail
11+
12+
REPO="${{ github.repository }}"
13+
REPO_URL="https://github.com/${REPO}"
14+
REF="${{ github.ref }}"
15+
ACTOR="${{ github.actor }}"
16+
BEFORE="${{ github.event.before }}"
17+
AFTER="${{ github.sha }}"
18+
RUN_TS_UTC="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
19+
20+
echo "## Résumé (table unique)" >> "$GITHUB_STEP_SUMMARY"
21+
echo "" >> "$GITHUB_STEP_SUMMARY"
22+
23+
# Tableau unique (tout fusionné)
24+
# Remarque: on évite les colonnes typées numériques (---:) pour pouvoir écrire du texte (ex: lien repo) dans "Valeur".
25+
echo "| Section | Dépôt | Commit | Contributeur | Date commit | Message (complet) | Indicateur | Valeur | Fichier | + | - |" >> "$GITHUB_STEP_SUMMARY"
26+
echo "|---|---|---|---|---|---|---|---|---|---:|---:|" >> "$GITHUB_STEP_SUMMARY"
27+
28+
# LIGNE META: lien vers le dépôt + infos de branche
29+
echo "| META | [${REPO}](${RE| | | Branche | \`${REF}\` | | | |" >> "$GITHUB_STEP_SUMMARY"
30+
echo "| META | ${REPO} | | | | | Actor | \`${ACTOR}\` | | | |" >> "$GITHUB_STEP_SUMMARY"
31+
echo "| META | ${REPO} | | | | | Date run (UTC) | \`${RUN_TS_UTC}\` | | | |" >> "$GITHUB_STEP_SUMMARY"
32+
echo "| META | [${REPO}](${REPO_URL| Range | \`${BEFORE}..${AFTER}\` | | | |" >> "$GITHUB_STEP_SUMMARY"
33+
34+
# 1) COMMITS (SHA cliquable + message complet)
35+
# - SHA court + lien vers le commit
36+
# - message: remplace les retours ligne par <br> pour garder le message complet (titre + corps)
37+
# - échappe le '|' qui casserait le tableau
38+
jq -r --arg repo_url "$REPO_URL" --arg repo "$REPO" '
39+
.commits[]
40+
| .short = (.id[0:7])
41+
| .msg = (.message | gsub("\r\n|\n|\r"; "<br>") | gsub("\\|"; "\\\\|"))
42+
| "| COMMITS | " + $repo + ""
43+
+ " | " + .short + ""
44+
+ " | " + (.author.name // "unknown")
45+
+ " | " + (.timestamp // "unknown")
46+
+ " | " + .msg
47+
+ " | | | | | |"
48+
' "$GITHUB_EVENT_PATH" >> "$GITHUB_STEP_SUMMARY"
49+
50+
# 2) STATS globales (diff BEFORE -> AFTER)
51+
# GitHub Actions ne fournit plus added/removed/modified dans le payload push → calcul 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)
52+
if [[ "$BEFORE" =~ ^0+$ ]]; then
53+
echo "| STATS | [${REO} | | | | | Premier push | BEFORE=000… (diff non calculable) | | | |" >> "$GITHUB_STEP_SUMMARY"
54+
else
55+
NUMSTAT="$(git diff --numstat "$BEFORE" "$AFTER")"
56+
57+
FILES_CHANGED="$(echo "$NUMSTAT" | wc -l | tr -d ' ')"
58+
ADDED="$(echo "$NUMSTAT" | awk '{a+=$1} END {print a+0}')"
59+
REMOVED="$(echo "$NUMSTAT" | awk '{d+=$2} END {print d+0}')"
60+
MODIFIED_EST=$(( ADDED < REMOVED ? ADDED : REMOVED ))
61+
62+
echo "| STATS | [${EPO} | | | | | Fichiers changés | ${FILES_CHANGED} | | | |" >> "$GITHUB_STEP_SUMMARY"
63+
echo "| STATS | ${REPO} | | | | | Lignes ajoutées (+) | ${ADDED} | | | |" >> "$GITHUB_STEP_SUMMARY"
64+
echo "| STATS | ${REPO} | | | | | Lignes supprimées (-) | ${REMOVED} | | | |" >> "$GITHUB_STEP_SUMMARY"
65+
echo "| STATS | ${REPO} | | | | | Estimation lignes modifiées (~) | ${ echo "| STATS | ${REPO} | | | | | Estimation lignes modifiées (~) | ${MODIFIED_EST} | | | |" >> "$GITHUB_STEP_SUMMARY"
66+
67+
# 3) Détail par fichier (+/-)
68+
echo "$NUMSTAT" | awk -F '\t' '{printf "| FICHIERS | '"$REPO"' | | | | | | | `%s` | %s | %s |\n", $3, $1, $2}' >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)