Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI/CD Pipeline

on:
push:
branches: [develop, release/**]
branches: [main, develop, release/**]
pull_request:
branches: [main, develop]

Expand Down
92 changes: 75 additions & 17 deletions .github/workflows/gitflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Gitflow Auto-Merge
name: Upmerge main to develop (PR)

on:
workflow_run:
Expand All @@ -8,27 +8,85 @@ on:
- completed
branches:
- main
workflow_dispatch: {}

concurrency:
group: upmerge-main-to-develop
cancel-in-progress: true

permissions:
contents: read
contents: write
pull-requests: write

jobs:
merge-back:
name: Gitflow
upmerge:
name: Create/Update upmerge PR
runs-on: ubuntu-latest
# Only run if the release workflow succeeded
if: github.event.workflow_run.conclusion == 'success'


steps:
- name: Run gitflow action
uses: Logerfo/gitflow-action@0.0.5
- name: Checkout
uses: actions/checkout@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
dev: develop
master: main
release: release
release-regex: '^release/(.*)'
label: gitflow
auto-merge: true
require-merge: false
fetch-depth: 0

- name: Configure git
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Create or update upmerge branch + PR
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_BRANCH: feature/upmerge-main-to-develop
BASE_BRANCH: develop
SOURCE_BRANCH: main
run: |
set -euo pipefail

git fetch origin "${SOURCE_BRANCH}:${SOURCE_BRANCH}" "${BASE_BRANCH}:${BASE_BRANCH}" || true
git fetch origin "+refs/heads/${SOURCE_BRANCH}:refs/remotes/origin/${SOURCE_BRANCH}" "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}"

TITLE="chore(gitflow): upmerge ${SOURCE_BRANCH} -> ${BASE_BRANCH}"
BODY=$'Automated upmerge PR.\n\nSource: `main`\nTarget: `develop`\nBranch: `feature/upmerge-main-to-develop`\n\nIf there are merge conflicts:\n1) Checkout `feature/upmerge-main-to-develop` locally\n2) Run `git fetch origin` then `git merge origin/develop`\n3) Resolve conflicts, commit, and push'

EXISTING_PR=$(gh pr list --state open --head "${HEAD_BRANCH}" --base "${BASE_BRANCH}" --json number --jq '.[0].number' || true)

if [ -n "${EXISTING_PR}" ] && [ "${EXISTING_PR}" != "null" ]; then
echo "Found existing PR #${EXISTING_PR} for ${HEAD_BRANCH} -> ${BASE_BRANCH}"
git fetch origin "+refs/heads/${HEAD_BRANCH}:refs/remotes/origin/${HEAD_BRANCH}" || true
git checkout -B "${HEAD_BRANCH}" "origin/${HEAD_BRANCH}"

# Bring in new commits from main
if ! git merge --no-edit "origin/${SOURCE_BRANCH}"; then
echo "::warning::Merge conflict while merging ${SOURCE_BRANCH} into ${HEAD_BRANCH}."
echo "::warning::Leaving branch as-is; please resolve conflicts locally."
git merge --abort || true
fi
else
echo "No existing PR found; creating ${HEAD_BRANCH} from ${SOURCE_BRANCH}"
git checkout -B "${HEAD_BRANCH}" "origin/${SOURCE_BRANCH}"
fi

# Try to pre-resolve conflicts by merging develop into the head branch.
# This makes the eventual PR merge into develop much less likely to conflict.
DRAFT_FLAG=""
if ! git merge --no-edit "origin/${BASE_BRANCH}"; then
echo "::warning::Merge conflicts detected while merging ${BASE_BRANCH} into ${HEAD_BRANCH}."
echo "::warning::Creating/updating PR as draft; resolve conflicts on the branch."
git merge --abort || true
DRAFT_FLAG="--draft"
fi

# Push the branch (force-with-lease to keep it aligned if recreated)
git push --force-with-lease origin "${HEAD_BRANCH}"

if [ -n "${EXISTING_PR}" ] && [ "${EXISTING_PR}" != "null" ]; then
gh pr edit "${EXISTING_PR}" --title "${TITLE}" --body "${BODY}" >/dev/null
echo "Updated PR #${EXISTING_PR}"
else
PR_URL=$(gh pr create --head "${HEAD_BRANCH}" --base "${BASE_BRANCH}" --title "${TITLE}" --body "${BODY}" ${DRAFT_FLAG} --json url --jq .url)
echo "Created PR: ${PR_URL}"
fi
4 changes: 3 additions & 1 deletion .github/workflows/release-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
uses: winccoa-tools-pack/.github/.github/workflows/versioning-tags-changelog-reusable.yml@main
with:
mode: release
target_branch: ${{ inputs.target_branch }}
create_tag: false
push_tag: false
secrets: inherit
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
needs: [precheck]
with:
mode: release
target_branch: ${{ inputs.target_branch }}
create_tag: true
push_tag: true
force_push_tag: false
Expand Down Expand Up @@ -126,7 +128,7 @@ jobs:
with:
tag_name: ${{ needs.tag.outputs.tag }}
name: ${{ format('Release {0}', needs.tag.outputs.tag) }}
target_commitish: ${{ github.sha }}
target_commitish: ${{ inputs.target_branch }}
body: |
${{ needs.versioning.outputs.changelog }}

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
workflow_run:
workflows:
- "CI/CD Pipeline"
- "Integration Tests - WinCC OA"
types:
- completed
branches:
Expand All @@ -25,7 +24,10 @@ jobs:
# Only run if the triggering workflow succeeded or manual dispatch
if: |
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success'
(
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
)
uses: ./.github/workflows/release-reusable.yml
with:
target_branch: main
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wincc-oa-tools-pack",
"displayName": "WinCC OA Tools Pack",
"publisher": "mPokornyETM",
"version": "0.0.6",
"version": "0.0.7",
"engines": {
"vscode": "^1.60.0"
},
Expand Down
Loading