-
Notifications
You must be signed in to change notification settings - Fork 3
74 lines (72 loc) · 2.54 KB
/
ctfd-deploy.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
name: CTFd Challenge Deploy
on:
pull_request:
paths:
- 'challenges/**'
push:
paths:
- 'challenges/**'
jobs:
challenge-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
- name: Install ctfcli
run: |
python -m pip install --upgrade pip
pip install ctfcli
- name: Set up ctfcli config
run: |
CONFIG="[config]\n\
url = ${{ secrets.CTFD_URL }}\n\
access_token = ${{ secrets.CTFD_TOKEN }}\n\
\n"
echo -e "$CONFIG" > .ctf/config
cat .ctf/challenges >> .ctf/config
- name: Lint and deploy challenges
run: |
shopt -s globstar
CHANGED_CHALLENGES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '^challenges/')
for CHAL_DIR in $CHANGED_CHALLENGES; do
echo "LINTING CHALLENGE FILE: $CHAL_DIR"
ctf challenge lint "$CHAL_DIR"
echo "CHECKING IF CHALLENGE IS INSTALLED: $CHAL_DIR"
if ! cat .ctf/config | grep -q "$CHAL_DIR"; then
echo "INSTALLING CHALLENGE TO CTFd: $CHAL_DIR"
ctf challenge install "$CHAL_DIR"
ctf challenge add "$CHAL_DIR"
continue
else
echo "CHALLENGE ALREADY INSTALLED: $CHAL_DIR"
fi
echo "SYNCING CHALLENGE TO CTFd: $CHAL_DIR"
ctf challenge sync "$CHAL_DIR"
done
shell: bash
- name: Push ctfcli config file
run: |
if cat .ctf/config | grep -q 'challenge.yml'; then
NEW_CHALLENGES=$(sed -n '/challenge.yml/p' .ctf/config)
while IFS= read -r LINE; do
if ! grep -q "$LINE" .ctf/challenges; then
echo -e "$LINE" >> .ctf/challenges
echo "ADDED NEW CHALLENGE TO .ctf/challenge: $LINE"
fi
done <<< "$NEW_CHALLENGES"
if [ -s .ctf/challenges ]; then
echo -e "$NEW_CHALLENGES" >> .ctf/challenges
git config user.name github-actions
git config user.email [email protected]
git checkout ${GITHUB_REF_NAME}
git add .ctf/challenges
git commit -m "chore(config): update challenges"
git push
else
echo "No challenges added to config file"
fi
fi