Repository navigation
152 lines (129 loc) · 5.19 KB
/
Copy pathsync-main-to-develop.yml
File metadata and controls
152 lines (129 loc) · 5.19 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Sync main to develop after release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version to sync, e.g. 1.2.3. Defaults to packages/vchart version on main.'
required: false
type: string
# Release PR heads use [skip ci], which suppresses pull_request workflows.
# pull_request_target still runs on merge; this job only checks out main.
pull_request_target:
types:
- closed
branches:
- main
jobs:
sync_main_to_develop:
if: >-
github.event_name == 'workflow_dispatch' ||
(
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/') &&
github.event.pull_request.head.repo.full_name == github.repository
)
runs-on: macos-latest
permissions:
contents: write
pull-requests: write
strategy:
matrix:
node-version: [20.x]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
persist-credentials: false
- name: Configure Git identity
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Configure git remote for workflow-created branches
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: './common/config/rush/pnpm-lock.yaml'
- name: Install Python distutils (macOS)
if: runner.os == 'macOS'
run: |
python3 -m pip install setuptools --break-system-packages
- name: Install Python distutils (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y python3-distutils
python3 -m pip install setuptools --break-system-packages
- name: Install native deps for node-canvas (macOS)
if: runner.os == 'macOS'
run: |
brew update
brew install pkg-config cairo pango libpng jpeg giflib librsvg
- name: Install native deps for node-canvas (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config
- name: Install latest pnpm
run: npm install -g pnpm@10.7.0
- name: Install rush
run: node common/scripts/install-run-rush.js install --bypass-policy
- name: Read vchart version from package.json
id: package_version
uses: xile611/read-package-version-action@main
with:
path: packages/vchart
- name: Compute sync branch name and check existence
id: sync_branch
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
PACKAGE_VERSION: ${{ steps.package_version.outputs.current_version }}
run: |
set -euo pipefail
VERSION="${INPUT_VERSION:-${PACKAGE_VERSION}}"
if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid sync version: ${VERSION}"
exit 1
fi
BRANCH="sync/main-${VERSION}"
echo "sync_branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
git fetch origin "${BRANCH}":refs/remotes/origin/tmp-sync-branch 2>/dev/null || true
if git ls-remote --exit-code --heads origin "${BRANCH}" > /dev/null 2>&1; then
echo "Branch ${BRANCH} already exists on origin, skip creating new sync branch."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create and push sync/main-X.Y.Z branch
if: steps.sync_branch.outputs.exists == 'false'
run: |
set -euo pipefail
BRANCH="${{ steps.sync_branch.outputs.sync_branch }}"
git checkout main
git pull --ff-only origin main
git checkout -b "${BRANCH}"
git push --no-verify origin "${BRANCH}"
- name: Create Pull Request to develop
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
BRANCH="${{ steps.sync_branch.outputs.sync_branch }}"
echo "Source branch: $BRANCH"
# Check if PR already exists
if gh pr list --base develop --head "$BRANCH" --state open --json number --limit 1 | grep -q '"number"'; then
echo "PR from $BRANCH to develop already exists, skip creating."
exit 0
fi
TITLE="[Auto Sync] Sync the code from branch main to branch develop after release ${{ steps.sync_branch.outputs.version }}"
BODY="Sync the code from branch main to branch develop after release ${{ steps.sync_branch.outputs.version }}"
gh pr create --base develop --head "$BRANCH" --title "$TITLE" --body "$BODY" --reviewer xuefei1313