從 Paratranz 下載至 GitHub #3
This file contains 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: 從 Paratranz 下載至 GitHub | |
on: | |
schedule: | |
# 每天台北時間早上 9 點和晚上 9 點執行 | |
- cron: "0 1,13 * * *" | |
workflow_dispatch: | |
jobs: | |
paratranz-to-gitHub: | |
name: 從 Paratranz 下載至 GitHub | |
environment: PARATRANZ_ENV | |
runs-on: ubuntu-latest | |
env: | |
API_TOKEN: ${{ secrets.API_KEY }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PROJECT_ID: ${{ vars.ID }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: 建置 Python 環境 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.13" | |
- name: 安裝模組依賴 | |
run: | | |
pip install requests | |
pip install nbtlib | |
- name: 設置 Git | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" && \ | |
git config --global user.name "VM[BOT]" | |
- name: 簽入到 main 分支 | |
run: git checkout main | |
- name: 從 Paratranz 下載至 GitHub | |
run: python .github/workflows/para2github.py | |
- name: 提交更改 | |
id: commit | |
run: | | |
if [[ -n $(git status -s) ]]; then | |
git add . | |
git commit -m '從 Paratranz 同步翻譯' | |
git push origin main | |
echo "changed=true" >> $GITHUB_ENV | |
else | |
echo "changed=false" >> $GITHUB_ENV | |
fi | |
outputs: | |
changed: ${{ steps.commit.env.changed }} | |
release: | |
name: 創建發布版 | |
runs-on: ubuntu-latest | |
needs: paratranz-to-gitHub | |
if: ${{ needs.paratranz-to-gitHub.outputs.changed == 'true' }} | |
steps: | |
- name: 簽入 | |
uses: actions/checkout@v4 | |
- name: 上傳 ZHTWPack 資料夾 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ZHTWPack | |
path: ${{ github.workspace }}/ZHTWPack | |
- name: 獲取當前系統時間以當作標籤 | |
id: datetime | |
run: echo "datetime=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV | |
- name: 壓縮 ZHTWPack 資料夾 | |
run: zip -r "${{ env.datetime }}.zip" ./ZHTWPack | |
- name: 上傳加工品 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "${{ env.datetime }}.zip" | |
path: "${{ env.datetime }}.zip" | |
- name: 創建發布版 | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "${{ env.datetime }}.zip" | |
tag: "Release-${{ env.datetime }}" | |
name: "Release ${{ env.datetime }}" | |
body: "自動生成最新的翻譯補丁" | |
draft: false | |
prerelease: true |