ScWeb_Chinese_Translate/.github/workflows/main.yml

69 lines
2.8 KiB
YAML
Raw Normal View History

2023-10-10 10:28:34 +08:00
on:
2023-10-10 10:33:10 +08:00
workflow_dispatch:
2023-10-10 10:37:19 +08:00
push:
branches: [ main ]
2023-10-10 10:28:34 +08:00
jobs:
bump_version:
name: Bump Version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
2023-10-10 10:30:28 +08:00
with:
fetch-depth: 2
2023-10-10 10:28:34 +08:00
- name: Get changed files
id: getfile
run: |
2023-10-10 11:28:46 +08:00
files=$(git diff --name-only HEAD^ HEAD | tr '\n' ' ')
2023-10-10 10:28:34 +08:00
echo "::set-output name=files::$files"
- name: Bump version number based on changed files
run: |
2023-10-10 10:43:40 +08:00
increment_version() {
echo "$1" | awk -F. '{$NF = $NF + 1;} 1' OFS=.
}
2023-10-10 10:28:34 +08:00
changed_files="${{ steps.getfile.outputs.files }}"
2023-10-10 11:28:46 +08:00
temp_file=$(mktemp)
cp json/versions.json $temp_file
2023-10-10 10:43:40 +08:00
# Use jq and increment_version function to bump version numbers based on changed files
2023-10-10 10:28:34 +08:00
if echo "$changed_files" | grep -q "addresses.json"; then
new_version=$(increment_version $(jq -r '.addresses' json/locales/versions.json))
2023-10-10 11:28:46 +08:00
jq --arg v "$new_version" '.addresses = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "concierge.json"; then
new_version=$(increment_version $(jq -r '.concierge' json/locales/versions.json))
2023-10-10 11:28:46 +08:00
jq --arg v "$new_version" '.concierge = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "hangar.json"; then
new_version=$(increment_version $(jq -r '.hangar' json/locales/versions.json))
2023-10-10 11:28:46 +08:00
jq --arg v "$new_version" '.hangar = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "orgs.json"; then
new_version=$(increment_version $(jq -r '.orgs' json/locales/versions.json))
2023-10-10 11:28:46 +08:00
jq --arg v "$new_version" '.orgs = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "zh-CN-rsi.json"; then
2023-10-10 11:28:46 +08:00
new_version=$(increment_version $(jq -r '.rsi' $temp_file))
jq --arg v "$new_version" '.rsi = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "zh-CN-uex.json"; then
2023-10-10 11:28:46 +08:00
new_version=$(increment_version $(jq -r '.uex' $temp_file))
jq --arg v "$new_version" '.uex = $v' $temp_file > json/temp.json && mv json/temp.json $temp_file
2023-10-10 10:28:34 +08:00
fi
2023-10-10 11:28:46 +08:00
mv $temp_file json/versions.json
2023-10-10 10:28:34 +08:00
- name: Commit and push changes if there's an update
run: |
if [[ `git status --porcelain` ]]; then
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add json/locales/versions.json
2023-10-10 10:28:34 +08:00
git commit -m "Bump version number" && git push
fi