Skip to content

Commit 644b886

Browse files
authored
Merge pull request #18 from tsgcpp/feature/ci_update_version
feat: Add CI to update this package version
2 parents f662dfe + a656675 commit 644b886

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

.github/workflows/pull-localization.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ jobs:
7171
if: steps.commit.outputs.has_diff == 'true'
7272
shell: bash
7373
run: |
74+
set -eux
75+
7476
REMOTE_SHA=$(git ls-remote --heads origin ${{ env.HEAD_BRANCH }})
7577
if [ -n "${REMOTE_SHA}" ]
7678
then
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 }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Extension package for Unity Localization
77
- Window -> Package Manager
88
- Add package from git URL...
99
- Add the package URL
10-
- `https://github.com/tsgcpp/UnityLocalizationExtension.git?path=Assets/Plugins/LocalizationExtension#<tag>`
10+
- e.g. `https://github.com/tsgcpp/UnityLocalizationExtension.git?path=Assets/Plugins/LocalizationExtension#0.1.0` #version
1111

1212

1313
## Feature

0 commit comments

Comments
 (0)