forked from skills/action-update-step
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
85 lines (76 loc) · 2.73 KB
/
action.yml
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
name: "Update step"
description: "Update the course repository when the learner completes a step."
inputs:
token:
description: "Set to [secrets.GITHUB_TOKEN]."
required: true
from_step:
description: "Requires the STEP file set to FROM_STEP."
required: true
to_step:
description: "The step number to go to next."
required: true
branch_name:
description: "If the learner is working in a branch, add the branch name."
runs:
using: composite
steps:
- shell: bash
run: |
echo "Check that all required env variables are set"
if [ -z "$TO_STEP" ]
then
echo "TO_STEP is unset or set to the empty string"
exit 1
fi
if [ -z "$FROM_STEP" ]
then
echo "FROM_STEP is unset or set to the empty string"
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]
then
echo "GITHUB_TOKEN is unset or set to the empty string"
exit 1
fi
echo "Check that we are on FROM_STEP"
if [ "$(cat .github/script/STEP)" != $FROM_STEP ]
then
echo "Current step is not $FROM_STEP"
exit 0
fi
echo "Make sure we are on the main branch"
git checkout main
echo "Remove 'open' from any <details> tags"
sed -i.tmp -r 's/<details id=([0-9X]+) open>/<details id=\1>/g' README.md
echo "Add 'open' to step TO_STEP"
sed -i.tmp -r "s/<details id=$TO_STEP>/<details id=$TO_STEP open>/g" README.md
echo "Update all HTML comments to hide everything"
sed -i.tmp -r 's/<!--step([0-9X]+)-->/<!--step\1/g' README.md
sed -i.tmp -r 's/<!--endstep([0-9X]+)-->/endstep\1-->/g' README.md
echo "Show the current TO_STEP"
sed -i.tmp -r "s/<\!--step$TO_STEP/<\!--step$TO_STEP-->/g" README.md
sed -i.tmp -r "s/endstep$TO_STEP-->/<\!--endstep$TO_STEP-->/g" README.md
echo "Update the STEP file to TO_STEP"
echo "$TO_STEP" > .github/script/STEP
echo "Commit the files, and push to main"
git config user.name github-actions
git config user.email github-actions@github.com
git add README.md
git add .github/script/STEP
git commit --message="Update to $TO_STEP in STEP and README.md"
git push
echo "If BRANCH_NAME, update that branch as well"
if git show-ref --quiet refs/heads/$BRANCH_NAME
then
git checkout $BRANCH_NAME
git cherry-pick main
git push
else
echo "Branch $BRANCH_NAME does not exist"
fi
env:
GITHUB_TOKEN: ${{ inputs.token }}
FROM_STEP: ${{ inputs.from_step }}
TO_STEP: ${{ inputs.to_step }}
BRANCH_NAME: ${{ inputs.branch_name }}