Skip to content

Commit a656675

Browse files
committed
feat: Add "update-version.yml"
1 parent e202525 commit a656675

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Update Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The version that is going to be used."
8+
required: true
9+
10+
env:
11+
README_PATH: "README.md"
12+
PACKAGE_PATH: "Assets/Plugins/LocalizationExtension"
13+
BASE_BRANCH: ${{ github.ref_name }}
14+
HEAD_BRANCH: update_version-${{ inputs.version }}-${{ github.ref_name }}
15+
16+
jobs:
17+
update-version:
18+
name: Update Version
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
lfs: true
24+
25+
- name: Notice Version
26+
shell: bash
27+
run: |
28+
echo "::notice::Version: \"${{ inputs.version }}\""
29+
30+
- name: Update Version in package.json
31+
id: update-file
32+
shell: bash
33+
run: |
34+
set -eux
35+
36+
VERSION=${{ inputs.version }}
37+
38+
PACKAGE_JSON_PATH="${{ env.PACKAGE_PATH }}/package.json"
39+
cat "${PACKAGE_JSON_PATH}" | perl -pe 's/(\s*"version":\s*")([^"]+)/${1}'${VERSION}'/g' > "${PACKAGE_JSON_PATH}.tmp"
40+
mv "${PACKAGE_JSON_PATH}.tmp" "${PACKAGE_JSON_PATH}"
41+
git add "${PACKAGE_JSON_PATH}"
42+
43+
README_PATH=${{ env.README_PATH }}
44+
cat "${README_PATH}" | perl -pe 's/(#[^`]+)(` #version)/#'${VERSION}'${2}/g' > "${README_PATH}.tmp"
45+
mv "${README_PATH}.tmp" "${README_PATH}"
46+
git add "${README_PATH}"
47+
48+
DIFF_COUNT=$(git diff --staged --name-only | wc -l)
49+
50+
if [ "${DIFF_COUNT}" -le 0 ]
51+
then
52+
echo "::error::There are no changes for \"${VERSION}\""
53+
exit 1
54+
fi
55+
56+
echo "::set-output name=has_update::true"
57+
58+
- name: Commit, Push and PullRequest
59+
if: steps.update-file.outputs.has_update == 'true'
60+
shell: bash
61+
run: |
62+
set -eux
63+
64+
VERSION=${{ inputs.version }}
65+
66+
git checkout -b ${{ env.HEAD_BRANCH }}
67+
68+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
69+
git config --local user.name "github-actions[bot]"
70+
71+
TITLE="Update version to \"${VERSION}\""
72+
73+
git commit -m "${TITLE}"
74+
git push origin ${{ env.HEAD_BRANCH }}
75+
76+
sleep 2
77+
78+
PR_URL=$(gh pr create \
79+
--base "${{ env.BASE_BRANCH }}" \
80+
--head "${{ env.HEAD_BRANCH }}" \
81+
--title "[CI] ${TITLE}" \
82+
--body "" \
83+
)
84+
85+
echo "::notice::${PR_URL} was issued."
86+
87+
env:
88+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)