-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (92 loc) · 3.47 KB
/
ctfd.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Sync CTFd
on: [workflow_call] # allow this workflow to be called from other workflows
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create .ctf/config file
run: |
mkdir -p .ctf
echo "${{ secrets.CTF_CLI_CONFIG }}" > .ctf/config
- name: Install ctfcli
run: |
python -m pip install --upgrade pip
pip install git+https://github.com/apogiatzis/ctfcli
- name: Challenge discovery
id: challenge-discovery
uses: ./.github/actions/discover-challenges
with:
base-dir: '.'
- uses: actions/cache/restore@v3
id: challenges-hashes-cache
with:
path: .cache/last_hashes
key: ctfd-pipeline-last-hashes
- name: Create folder challenge hashes
id: challenge-hashes
run: |
if [ -d .cache ]; then
rm -f .cache/hashes
fi
mkdir -p .cache
touch .cache/hashes
IFS=' ' read -r -a challenge_dirs <<< "${{ steps.challenge-discovery.outputs.dirs }}"
for dir in "${challenge_dirs[@]}"; do
echo "$(find $dir -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum | cut -d " " -f 1) $dir" >> .cache/hashes
done
sort .cache/hashes -o .cache/hashes
- name: Find modified challenges
id: modified-chalenges
run: |
COMMIT_MESSAGE=$(git log --format=%B -n 1)
if [[ "$COMMIT_MESSAGE" == *"[no-cache]"* ]]; then
rm -f .cache/last_hashes
fi
touch .cache/last_hashes
changes=$(diff .cache/hashes .cache/last_hashes) || true
if [[ -n "$changes" ]]; then
changed_dirs=$(echo "$changes" | grep '<' | cut -d ' ' -f 3-)
echo "$changed_dirs"
fi
mv .cache/hashes .cache/last_hashes
echo dirs="${changed_dirs//$'\n'/ }" >> "$GITHUB_OUTPUT"
- name: Changed challenges list
run: echo "${{ steps.modified-chalenges.outputs.dirs }}"
- name: Challenge Sync
id: challenge-sync
run: |
IFS=' ' read -r -a chall_dirs <<< "${{ steps.modified-chalenges.outputs.dirs }}"
for dir in "${chall_dirs[@]}"; do
ctf challenge install ${dir}
ctf challenge sync ${dir}
done
echo "dirs=${dirs[*]}" >> "$GITHUB_OUTPUT"
- name: Clear cache
uses: actions/github-script@v6
with:
script: |
console.log("About to clear")
const cachesToDelete = ["ctfd-pipeline-last-hashes"];
const caches = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
})
for (const cache of caches.data.actions_caches) {
if (cachesToDelete.includes(cache.key)) {
console.log(cache)
github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id,
})
}
}
console.log("Clear completed")
- name: Save folder challenge hashes
id: challenge-hashes-save
uses: actions/cache/save@v3
with:
path: .cache/last_hashes
key: ctfd-pipeline-last-hashes