-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ekhangal/main
Automated CTFd challenge deployment using `ctfcli`
- Loading branch information
Showing
11 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[challenges] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: CTFd Challenge Deploy | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'challenges/**' | ||
push: | ||
paths: | ||
- 'challenges/**' | ||
branches: [main] | ||
|
||
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 add .ctf/challenges | ||
git commit -m "chore(config): update challenges" | ||
git push | ||
else | ||
echo "No challenges added to config file" | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.