on: workflow_dispatch: pull_request: branches: - main - json-improvement types: [closed] push: branches: [ main ] jobs: bump_version: name: Bump Version runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 with: fetch-depth: 2 - 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: | increment_version() { echo "$1" | awk -F. '{$NF = $NF + 1;} 1' OFS=. } changed_files="${{ steps.getfile.outputs.files }}" # Use jq and increment_version function to bump version numbers based on changed files if echo "$changed_files" | grep -q "addresses.json"; then 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 fi if echo "$changed_files" | grep -q "concierge.json"; then 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 fi if echo "$changed_files" | grep -q "hangar.json"; then 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 fi if echo "$changed_files" | grep -q "orgs.json"; then 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 fi if echo "$changed_files" | grep -q "zh-CN-rsi.json"; then 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 fi if echo "$changed_files" | grep -q "zh-CN-uex.json"; then 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 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