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