-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (159 loc) · 6.97 KB
/
Copy path2-commit-a-file.yml
File metadata and controls
186 lines (159 loc) · 6.97 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Step 2 # Créer un fichier et un commit
on:
push:
branches:
- "my-first-branch"
paths:
- "PROFILE.md"
workflow_dispatch:
concurrency:
group: github-basics-step-2-${{ github.repository }}
cancel-in-progress: true
permissions:
contents: read
actions: write
issues: write
env:
STEP_3_FILE: ".github/steps/3-open-a-pull-request.md"
TOOLKIT_REPOSITORY: "ENSTARobotics/exercise-toolkit-fr"
TOOLKIT_REF: "19f8395fee473aca8af74039182a41cdda9ab0e3"
jobs:
find_exercise:
if: |
!github.event.repository.is_template &&
github.ref_name == 'my-first-branch'
name: Retrouver l'Issue de l'exercice
uses: ENSTARobotics/exercise-toolkit-fr/.github/workflows/find-exercise-issue.yml@19f8395fee473aca8af74039182a41cdda9ab0e3
check_step_work:
name: Vérifier le fichier et le commit
runs-on: ubuntu-latest
needs: [find_exercise]
env:
ISSUE_REPOSITORY: ${{ github.repository }}
ISSUE_NUMBER: ${{ needs.find_exercise.outputs.issue-number }}
steps:
- name: Récupérer la branche de travail
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: my-first-branch
fetch-depth: 0
- name: Récupérer les templates français
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: ${{ env.TOOLKIT_REPOSITORY }}
path: exercise-toolkit-fr
ref: ${{ env.TOOLKIT_REF }}
- name: Retrouver le dernier commentaire de progression
id: find-last-comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
direction: last
- name: Indiquer que le travail est en cours de vérification
uses: GrantBirki/comment@608e41b19bc973020ec0e189ebfdae935d7fe0cc # v2.1.1
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
comment-id: ${{ steps.find-last-comment.outputs.comment-id }}
file: exercise-toolkit-fr/markdown-templates/step-feedback/checking-work.md
edit-mode: replace
- name: Vérifier que PROFILE.md existe
id: check-file
continue-on-error: true
uses: skills/exercise-toolkit/actions/file-exists@09fa94f97127fbd0a9c99e25e1505043791cc451 # v0.7.1
with:
file: PROFILE.md
- name: Vérifier que PROFILE.md contient Hello
id: check-content
continue-on-error: true
uses: skills/action-keyphrase-checker@7f463836f6c105e85a182487ae4b628ff61cb904 # v1
with:
text-file: PROFILE.md
keyphrase: Hello
case-sensitive: false
- name: Publier les résultats
uses: GrantBirki/comment@608e41b19bc973020ec0e189ebfdae935d7fe0cc # v2.1.1
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
comment-id: ${{ steps.find-last-comment.outputs.comment-id }}
edit-mode: replace
file: exercise-toolkit-fr/markdown-templates/step-feedback/step-results-table.md
vars: |
step_number: 2
results_table:
- description: "Le fichier PROFILE.md existe"
passed: ${{ steps.check-file.outcome == 'success' }}
- description: "PROFILE.md contient le mot Hello"
passed: ${{ steps.check-content.outcome == 'success' }}
- name: Arrêter si une vérification échoue
if: contains(steps.*.outcome, 'failure')
run: exit 1
post_next_step_content:
name: Afficher l'étape 3
needs: [find_exercise, check_step_work]
runs-on: ubuntu-latest
env:
ISSUE_REPOSITORY: ${{ github.repository }}
ISSUE_NUMBER: ${{ needs.find_exercise.outputs.issue-number }}
steps:
- name: Récupérer le contenu pédagogique depuis main
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: main
- name: Récupérer les templates français
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
repository: ${{ env.TOOLKIT_REPOSITORY }}
path: exercise-toolkit-fr
ref: ${{ env.TOOLKIT_REF }}
- name: Confirmer l'étape terminée
uses: GrantBirki/comment@608e41b19bc973020ec0e189ebfdae935d7fe0cc # v2.1.1
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
file: exercise-toolkit-fr/markdown-templates/step-feedback/step-finished-prepare-next-step.md
vars: |
next_step_number: 3
- name: Publier l'étape 3
uses: GrantBirki/comment@608e41b19bc973020ec0e189ebfdae935d7fe0cc # v2.1.1
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
file: ${{ env.STEP_3_FILE }}
- name: Activer l'étape 3 et rattraper une PR déjà ouverte
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
current_state="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/2-commit-a-file.yml" --jq '.state')"
if [ "$current_state" = "active" ]; then
gh api --method PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/2-commit-a-file.yml/disable"
fi
next_state="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/3-open-a-pull-request.yml" --jq '.state')"
if [ "$next_state" != "active" ]; then
gh api --method PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/3-open-a-pull-request.yml/enable"
fi
for attempt in {1..10}; do
next_state="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/3-open-a-pull-request.yml" --jq '.state')"
if [ "$next_state" = "active" ]; then
break
fi
sleep 1
done
if [ "$next_state" != "active" ]; then
echo "Le workflow suivant n'est pas devenu actif à temps."
exit 1
fi
# Laisse à GitHub le temps d'enregistrer un événement déjà parti.
sleep 2
head_sha="$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/my-first-branch" --jq '.object.sha')"
pr_number="$(gh pr list --head my-first-branch --base main --state all --limit 20 --json number,headRefOid --jq ".[] | select(.headRefOid == \"$head_sha\") | .number" | head -n 1)"
if [ -n "$pr_number" ]; then
run_count="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/3-open-a-pull-request.yml/runs?head_sha=$head_sha&per_page=1" --jq '.total_count')"
if [ "$run_count" -eq 0 ]; then
echo "La pull request #$pr_number existe déjà : lancement immédiat de l'étape 3."
gh workflow run 3-open-a-pull-request.yml --ref main -f pr-number="$pr_number"
fi
fi