Sync Releases #258
This file contains hidden or 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
| name: Sync Releases | |
| on: | |
| workflow_dispatch: # Enables manual run | |
| schedule: | |
| - cron: "0 0 * * *" # Runs daily at midnight | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Allow write permissions to commit and push changes | |
| steps: | |
| - name: Fetch Latest Release Info | |
| run: | | |
| owner="WorldEnd" | |
| repo="worldend-formatting" | |
| url="https://api.github.com/repos/${owner}/${repo}/releases/latest" | |
| response=$(curl -s "$url") | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to fetch release data." | |
| exit 1 | |
| fi | |
| tag_name=$(echo "$response" | grep -oP '"tag_name": "\K[^"]+') | |
| if [ -z "$tag_name" ]; then | |
| echo "Tag name not found." | |
| exit 1 | |
| fi | |
| echo "tag_name=$tag_name" >>$GITHUB_ENV | |
| echo "source_tar=https://github.com/${owner}/${repo}/archive/refs/tags/${tag_name}.tar.gz" >>$GITHUB_ENV | |
| echo "volume_base=https://github.com/${owner}/${repo}/releases/download/${tag_name}" >>$GITHUB_ENV | |
| - name: Checkout GitHub Pages Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: worldend.github.io | |
| fetch-depth: 1 # Only fetch the latest commit | |
| - name: Cache Volume Text | |
| uses: actions/cache@v4 | |
| with: | |
| path: worldend-formatting | |
| key: volume-text-${{ runner.os }}-${{ env.tag_name }} | |
| - name: Download and Extract Release | |
| run: | | |
| if [ -d "worldend-formatting" ]; then | |
| echo "Directory already exists" | |
| else | |
| echo "Downloading and extracting the tar.gz file for the latest release" | |
| curl -L -o "worldend-formatting.tar.gz" "$source_tar" | |
| tar -xzvf "worldend-formatting.tar.gz" | |
| mv "worldend-formatting-${tag_name#v}" "worldend-formatting" | |
| echo "Download and extraction completed successfully." | |
| rm "worldend-formatting.tar.gz" | |
| fi | |
| - name: Process Files | |
| run: | | |
| mkdir -p worldend.github.io/_releases | |
| output_file="worldend.github.io/releases.md" | |
| { | |
| echo "---" | |
| echo "layout: article" | |
| echo "title: Releases" | |
| echo "key: page-releases" | |
| echo "---" | |
| echo "" | |
| } >"$output_file" | |
| for volume_dir in worldend-formatting/Volumes/*; do | |
| config_file="$volume_dir/config.yaml" | |
| volume=$(yq e '.volume_number' "$config_file") | |
| padded_volume=$(printf "%02d" "$volume") | |
| dest_volume_dir="worldend.github.io/_releases/volume_${padded_volume}" | |
| mkdir -p "$dest_volume_dir" | |
| image_dest_dir="assets/images/volume_${padded_volume}" | |
| cover_image_dest_dir="$image_dest_dir/cover" | |
| chapter_image_dest_dir="$image_dest_dir/chapter" | |
| insert_image_dest_dir="$image_dest_dir/insert" | |
| mkdir -p "worldend.github.io/$cover_image_dest_dir" | |
| mkdir -p "worldend.github.io/$chapter_image_dest_dir" | |
| mkdir -p "worldend.github.io/$insert_image_dest_dir" | |
| cp -r "$volume_dir/Images/Chapter/"* "worldend.github.io/$chapter_image_dest_dir" | |
| { | |
| echo "---" | |
| echo "layout: article" | |
| echo "title: WorldEnd2 Volume $volume – Illustrations" | |
| echo "---" | |
| echo "" | |
| } >"$dest_volume_dir/0.md" | |
| cover_count=$(yq e '.cover | length' "$volume_dir/Images/config.yaml") | |
| for cover in $(seq 1 "$cover_count"); do | |
| cover_image=$(yq e ".cover | keys | .[$((cover - 1))]" "$volume_dir/Images/config.yaml") | |
| image_type=$(yq e ".cover[\"$cover_image\"].image_type" "$volume_dir/Images/config.yaml") | |
| if [[ $image_type == "front_cover" ]]; then | |
| cp "$volume_dir/Images/Cover/$cover_image" "worldend.github.io/$cover_image_dest_dir/front.png" | |
| { | |
| echo "## Front Cover" | |
| echo -e "{:.border.shadow.rounded}\n" | |
| } >>"$dest_volume_dir/0.md" | |
| elif [[ $image_type == "back_cover" ]]; then | |
| back_cover="$cover_image" | |
| fi | |
| done | |
| insert_count=$(yq e '.insert | length' "$volume_dir/Images/config.yaml") | |
| if [[ $insert_count -gt 0 ]]; then | |
| echo "## Inserts" >>"$dest_volume_dir/0.md" | |
| fi | |
| for insert in $(seq 1 "$insert_count"); do | |
| insert_image=$(yq e ".insert | keys | .[$((insert - 1))]" "$volume_dir/Images/config.yaml") | |
| image_type=$(yq e ".insert[\"$insert_image\"].image_type" "$volume_dir/Images/config.yaml") | |
| if [[ $image_type != "toc" && $image_type != "filler" ]]; then | |
| cp "$volume_dir/Images/Insert/$insert_image" "worldend.github.io/$insert_image_dest_dir" | |
| echo -e "{:.border.shadow.rounded}\n" >>"$dest_volume_dir/0.md" | |
| fi | |
| done | |
| if [[ -n $back_cover ]]; then | |
| cp "$volume_dir/Images/Cover/$back_cover" "worldend.github.io/$cover_image_dest_dir/back.png" | |
| { | |
| echo "## Back Cover" | |
| echo -e "{:.border.shadow.rounded}\n" | |
| } >>"$dest_volume_dir/0.md" | |
| fi | |
| { | |
| echo "## Volume $volume" | |
| echo "{:.image.image--lg.border.shadow.rounded}" | |
| echo "" | |
| echo "[Download EPUB]($volume_base/WorldEnd2-v${padded_volume}.epub){:.button.button--primary.button--rounded}" | |
| echo "[Download PDF]($volume_base/WorldEnd2-v${padded_volume}.pdf){:.button.button--primary.button--rounded}" | |
| echo "" | |
| echo "- [Illustrations]({{ \"/releases/volume_${padded_volume}/0.html\" | relative_url }})" | |
| } >>"$output_file" | |
| chapter_count=$(yq e '.chapters | length' "$config_file") | |
| for chapter_index in $(seq 1 "$chapter_count"); do | |
| chapter_title=$(yq e ".chapters[$((chapter_index - 1))].title" "$config_file") | |
| part_count=$(yq e ".chapters[$((chapter_index - 1))].parts | length" "$config_file") | |
| chapter_printed=false | |
| for part_index in $(seq 1 "$part_count"); do | |
| part_title=$(yq e ".chapters[$((chapter_index - 1))].parts[$((part_index - 1))].title" "$config_file") | |
| if [[ $part_title == "null" ]]; then | |
| file="$volume_dir/Text/$chapter_index.md" | |
| header="---\n" | |
| header+="layout: article\n" | |
| header+="title: WorldEnd2 Volume $volume – Chapter $chapter_index | $chapter_title\n" | |
| else | |
| file="$volume_dir/Text/$chapter_index.$part_index.md" | |
| header="---\n" | |
| header+="layout: article\n" | |
| header+="title: WorldEnd2 Volume $volume – Chapter $chapter_index, Part $part_index | $part_title\n" | |
| fi | |
| header+="---\n\n" | |
| if [[ $part_index -eq 1 ]]; then | |
| header+=")]" "$volume_dir/Images/config.yaml")\" | relative_url }}){:.border.shadow.rounded}\n" | |
| fi | |
| if [[ -f $file ]]; then | |
| cat <(echo -e "$header") "$file" >"$dest_volume_dir/$(basename "$file")" | |
| fi | |
| file_path="{{ \"/releases/volume_${padded_volume}/$(basename "$file" .md).html\" | relative_url }}" | |
| if [[ $chapter_printed == false ]]; then | |
| if [[ $part_title != "null" ]]; then | |
| echo "- Chapter $chapter_index \| $chapter_title" >>"$output_file" | |
| else | |
| echo "- [Chapter $chapter_index \| $chapter_title]($file_path)" >>"$output_file" | |
| fi | |
| chapter_printed=true | |
| fi | |
| if [[ $part_title != "null" ]]; then | |
| echo " - [Part $part_index \| $part_title]($file_path)" >>"$output_file" | |
| fi | |
| done | |
| done | |
| echo "" >>"$output_file" | |
| done | |
| { | |
| echo "## Google Docs Translation Index" | |
| echo "For unfinished volumes and side-stories, you can check out our [Google Docs Translation Index](https://docs.google.com/document/d/16EOH4sCjJKkgEeGSW4T0kZXWLoove4iBvGZz_hf7xeU/edit)." | |
| } >>"$output_file" | |
| - name: Commit | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| repository: worldend.github.io | |
| commit_message: Sync Releases | |
| skip_fetch: true | |
| skip_checkout: true |