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:28:34 +08:00
pull_request:
branches:
- main
- json-improvement
2023-10-10 10:33:10 +08:00
types: [closed]
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: |
files=$(git diff --name-only HEAD^ HEAD)
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 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
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.addresses' json/versions.json))
jq --arg v "$new_version" '.addresses = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "concierge.json"; then
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.concierge' json/versions.json))
jq --arg v "$new_version" '.concierge = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "hangar.json"; then
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.hangar' json/versions.json))
jq --arg v "$new_version" '.hangar = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "orgs.json"; then
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.orgs' json/versions.json))
jq --arg v "$new_version" '.orgs = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "zh-CN-rsi.json"; then
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.rsi' json/versions.json))
jq --arg v "$new_version" '.rsi = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
if echo "$changed_files" | grep -q "zh-CN-uex.json"; then
2023-10-10 10:43:40 +08:00
new_version=$(increment_version $(jq -r '.uex' json/versions.json))
jq --arg v "$new_version" '.uex = $v' json/versions.json > json/temp.json && mv json/temp.json json/versions.json
2023-10-10 10:28:34 +08:00
fi
- 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/versions.json
git commit -m "Bump version number" && git push
fi