forked from skills/action-update-step
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
88 lines (81 loc) · 2.87 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
86
87
88
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.txt 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."
base_branch_name:
description: "Optional base branch name (default: main)."
required: false
default: "main"
runs:
using: composite
steps:
- shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
FROM_STEP: ${{ inputs.from_step }}
TO_STEP: ${{ inputs.to_step }}
BRANCH_NAME: ${{ inputs.branch_name }}
BASE_BRANCH_NAME: ${{ inputs.base_branch_name }}
CLIENT_NAME: ${{ secrets.CLIENT_NAME }}
TRAINING_GUIDE_URL: ${{ secrets.TRAINING_GUIDE_URL }}
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 "Make sure we are on the base branch ($BASE_BRANCH_NAME)"
git checkout $BASE_BRANCH_NAME
echo "Check that we are on FROM_STEP"
if [ "$(cat .github/steps/-step.txt)" != $FROM_STEP ]
then
echo "Current step is not $FROM_STEP"
exit 0
fi
echo "Update the step to TO_STEP"
NEXT_STEP=$(cat .github/steps/[$TO_STEP]-*.md)
HEADER=$(awk '/<header>/,/<\/header>/' README.md)
FOOTER=$(awk '/<footer>/,/<\/footer>/' README.md)
echo -e "$HEADER\n\n$NEXT_STEP\n\n$FOOTER" > README.md
echo "Update variables"
sed -i "s/CLIENT_NAME/$CLIENT_NAME/g" README.md
sed -i "s/TRAINING_GUIDE_URL/$TRAINING_GUIDE_URL/g" README.md
echo "Update step file to TO_STEP"
echo "$TO_STEP" > .github/steps/-step.txt
echo "Commit the files, and push to base branch"
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add README.md
git add .github/steps/-step.txt
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 $BASE_BRANCH_NAME
git push
else
echo "Branch $BRANCH_NAME does not exist"
fi