Skip to content

Commit

Permalink
separate downloads page generation from release workflow (#103)
Browse files Browse the repository at this point in the history
* wip

* add workflow
  • Loading branch information
StefanVukovic99 authored Jul 10, 2024
1 parent c94e402 commit 9b7d155
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/generate-downloads.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Generate downloads page

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install jq
run: sudo apt-get install -y jq

- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Generate markdown table
id: generate_markdown
run: |
./tools/generate-downloads-table.sh > table.md
cat table.md
- name: Write to downloads.md
id: write_downloads_md
shell: bash
run: |
cat downloads-preamble.md table.md > downloads.md
rm table.md
cat downloads.md
- name: Create pull request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Update downloads.md with list of .zip files"
body: "This PR updates the downloads.md file with a table listing all .zip files."
2 changes: 1 addition & 1 deletion languages.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{"iso": "sq", "language": "Albanian", "flag": "🇦🇱"},
{"iso": "grc", "language": "Ancient Greek", "flag": "🏺"},
{"iso": "ar", "language": "Arabic", "flag": "🇪🇬"},
{"iso": "ar", "language": "Arabic", "flag": "🟩"},
{"iso": "zh", "language": "Chinese", "flag": "🇨🇳"},
{"iso": "cs", "language": "Czech", "flag": "🇨🇿"},
{"iso": "nl", "language": "Dutch", "flag": "🇳🇱"},
Expand Down
25 changes: 8 additions & 17 deletions tools/generate-downloads-table.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
find data/language -type f -name '*.zip' > zip_files.txt

check_file_exists() {
local filename=$1
while IFS= read -r file; do
# Extract the part of the path after 'kty-' and before the '.zip'
extracted_name=$(basename "$file" .zip | sed 's/^kty-//')
if [ "$extracted_name" = "$filename" ]; then
return 0
fi
done < zip_files.txt
return 1
}

declare -a languages="($(
jq -r '.[] | @json | @sh' languages.json
))"
Expand All @@ -22,8 +8,9 @@ columns=("en" "zh" "fr" "de" "ru" "es" "ipa")
for source_lang in "${languages[@]}"; do
source_iso=$(echo "${source_lang}" | jq -r '.iso')
source_language_name=$(echo "${source_lang}" | jq -r '.language')
flag=$(echo "${source_lang}" | jq -r '.flag')

row="| $source_language_name ($source_iso)"
row="| $flag </br> $source_language_name ($source_iso)"

for column in "${columns[@]}"; do

Expand All @@ -35,9 +22,13 @@ for source_lang in "${languages[@]}"; do

cell=""
for expected_filename in "${expected_filenames[@]}"; do
if check_file_exists "$expected_filename"; then
cell="$cell [kty-$expected_filename.zip](https://github.com/themoeway/kaikki-to-yomitan/releases/latest/download/kty-$expected_filename.zip) </br>"
if [[ "$expected_filename" == *"-ipa" ]]; then
display_filename="IPA for ${expected_filename%-ipa}"
else
display_filename="$expected_filename"
fi

cell="$cell [$display_filename](https://github.com/themoeway/kaikki-to-yomitan/releases/latest/download/kty-$expected_filename.zip) </br>"
done
row="$row | $cell"
done
Expand Down

0 comments on commit 9b7d155

Please sign in to comment.