forked from apache/incubator-kie-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (121 loc) · 4.99 KB
/
osl_sync_main.yml
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
name: "CI :: OSL :: Sync Main"
on:
workflow_dispatch: # Allows you to run the workflow manually from the Actions tab
schedule:
- cron: "0 2 * * 1" # Runs every Monday at 2 AM UTC (adjust as needed)
env:
UPSTREAM_URL: ${{ vars.UPSTREAM_URL }}
GITHUB_TOKEN: ${{ secrets.KIE1_TOKEN }}
PNPM_FILTER: ${{ vars.SYNC_PNPM_FILTER }}
jobs:
sync_main_apache:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.KIE1_TOKEN }}
ref: main
- name: Add Upstream Remote
run: |
git remote add upstream $UPSTREAM_URL
git fetch --unshallow upstream main
- name: Setup Git Environment
run: |
git config --global user.name "${{ secrets.KIE1_USER_NAME }}"
git config --global user.email "${{ secrets.KIE1_EMAIL }}"
- name: Create Sync Branch
run: |
SYNC_BRANCH="main-sync-$(date +'%Y%m%d-%H%M%S')"
echo "SYNC_BRANCH=$SYNC_BRANCH" >> $GITHUB_ENV
git checkout -b $SYNC_BRANCH
git merge-base HEAD upstream/main
git show $(git merge-base HEAD upstream/main)
- name: Attempt Merge with Upstream
id: merge
run: |
git merge upstream/main --no-edit || echo "CONFLICT" > /tmp/merge_result.txt
- name: Check for Merge Conflicts
id: check_conflicts
run: |
if [ -f /tmp/merge_result.txt ]; then
echo "MERGE_RESULT=CONFLICT" >> $GITHUB_ENV
else
echo "MERGE_RESULT=SUCCESS" >> $GITHUB_ENV
fi
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Handle Conflicts
if: env.MERGE_RESULT == 'CONFLICT'
run: |
echo "Conflicts detected. Resolving specific files..."
git checkout upstream/main -- pnpm-lock.yaml repo/graph.*
pnpm bootstrap --no-frozen-lockfile
# - name: Run Bootstrap (No Conflicts)
# if: env.MERGE_RESULT == 'SUCCESS'
# run: |
# pnpm bootstrap --no-frozen-lockfile
#
# - name: "Run Build"
# shell: bash
# env:
# KIE_TOOLS_BUILD__runTests: "false"
# KIE_TOOLS_BUILD__runEndToEndTests: "false"
# KIE_TOOLS_BUILD__buildContainerImages: "true"
# KIE_TOOLS_BUILD__ignoreTestFailures: "true"
# KIE_TOOLS_BUILD__ignoreEndToEndTestFailures: "true"
# NODE_OPTIONS: "--max_old_space_size=4096"
# run: >-
# eval "pnpm ${{ env.PNPM_FILTER }} --workspace-concurrency=1 build:prod"
- name: Capture Uncommitted Changes
id: capture_changes
run: |
SYNC_CHANGES=$(git status --porcelain)
echo "$SYNC_CHANGES" > /tmp/sync_changes.txt
if [ -n "$SYNC_CHANGES" ]; then
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
- name: Commit and Push Changes to Sync Branch
if: env.MERGE_RESULT == 'CONFLICT' || env.HAS_CHANGES == 'true'
run: |
echo "Changes detected. Committing and pushing..."
git add .
git commit -m "Sync with upstream/main and resolved conflicts"
git push -u origin "${{ env.SYNC_BRANCH }}"
- name: Push Changes (No Conflict or Changes)
if: env.MERGE_RESULT == 'SUCCESS' && env.HAS_CHANGES == 'false'
run: |
echo "No conflicts or changes detected. Pushing merged branch."
git push -u origin "${{ env.SYNC_BRANCH }}"
echo "No conflicts or changes detected." > /tmp/sync_changes.txt
- name: Create Pull Request
env:
RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
run: |
set -x
SYNC_CHANGES=$(cat /tmp/sync_changes.txt)
# Truncate SYNC_CHANGES to 5000
MAX_CHARS=5000
if [ ${#SYNC_CHANGES} -gt $MAX_CHARS ]; then
TRUNCATED_SYNC_CHANGES="${SYNC_CHANGES:0:$MAX_CHARS}..."
else
TRUNCATED_SYNC_CHANGES="$SYNC_CHANGES"
fi
ESCAPED_CHANGES=$(echo "$TRUNCATED_SYNC_CHANGES" | sed -e ':a' -e 'N' -e '$!ba' -e 's|\n|\\n|g' -e 's|/|\\/|g')
# Use double quotes for variable substitution in sed
sed -e "s|\\\$RUN_URL|${RUN_URL}|g" -e "s|\\\$TRUNCATED_SYNC_CHANGES|${ESCAPED_CHANGES}|g" .github/supporting-files/ci/templates/osl_sync_pr_template.md > temp.md
prTitle="[$(date +'%Y-%m-%d:%H%M%S')] - :robot: Automated PR: Sync main with upstream"
reviewersOption=""
if [[ -n "${{ vars.SYNC_REVIEWERS }}" ]]; then
reviewersOption="--reviewer ${{ vars.SYNC_REVIEWERS }}"
fi
gh pr create --title "${prTitle}" \
--body-file temp.md \
--repo fantonangeli/kie-tools \
--base main $reviewersOption