Skip to content

CI :: OSL :: Sync Main #20

CI :: OSL :: Sync Main

CI :: OSL :: Sync Main #20

Workflow file for this run

name: "CI :: OSL :: Sync Main"
on:
workflow_dispatch:
schedule:
- cron: "0 2 * * 1"
env:
UPSTREAM_URL: ${{ vars.UPSTREAM_URL }}
GITHUB_TOKEN: ${{ secrets.KIE1_TOKEN }}
PNPM_FILTER: ${{ vars.SYNC_PNPM_FILTER }}
jobs:
sync_main_apache:
if: ${{ vars.ENABLE_OSL_SYNC_MAIN == 'yes' }}
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 & CLI
run: |
git config --global user.name "${{ secrets.KIE1_USER_NAME }}"
git config --global user.email "${{ secrets.KIE1_EMAIL }}"
git config --global merge.ours.driver true
- 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"
- name: Merge upstream/main (prefer theirs)
id: merge
run: git merge upstream/main -X theirs --no-edit || true
- name: Reset lock & graph to upstream
run: git checkout upstream/main -- pnpm-lock.yaml repo/graph.*
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Bootstrap & 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: |
pnpm bootstrap --no-frozen-lockfile
pnpm ${{ env.PNPM_FILTER }} --workspace-concurrency=1 build:prod
- name: Capture Changes
id: capture_changes
run: |
git status --porcelain > /tmp/sync_changes.txt
if [ -s /tmp/sync_changes.txt ]; then
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
- name: Commit & Push (if there are changes)
if: env.HAS_CHANGES == 'true'
run: |
git add .
git commit -m "🤖 Sync with upstream/main (auto-theirs)"
git push -u origin "${{ env.SYNC_BRANCH }}"
- name: Push Sync Branch (no changes)
if: env.HAS_CHANGES == 'false'
run: git push -u origin "${{ env.SYNC_BRANCH }}"
- name: Create Pull Request
env:
RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
run: |
# build a trimmed-change list for the PR body
SYNC_CHANGES=$(head -c 5000 /tmp/sync_changes.txt; echo "…")
ESCAPED=$(printf '%s' "$SYNC_CHANGES" \
| sed -e ':a' -e 'N' -e '$!ba' -e 's|\n|\\n|g' -e 's|/|\\/|g')
sed \
-e "s|\\\$RUN_URL|${RUN_URL}|g" \
-e "s|\\\$TRUNCATED_SYNC_CHANGES|${ESCAPED}|g" \
.github/supporting-files/ci/templates/osl_sync_pr_template.md \
> pr_body.md
REVIEWERS_ARG=""
if [ -n "${{ vars.SYNC_REVIEWERS }}" ]; then
REVIEWERS_ARG="--reviewer ${{ vars.SYNC_REVIEWERS }}"
fi
gh pr create \
--title "[$(date +'%Y-%m-%d:%H%M%S')] 🤖 Sync main with upstream" \
--body-file pr_body.md \
--repo kubesmarts/kie-tools \
--base main $REVIEWERS_ARG