forked from froala/wysiwyg-editor-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (110 loc) · 4.15 KB
/
sync-version.yml
File metadata and controls
136 lines (110 loc) · 4.15 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Sync Version – Python SDK
on:
repository_dispatch:
types: [version_update]
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
# --------------------------------------------
# Checkout repository
# --------------------------------------------
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
# --------------------------------------------
# Load & validate version
# --------------------------------------------
- name: Load & validate version
run: |
VERSION="${{ github.event.client_payload.version }}"
VERSION="${VERSION//,/\.}"
if [ -z "$VERSION" ]; then
echo "Version missing in dispatch payload"
exit 1
fi
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Dispatching version $VERSION"
# --------------------------------------------
# Compare current version
# --------------------------------------------
- name: Compare current version
run: |
CURRENT_VERSION=$(jq -r '.version' bower.json)
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" = "null" ]; then
echo "Unable to determine current version from bower.json"
exit 1
fi
echo "Current version : $CURRENT_VERSION"
echo "Incoming version: $VERSION"
if [ "$CURRENT_VERSION" = "$VERSION" ]; then
echo "Versions are identical. Denying PR creation."
exit 0
fi
echo "Version change detected. Proceeding."
# --------------------------------------------
# Prepare release branch
# --------------------------------------------
- name: Prepare release branch
run: |
BRANCH="release-v${VERSION}"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
git fetch origin
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
git checkout "$BRANCH"
git pull origin "$BRANCH"
else
git checkout -b "$BRANCH"
fi
# --------------------------------------------
# Update bower.json version + dependency
# --------------------------------------------
- name: Update bower.json
run: |
# Update SDK version
jq ".version = \"$VERSION\"" bower.json > tmp.json
mv tmp.json bower.json
# Update froala-wysiwyg-editor dependency
jq ".dependencies[\"froala-wysiwyg-editor\"] = \"^$VERSION\"" bower.json > tmp.json
mv tmp.json bower.json
# --------------------------------------------
# Commit & push
# --------------------------------------------
- name: Commit & push
run: |
git config user.name "froala-travis-bot"
git config user.email "froala_git_travis_bot@idera.com"
git add bower.json
git commit -m "chore: release Python SDK v${VERSION}" || echo "Nothing to commit"
git push origin "$BRANCH"
# --------------------------------------------
# Create Pull Request
# --------------------------------------------
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.PAT }}
RELEASE_NOTES: ${{ github.event.client_payload.release_notes }}
run: |
git fetch origin master
if git diff --quiet origin/master..."$BRANCH"; then
echo "No commits between $BRANCH and master. Skipping PR creation."
exit 0
fi
PR_BODY=$(printf \
"release: yes\n\n## Release Notes (from primary repo)\n\n%s\n" \
"$RELEASE_NOTES")
gh pr create \
--base master \
--head "$BRANCH" \
--title "Release v${VERSION}" \
--body "$PR_BODY" \
|| echo "Pull request already exists"