Skip to content

Commit

Permalink
Merge pull request #1 from ekhangal/main
Browse files Browse the repository at this point in the history
Automated CTFd challenge deployment using `ctfcli`
  • Loading branch information
ulambayar0511 authored Oct 29, 2023
2 parents 59f8572 + babb1a9 commit 921dd80
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ctf/challenges
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[challenges]
74 changes: 74 additions & 0 deletions .github/workflows/ctfd-deploy.yml
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ This repository lists most of the challenges used in the CTF Night, as well as m

## Contributing

### Challenge Creator's Checklist

Before submitting a pull request (PR), please make sure to:

- [ ] Your challenge includes a `challenge.yml` file. If not, refer to the [challenge specification](https://github.com/CTFd/ctfcli/blob/master/ctfcli/spec/challenge-example.yml) for guidance using the **ctfcli** tool.
- [ ] Each challenge must have a unique name. Existing challenge names can be found in the [.ctf/challenges](.ctf/challenges) config file.
- [ ] Follow the repository structure. Create a directory for your challenge to store necessary source files. Do not modify or delete `.ctf/`, `.github/workflow/`, and `infra/` directories.
- [ ] Your challenges must have a healthcheck script if it is deployable. For automatically deployment, Dockerization is **required**.

### Contributing Guidelines

Read through our [contributing guidelines](CONTRIBUTING.md) to learn about our submission process, coding rules, and more.
Expand Down
Empty file added challenges/crypto/.gitkeep
Empty file.
Empty file added challenges/forensics/.gitkeep
Empty file.
Empty file added challenges/misc/.gitkeep
Empty file.
Empty file added challenges/osint/.gitkeep
Empty file.
Empty file added challenges/programming/.gitkeep
Empty file.
Empty file added challenges/pwn/.gitkeep
Empty file.
Empty file added challenges/reverse/.gitkeep
Empty file.
Empty file added challenges/web/.gitkeep
Empty file.

0 comments on commit 921dd80

Please sign in to comment.