Skip to content

Commit

Permalink
ci: 新增自動更新模組清單流程 (#129)
Browse files Browse the repository at this point in the history
歷史提交:
* ci: 新增自動更新模組清單流程

docs(ModsList): 增加 CITResewn 狀態
  • Loading branch information
xMikux authored Jan 27, 2023
1 parent c552659 commit 379067b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 36 deletions.
93 changes: 57 additions & 36 deletions .github/scripts/assets_folder.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
#!/bin/bash

list_dir () {
find ../assets/ -maxdepth 1 -type d -exec echo "$1" \; > "$2"
make_file () {
file_name=ModsList.md
touch $file_name
{
echo "# 模組清單"
echo ""
echo "此清單用於記錄模組翻譯回饋回該模組專案的記錄"
echo ""
echo "| 模組名稱 | 貢獻 | PR | 翻譯變動 |"
echo "| ------ | ------ | ------ | ------ |"
} > $file_name
}

readme_generate () {
file_name=readme_result.md
list_dir '<li>{}</li>' $file_name
sed -i "s+<li>../assets/</li>++" $file_name
sed -i "s+<li>../assets/minecraft</li>++" $file_name
sed -i "s+../assets/++" $file_name
sed -i "/^$/d" $file_name
list_dir () {
find assets/ -maxdepth 1 -type d -exec echo "$1" \; >> "$2"
}

modslist_generate () {
file_name=modslist_result.md
list_dir '| {} | :x: | | |' $file_name
sed -i "1s+| ../assets/ | :x: | | |++" $file_name
sed -i "s+| {} | ../assets/minecraft | :x: | | |++" $file_name
sed -i "s+../assets/++" $file_name
sed -i "/^$/d" $file_name
file_name=modslist_result.md
list_dir '| {} | :x: | | |' $file_name
sed -i "1s+| assets/ | :x: | | |++" $file_name
sed -i "s+assets/++" $file_name
sed -i "/^$/d" $file_name
}

modslist_added_mod_generate () {
file_name=modslist_result.md
x_placeholder=" | :x: | | |"
question_placeholder=" | :question: |"
check_placeholder=" | :heavy_check_mark: |"

if [ "$1" = 1 ]; then
sed -i "s+$2$x_placeholder+$2$check_placeholder [已回饋]($3) | |+" $file_name
elif [ "$1" = 2 ]; then
sed -i "s+$2$x_placeholder+$2$check_placeholder [已回饋]($3) | :heavy_exclamation_mark: |+" $file_name
elif [ "$1" = 3 ]; then
sed -i "s+$2$x_placeholder+$2$question_placeholder [等待合併]($3) | |+" $file_name
elif [ "$1" = 4 ]; then
sed -i "s+$2$x_placeholder+$2$question_placeholder 已提交上 Crowdin(或同步) | |+" $file_name
fi
file_name=modslist_result.md
x_placeholder=" | :x: | | |"
question_placeholder=" | :question: |"
check_placeholder=" | :heavy_check_mark: |"

if [ "$1" = 1 ]; then
sed -i "s+$2$x_placeholder+$2$check_placeholder [已回饋]($3) | |+" $file_name
elif [ "$1" = 2 ]; then
sed -i "s+$2$x_placeholder+$2$check_placeholder [已回饋]($3) | :heavy_exclamation_mark: |+" $file_name
elif [ "$1" = 3 ]; then
sed -i "s+$2$x_placeholder+$2$question_placeholder [等待合併]($3) | |+" $file_name
elif [ "$1" = 4 ]; then
sed -i "s+$2$x_placeholder+$2$question_placeholder Crowdin | |+" $file_name
fi
}

sort_file () {
sort -o modslist_result_sorted.md modslist_result.md
}

combind_file () {
cat modslist_result_sorted.md >> ModsList.md
mv ModsList.md docs/ModsList.md
rm modslist_result_sorted.md modslist_result.md
}

# Main
readme_generate
modslist_generate

## Status Code
Expand Down Expand Up @@ -73,17 +85,26 @@ modslist_added_mod_generate "2" "fluxnetworks" "https://github.com/SonarSonic/Fl
modslist_added_mod_generate "1" "yet-another-config-lib" "https://github.com/isXander/YetAnotherConfigLib/pull/31"

### ExNihiloSequentia
modslist_added_mod_generate "3" "exnihiloae" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "3" "exnihilomekanism" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "3" "exnihilosequentia" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "3" "exnihilothermal" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "3" "exnihilotinkers" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "1" "exnihiloae" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "1" "exnihilomekanism" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "1" "exnihilosequentia" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "1" "exnihilothermal" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"
modslist_added_mod_generate "1" "exnihilotinkers" "https://github.com/NovaMachina-Mods/ExNihiloSequentia/pull/380"

### LanguageReload
modslist_added_mod_generate "3" "languagereload" "https://github.com/Jerozgen/LanguageReload/pull/20"
modslist_added_mod_generate "1" "languagereload" "https://github.com/Jerozgen/LanguageReload/pull/20"

### BorderlessMining
modslist_added_mod_generate "1" "borderlessmining" "https://github.com/comp500/BorderlessMining/pull/56"

### SlimefunToEMI
modslist_added_mod_generate "3" "sftoemi" "https://github.com/JustAHuman-xD/SlimefunToEMI/pull/2"

### CITResewn
modslist_added_mod_generate "1" "citresewn" "https://github.com/SHsuperCM/CITResewn/pull/219"
modslist_added_mod_generate "1" "citresewn-defaults" "https://github.com/SHsuperCM/CITResewn/pull/219"

# Finish
sort_file
make_file
combind_file
47 changes: 47 additions & 0 deletions .github/workflows/ModsList-Updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ModsList Updater

on:
workflow_dispatch: {}
schedule:
- cron: "0 0 * * 1"

permissions:
contents: write
pull-requests: write

jobs:
Updater:
name: ModsList docs updater
runs-on: ubuntu-latest

steps:
- name: Checking Repostiory
uses: actions/checkout@v3

- name: Run script
run: ./.github/scripts/assets_folder.sh

- name: Date
id: date
run: |
echo "date=$(date)" >> $GITHUB_OUTPUT
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
branch: "docs/action-modslist"
commit-message: "docs(ModsList): 更新模組清單"
title: "docs(ModsList): 更新模組清單"
body: |
自動化 [GitHub Action][github-action] 更新模組清單文件。
產生時間:${{ steps.date.outputs.date }}
------
由 [create-pull-request][cpr] 製作
[cpr]: https://github.com/peter-evans/create-pull-request
[github-action]: https://github.com/features/actions
labels: |
📃 文件

0 comments on commit 379067b

Please sign in to comment.