Skip to content

Commit 849098f

Browse files
committed
new setp
1 parent 8048c48 commit 849098f

3 files changed

Lines changed: 72 additions & 155 deletions

File tree

.github/steps/4-step.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,24 @@
66
Un conflit arrive quand la même portion de code a été modifiée différemment sur `main` et sur ta branche. Git ne sait pas quelle version garder, il te demande de trancher.
77

88
### ✅ Cas simple, pas de conflit
9-
- Le message GitHub « **This branch has no conflicts with the base branch** » (ou équivalent en FR) signifie que tu peux **fusionner** directement.
9+
- Le message GitHub « **This branch has no conflicts with the base branch** » signifie que tu peux **fusionner** directement.
1010
- Clique **Merge pull request** puis **Confirm merge**.
1111

1212
### ⚠️ S’il y a des conflits
1313
Choisis **une** des deux méthodes :
1414

15-
**A. Bouton GitHub (UI)**
16-
1. Clique **Update branch** dans la PR (s’il est proposé).
17-
2. Si des conflits persistent, clique **Resolve conflicts**, édite les fichiers, puis **Mark as resolved** **Commit merge**.
15+
**A. Bouton GitHub, UI**
16+
1. Clique **Update branch** dans la PR, si proposé.
17+
2. Si des conflits persistent, clique **Resolve conflicts**, édite, **Mark as resolved**, puis **Commit merge**.
1818

