Skip to content

Commit 491f64a

Browse files
authored
updated directory writer to be written in julia
1 parent 40586f4 commit 491f64a

File tree

2 files changed

+70
-13
lines changed

2 files changed

+70
-13
lines changed
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Directory writer
2-
on:
3-
schedule:
2+
on: [push]
3+
#schedule:
44
# ┌───────────── minute (0 - 59)
55
# │ ┌───────────── hour (0 - 23)
66
# │ │ ┌───────────── day of the month (1 - 31)
@@ -10,20 +10,24 @@ on:
1010
# │ │ │ │ │
1111
# │ │ │ │ │
1212
# * * * * *
13-
- cron: '0 0 * * *'
14-
workflow_dispatch:
13+
#- cron: '21 * * * *'
14+
#workflow_dispatch:
1515
jobs:
1616
build:
17-
if: github.repository == 'TheAlgorithms/Julia' # We only need this to run in our repository.
1817
runs-on: ubuntu-latest
1918
steps:
2019
- uses: actions/checkout@v4
20+
- name: Get Julia v1.8
21+
uses: julia-actions/setup-julia@v1
2122
with:
22-
fetch-depth: 0
23-
- name: Build directory
24-
uses: TheAlgorithms/scripts/directory_md@main
25-
with:
26-
language: Julia
27-
working-directory: src
28-
filetypes: jl
29-
ignored-directories: docs/,pluto_notebooks/,test/
23+
version: 1.8
24+
- name: Build DIRECTORY.md
25+
run: julia scripts/directory_writer.jl | tee DIRECTORY.md
26+
- name: Update DIRECTORY.md
27+
run: |
28+
git config --global user.name github-actions
29+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
30+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
31+
git add DIRECTORY.md
32+
git commit -am "updating DIRECTORY.md" || true
33+
git push --force origin HEAD:$GITHUB_REF || true

scripts/directory_writer.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
URL_BASE = "https://github.com/TheAlgorithms/Julia/blob/HEAD/src"
2+
3+
function get_list_files(path, extension=".jl")
4+
list_files = []
5+
dir_names = String[]
6+
for (root, dirs, files) in walkdir(path)
7+
current_dir = String[]
8+
strip_root = replace(root, "src/" => "")
9+
if strip_root != "src"
10+
push!(dir_names, strip_root)
11+
end
12+
for file in files
13+
if file == "TheAlgorithms.jl"
14+
continue
15+
end
16+
if endswith(file, extension)
17+
push!(current_dir, replace(file, extension => ""))
18+
end
19+
end
20+
if length(current_dir) > 0
21+
push!(list_files, current_dir)
22+
end
23+
end
24+
return list_files, dir_names
25+
end
26+
27+
function title(words)
28+
words = split(replace(lowercase(words), " " => "_"), "_")
29+
titled_words = [uppercasefirst(word) for word in words]
30+
return join(titled_words, " ")
31+
end
32+
33+
function print_directory()
34+
outputs = "\n## TheAlgorithms\n"
35+
files, dirs = get_list_files("src")
36+
for i in eachindex(dirs)
37+
factor = 1
38+
if contains(dirs[i], "/")
39+
dir = split(dirs[i], "/")
40+
factor = length(dir)
41+
dir = dir[end]
42+
else
43+
dir = dirs[i]
44+
end
45+
outputs *= " " ^ factor * "* $(title(dir))\n"
46+
for j in files[i]
47+
outputs *= " " ^ factor * " * [$(title(j))]($URL_BASE/$(dirs[i])/$(replace(j, " " => "%20")).jl)\n"
48+
end
49+
end
50+
println(outputs)
51+
end
52+
53+
print_directory()

0 commit comments

Comments
 (0)