diff --git a/.github/workflows/gitflow-validation.yml b/.github/workflows/gitflow-validation.yml index 1245050..06bc418 100644 --- a/.github/workflows/gitflow-validation.yml +++ b/.github/workflows/gitflow-validation.yml @@ -35,6 +35,8 @@ jobs: const baseRef = pr.base.ref; // e.g. develop const rules = [ + // main to develop means merging main back into develop (git flow) + { type: 'main', prefixes: ['main'], expectedBase: 'develop' }, { type: 'feature', prefixes: ['feature/'], expectedBase: 'develop' }, { type: 'bugfix', prefixes: ['bugfix/'], expectedBase: 'develop' }, { type: 'chore', prefixes: ['chore/'], expectedBase: 'develop', botOnly: true }, diff --git a/.github/workflows/gitflow.yml b/.github/workflows/gitflow.yml index 99fed56..c620905 100644 --- a/.github/workflows/gitflow.yml +++ b/.github/workflows/gitflow.yml @@ -1,13 +1,8 @@ name: Upmerge main to develop (PR) on: - workflow_run: - workflows: - - "Release" - types: - - completed - branches: - - main + push: + branches: [main] workflow_dispatch: {} concurrency: @@ -46,13 +41,18 @@ jobs: run: | set -euo pipefail - git fetch origin "${SOURCE_BRANCH}:${SOURCE_BRANCH}" "${BASE_BRANCH}:${BASE_BRANCH}" || true + REPO="${GITHUB_REPOSITORY}" + OWNER="${REPO%%/*}" + + # Fetch remote refs without writing into checked-out local branches 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) + # Find an existing open PR for HEAD_BRANCH -> BASE_BRANCH. + # Use GitHub API to avoid relying on gh CLI JSON flags that vary by version. + EXISTING_PR=$(gh api "repos/${REPO}/pulls?state=open&head=${OWNER}:${HEAD_BRANCH}&base=${BASE_BRANCH}" --jq '.[0].number' 2>/dev/null || true) if [ -n "${EXISTING_PR}" ] && [ "${EXISTING_PR}" != "null" ]; then echo "Found existing PR #${EXISTING_PR} for ${HEAD_BRANCH} -> ${BASE_BRANCH}" @@ -87,6 +87,12 @@ jobs: 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}" + CREATE_OUT=$(gh pr create --head "${HEAD_BRANCH}" --base "${BASE_BRANCH}" --title "${TITLE}" --body "${BODY}" ${DRAFT_FLAG}) + echo "$CREATE_OUT" + PR_URL=$(echo "$CREATE_OUT" | grep -Eo 'https://github\.com/[^ ]+/pull/[0-9]+' | head -n 1 || true) + if [ -n "${PR_URL}" ]; then + echo "Created PR: ${PR_URL}" + else + echo "::warning::PR created but URL could not be parsed from output." + fi fi diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..11bddf3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] diff --git a/package-lock.json b/package-lock.json index a5b7d80..9333333 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wincc-oa-tools-pack", - "version": "0.0.7", + "version": "0.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wincc-oa-tools-pack", - "version": "0.0.7", + "version": "0.0.8", "license": "MIT", "engines": { "vscode": "^1.60.0" diff --git a/package.json b/package.json index 71071f4..c833df4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "wincc-oa-tools-pack", "displayName": "WinCC OA Tools Pack", "publisher": "mPokornyETM", - "version": "0.0.7", + "version": "0.0.8", "engines": { "vscode": "^1.60.0" },