19-
**B. En ligne de commande (rebase recommandé)**
19+
**B. Ligne de commande, rebase recommandé**
2020
```bash
21-
# Mets à jour ton dépôt local
2221
git fetch origin
23-
24-
# Va sur ta branche de la PR
2522
git checkout my-first-branch
26-
27-
# Rebase sur main
2823
git rebase origin/main
2924

30-
# Ouvre les fichiers en conflit, supprime les marqueurs <<<<<<< ======= >>>>>>>
31-
# puis valide les résolutions :
25+
# Résous les conflits, supprime les marqueurs <<<<<<< ======= >>>>>>>
3226
git add .
33-
34-
# Continue le rebase
3527
git rebase --continue
3628

37-
# Pousse le résultat (forcé sécurisé)
3829
git push --force-with-lease

.github/workflows/3-last-step.yml

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Step 3 # Last step of the exercise
22

33
on:
44
pull_request:
5-
types: [opened, reopened, closed]
5+
types: [opened, reopened, synchronize, closed]
66
workflow_dispatch:
77

88
permissions:
@@ -13,51 +13,69 @@ permissions:
1313

1414
env:
1515
REVIEW_FILE: ".github/steps/x-review.md"
16+
STEP_4_FILE: ".github/steps/4-step.md"
1617

1718
jobs:
1819
find_exercise:
1920
name: Find Exercise Issue
2021
uses: skills/exercise-toolkit/.github/workflows/find-exercise-issue.yml@v0.7.1
2122

22-
on-opened:
23-
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: actions/checkout@v4
27-
- name: Comment on the PR
28-
uses: GrantBirki/comment@v2.1.1
29-
with:
30-
repository: ${{ github.repository }}
31-
issue-number: ${{ github.event.pull_request.number }}
32-
file: .github/steps/3-step.md
33-
34-
post_review_content:
35-
name: Post review content
23+
# À l'ouverture ou mise à jour de la PR, on affiche l'Étape 4 (merge)
24+
step4_merge_guidance:
25+
name: Step 4, merge guidance
3626
needs: [find_exercise]
37-
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
27+
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
3828
runs-on: ubuntu-latest
3929
env:
4030
ISSUE_REPOSITORY: ${{ github.repository }}
4131
ISSUE_NUMBER: ${{ needs.find_exercise.outputs.issue-number }}
42-
4332
steps:
4433
- name: Checkout
4534
uses: actions/checkout@v4
4635

47-
- name: Create comment, step finished, final review next
48-
uses: GrantBirki/comment@v2.1.1
36+
- name: Detect PR mergeability
37+
id: prinfo
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const { owner, repo } = context.repo;
42+
const number = context.payload.pull_request.number;
43+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: number });
44+
core.setOutput('mergeable_state', pr.mergeable_state || 'unknown');
45+
46+
- name: Build status line
47+
id: status
48+
run: |
49+
state='${{ steps.prinfo.outputs.mergeable_state }}'
50+
if [ "$state" = "clean" ] || [ "$state" = "unstable" ] || [ "$state" = "blocked" ]; then
51+
echo "line=✅ Pas de conflit bloquant détecté, tu peux **fusionner** ta PR" >> $GITHUB_OUTPUT
52+
elif [ "$state" = "dirty" ]; then
53+
echo "line=⚠️ Conflits détectés, suis les étapes ci-dessous pour les résoudre" >> $GITHUB_OUTPUT
54+
else
55+
echo "line=ℹ️ État de fusion inconnu pour le moment, suis le guide ci-dessous si GitHub indique des conflits" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Find existing Step 4 comment
59+
id: find
60+
uses: peter-evans/find-comment@v3
4961
with:
5062
repository: ${{ env.ISSUE_REPOSITORY }}
5163
issue-number: ${{ env.ISSUE_NUMBER }}
52-
file: .github/i18n/fr/lesson-review.md
64+
comment-author: github-actions[bot]
65+
body-includes: "## Étape 4, résoudre les conflits et fusionner"
5366

54-
- name: Create comment, add review content
67+
- name: Create or update Step 4 comment
5568
uses: GrantBirki/comment@v2.1.1
5669
with:
5770
repository: ${{ env.ISSUE_REPOSITORY }}
5871
issue-number: ${{ env.ISSUE_NUMBER }}
59-
file: ${{ env.REVIEW_FILE }}
72+
file: ${{ env.STEP_4_FILE }}
73+
edit-mode: ${{ steps.find.outputs.comment-id && 'replace' || 'append' }}
74+
comment-id: ${{ steps.find.outputs.comment-id }}
75+
vars: |
76+
status_line: ${{ steps.status.outputs.line }}
6077
78+
# À la fermeture mergée, on finalise
6179
finish_exercise:
6280
name: Finish Exercise
6381
needs: [find_exercise]
@@ -75,7 +93,6 @@ jobs:
7593
runs-on: ubuntu-latest
7694
env:
7795
ISSUE_NUMBER: ${{ needs.find_exercise.outputs.issue-number }}
78-
7996
steps:
8097
- name: Checkout
8198
uses: actions/checkout@v4
@@ -92,13 +109,11 @@ jobs:
92109
const {owner, repo} = context.repo;
93110
const login = context.actor;
94111
const repoUrl = `https://github.com/${owner}/${repo}`;
95-
96112
const text = `Je viens de terminer l’exercice "GitHub Basics" ! 🎉\n\n${repoUrl}\n\n#GitHubSkills #OpenSource #GitHubLearn`;
97113
const enc = encodeURIComponent(text);
98114
const shareX = `https://twitter.com/intent/tweet?text=${enc}`;
99115
const shareBsky = `https://bsky.app/intent/compose?text=${enc}`;
100116
const shareLinkedIn = `https://www.linkedin.com/feed/?shareActive=true&text=${enc}`;
101-
102117
const lines = [
103118
'<div align="center">',
104119
'',
@@ -137,7 +152,6 @@ jobs:
137152
''
138153
];
139154
const block = lines.join('\n');
140-
141155
const readmePath = path.join(process.env.GITHUB_WORKSPACE, 'README.md');
142156
const current = fs.existsSync(readmePath) ? fs.readFileSync(readmePath, 'utf8') : '';
143157
fs.writeFileSync(readmePath, block + current, 'utf8');
@@ -161,43 +175,40 @@ jobs:
161175
git pull --rebase origin main || true
162176
git push origin HEAD:main
163177
164-
- name: Replace final EN comment with FR
165-
uses: actions/github-script@v7
166-
env:
167-
ISSUE_NUMBER: ${{ env.ISSUE_NUMBER }}
178+
post_review_content:
179+
name: Post review content, after merge
180+
needs: [find_exercise, finalize_fr]
181+
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
182+
runs-on: ubuntu-latest
183+
env:
184+
ISSUE_REPOSITORY: ${{ github.repository }}
185+
ISSUE_NUMBER: ${{ needs.find_exercise.outputs.issue-number }}
186+
steps:
187+
- name: Checkout
188+
uses: actions/checkout@v4
189+
190+
- name: Create comment, step finished, final review next
191+
uses: GrantBirki/comment@v2.1.1
168192
with:
169-
script: |
170-
const {owner, repo} = context.repo;
171-
const issue_number = Number(process.env.ISSUE_NUMBER);
172-
const body = [
173-
`🎉 Félicitations @${context.actor} tu as terminé l’exercice **GitHub Basics**.`,
174-
`Le README a été mis à jour avec un message final en français.`,
175-
`➡️ Retourne à la page d’accueil du dépôt pour voir le résultat.`
176-
].join('\n\n');
177-
178-
const { data: comments } = await github.rest.issues.listComments({
179-
owner, repo, issue_number, per_page: 100, sort: 'created', direction: 'desc'
180-
});
181-
182-
const target = comments.find(c =>
183-
c.user?.login === 'github-actions[bot]' &&
184-
/Congratulations|You finished the exercise/i.test(c.body || '')
185-
);
186-
187-
if (target) {
188-
await github.rest.issues.updateComment({ owner, repo, comment_id: target.id, body });
189-
} else {
190-
await github.rest.issues.createComment({ owner, repo, issue_number, body });
191-
}
193+
repository: ${{ env.ISSUE_REPOSITORY }}
194+
issue-number: ${{ env.ISSUE_NUMBER }}
195+
file: .github/i18n/fr/lesson-review.md
196+
197+
- name: Create comment, add review content
198+
uses: GrantBirki/comment@v2.1.1
199+
with:
200+
repository: ${{ env.ISSUE_REPOSITORY }}
201+
issue-number: ${{ env.ISSUE_NUMBER }}
202+
file: ${{ env.REVIEW_FILE }}
192203

193204
disable_step3:
194205
name: Disable Step 3
195-
needs: [finalize_fr]
206+
needs: [post_review_content]
196207
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
197208
runs-on: ubuntu-latest
198209
steps:
199210
- name: Disable workflow file
200211
run: gh workflow disable ".github/workflows/3-last-step.yml"
201212
env:
202213
GH_TOKEN: ${{ github.token }}
203-
continue-on-error: true
214+
continue-on-error: true

.github/workflows/4-step.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)