-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (101 loc) · 3.86 KB
/
check_version.yml
File metadata and controls
117 lines (101 loc) · 3.86 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Check new version
on:
workflow_call:
inputs:
repository:
description: repository url
required: true
type: string
library:
description: library name
required: true
type: string
pr_body:
description: custom pull request body (optional)
required: false
type: string
jobs:
check_version:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Normalize repository input
shell: bash
run: |
repo_input='${{ inputs.repository }}'
if [[ "$repo_input" =~ ^https?:// ]]; then
repo_url="$repo_input"
repo_url="${repo_url%/}"
else
repo_url="https://github.com/$repo_input"
fi
echo "repository url: $repo_url"
echo "REPOSITORY_URL=$repo_url" >> $GITHUB_ENV
- name: Checkout latest code
shell: bash
run: |
git clone --no-single-branch "$REPOSITORY_URL" latest_code || {
echo "Failed to clone repository: $REPOSITORY_URL"
exit 1
}
git -C latest_code fetch --tags --force
- name: Get latest version
id: version
run: |
cd ./latest_code
latest_tag=$(git tag --sort=-v:refname | grep -v "-" | grep -v "_" | head -n 1)
echo "latest tag: $latest_tag"
echo "NEW_VERSION=$latest_tag" >> $GITHUB_ENV
rm -rf ../latest_code
- name: update to new version
uses: jannekem/run-python-script-action@v1
with:
script: |
import re
def parse_version(ver):
if '-' in ver or ver == '':
return 0
return int(re.sub(r'[^0-9]+', r'', ver))
file_path = './Sources/BuildScripts/XCFrameworkBuild/main.swift'
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
oldVersion = re.search(r'(case .${{ inputs.library }}[^\"]+?)"(.+?)"', content).group(2)
print("old version:", oldVersion)
set_env('OLD_VERSION', oldVersion)
newVersion = '${{ env.NEW_VERSION }}'
print("new version:", newVersion)
if parse_version(newVersion) > parse_version(oldVersion):
content = re.sub(r'(case .${{ inputs.library }}[^\"]+?)"(.+?)"', r'\1"${{ env.NEW_VERSION }}"', content, count=1)
set_env('FOUND_NEW_VERSION', '1')
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
- name: Prepare PR body
uses: jannekem/run-python-script-action@v1
with:
script: |
import os
pr_input = '''${{ inputs.pr_body }}'''
repo_url = '${{ env.REPOSITORY_URL }}'
new = '${{ env.NEW_VERSION }}'
old = '${{ env.OLD_VERSION }}'
if pr_input and pr_input.strip():
# Replace placeholders with actual values
pr_body = pr_input.replace('{REPOSITORY_URL}', repo_url)
pr_body = pr_body.replace('{NEW_VERSION}', new)
pr_body = pr_body.replace('{OLD_VERSION}', old)
else:
pr_body = f"{repo_url}/releases/tag/{new}\n\n{repo_url}/compare/{old}...{new}"
with open('/tmp/PR_BODY.txt', 'w', encoding='utf-8') as f:
f.write(pr_body)
- name: Create Pull Request
if: env.FOUND_NEW_VERSION
uses: peter-evans/create-pull-request@v6
with:
add-paths: |
./Sources/BuildScripts/XCFrameworkBuild/main.swift
title: "bump version to ${{ env.NEW_VERSION }}"
body-path: /tmp/PR_BODY.txt
commit-message: "chore: bump version to ${{ env.NEW_VERSION }}"