Skip to content

Commit c5422ff

Browse files
feat: add auto-pilot-auto-sync action
Signed-off-by: YuxuanLiuTier4Desktop <619684051@qq.com>
1 parent cb387e7 commit c5422ff

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: sync-version-to-pilot-auto
2+
3+
on:
4+
push:
5+
branches:
6+
- {{SOURCE_BRANCH}} # Target branch in universe repo
7+
8+
jobs:
9+
sync-version:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Generate token
13+
id: generate-token
14+
uses: actions/create-github-app-token@v1
15+
with:
16+
app_id: ${{ secrets.INTERNAL_APP_ID }}
17+
private_key: ${{ secrets.INTERNAL_PRIVATE_KEY }}
18+
owner: ${{ github.repository_owner }}
19+
20+
- name: Checkout universe
21+
uses: actions/checkout@v4
22+
with:
23+
path: universe-repo # Checkout into a subfolder to keep things clean
24+
25+
- name: Get current commit SHA and author
26+
id: vars
27+
run: |
28+
cd universe-repo
29+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
30+
echo "author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT
31+
32+
- name: Checkout {{TARGET_REPOSITORY}}
33+
uses: actions/checkout@v4
34+
with:
35+
repository: {{TARGET_REPOSITORY}}
36+
token: ${{ steps.generate-token.outputs.token }}
37+
path: pilot-auto-repo
38+
ref: {{TARGET_BRANCH}} # The target branch in {{TARGET_REPOSITORY}}
39+
40+
- name: Update autoware.repos
41+
env:
42+
REPO_KEY: autoware/universe
43+
NEW_SHA: ${{ steps.vars.outputs.sha }}
44+
run: |
45+
cd pilot-auto-repo
46+
# Use the verified sed command
47+
sed -i "/${REPO_KEY//\//\\\/}:/,/version:/ s/\(version:[[:space:]]*\).*/\1$NEW_SHA/" autoware.repos
48+
49+
- name: Create Pull Request in {{TARGET_REPOSITORY}}
50+
uses: peter-evans/create-pull-request@v5
51+
with:
52+
path: pilot-auto-repo
53+
token: ${{ steps.generate-token.outputs.token }}
54+
branch: sync-universe-${{ steps.vars.outputs.sha }}
55+
title: "chore: update autoware/universe to ${{ steps.vars.outputs.sha }}"
56+
body: |
57+
Auto-generated PR to sync autoware/universe version from merged changes in universe repository.
58+
59+
cc: @${{ github.actor }} (commit author: ${{ steps.vars.outputs.author }})
60+
base: {{TARGET_BRANCH}}
61+
commit-message: "chore: update autoware/universe version"
62+
delete-branch: true
63+
reviewers: ${{ github.actor }}

.github/create-sub-beta-branch.yaml renamed to .github/workflows/create-sub-beta-branch.yaml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create Sub-Beta Branch
1+
name: create-sub-beta-branch
22

33
on:
44
workflow_dispatch:
@@ -19,6 +19,14 @@ on:
1919
description: "Product identifier for labeling (e.g., pilotone)"
2020
required: true
2121
type: string
22+
target_repository:
23+
description: "Target repository for auto-sync (e.g., tier4/pilot-auto.x2)"
24+
required: false
25+
type: string
26+
target_branch:
27+
description: "Target branch in the target repository (e.g., beta/v4.2/pilotone)"
28+
required: false
29+
type: string
2230

2331
jobs:
2432
create-sub-beta-branch:
@@ -124,13 +132,50 @@ jobs:
124132
.github/workflows/auto-add-label.yaml
125133
echo "Copied auto-add-label.yaml to child branch"
126134
135+
- name: Render auto-sync-pilot-auto workflow for child branch
136+
run: |
137+
mkdir -p .github/workflows
138+
TEMPLATE_FILE="/tmp/workflow-templates/auto-sync-pilot-auto.yaml.template"
139+
OUTPUT_FILE=".github/workflows/auto-sync-pilot-auto.yaml"
140+
141+
if [ -f "$TEMPLATE_FILE" ]; then
142+
echo "Rendering auto-sync-pilot-auto.yaml template for child branch"
143+
144+
# Read template file
145+
TEMPLATE_CONTENT=$(cat "$TEMPLATE_FILE")
146+
147+
# Replace template variables
148+
# Using sed with different delimiters to avoid issues with slashes in branch names
149+
RENDERED_CONTENT=$(echo "$TEMPLATE_CONTENT" | \
150+
sed "s|{{SOURCE_BRANCH}}|${{ inputs.branch_name }}|g" | \
151+
sed "s|{{TARGET_REPOSITORY}}|${{ inputs.target_repository }}|g" | \
152+
sed "s|{{TARGET_BRANCH}}|${{ inputs.target_branch }}|g")
153+
154+
# Write rendered content to output file
155+
echo "$RENDERED_CONTENT" > "$OUTPUT_FILE"
156+
157+
echo "Created auto-sync-pilot-auto.yaml for child branch"
158+
echo "Source branch: ${{ inputs.branch_name }}"
159+
echo "Target repository: ${{ inputs.target_repository }}"
160+
echo "Target branch: ${{ inputs.target_branch }}"
161+
else
162+
echo "Warning: auto-sync-pilot-auto.yaml.template not found, skipping"
163+
fi
164+
127165
- name: Commit and push child branch
128166
run: |
129167
git add .github/branch-meta.yaml .github/workflows/auto-add-label.yaml
130-
git commit -m "chore: initialize child branch with meta file and auto-label workflow
168+
169+
# Add the auto-sync workflow if it exists
170+
if [ -f ".github/workflows/auto-sync-pilot-auto.yaml" ]; then
171+
git add .github/workflows/auto-sync-pilot-auto.yaml
172+
fi
173+
174+
git commit -m "chore: initialize child branch with meta file and workflows
131175
132176
- Add .github/branch-meta.yaml with branch metadata
133177
- Add .github/workflows/auto-add-label.yaml for automatic PR labeling
178+
- Add .github/workflows/auto-sync-pilot-auto.yaml for syncing to ${{ inputs.target_repository }}
134179
- Base branch: ${{ inputs.base_branch }}
135180
- Product: ${{ inputs.product_name }}"
136181
git push origin "${{ inputs.branch_name }}"
@@ -252,3 +297,4 @@ jobs:
252297
echo "1. Review and merge the PR to ${{ inputs.base_branch }}"
253298
echo "2. The child branch ${{ inputs.branch_name }} is ready for use"
254299
echo "3. PRs merged to ${{ inputs.base_branch }} will be auto-cherry-picked to ${{ inputs.branch_name }}"
300+
echo "4. Changes to ${{ inputs.branch_name }} will be auto-synced to ${{ inputs.target_repository }} branch ${{ inputs.target_branch }}"

0 commit comments

Comments
 (0)