Delete squash_version_to_main.yml
This commit is contained in:
109
.github/workflows/squash_version_to_main.yml
vendored
109
.github/workflows/squash_version_to_main.yml
vendored
@@ -1,109 +0,0 @@
|
|||||||
name: Squash merge version branch into main
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
squash-merge-version:
|
|
||||||
name: Conditional squash merge version/* into main
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Determine branch and version
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
BRANCH="${GITHUB_REF_NAME}"
|
|
||||||
|
|
||||||
echo "Running on branch: $BRANCH"
|
|
||||||
|
|
||||||
if [[ ! "$BRANCH" =~ ^version\/[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9]+)?$ ]]; then
|
|
||||||
echo "This workflow must be run on a branch named version/X.Y.Z or version/X.Y.Z-tag"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
VERSION="${BRANCH#version/}"
|
|
||||||
|
|
||||||
echo "Detected version: $VERSION"
|
|
||||||
|
|
||||||
# prerelease detection
|
|
||||||
if [[ "$VERSION" =~ -(alpha|beta|rc|pre|preview|dev|test) ]]; then
|
|
||||||
echo "Version is prerelease: $VERSION"
|
|
||||||
IS_PRERELEASE="true"
|
|
||||||
else
|
|
||||||
echo "Version is stable: $VERSION"
|
|
||||||
IS_PRERELEASE="false"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "is_prerelease=$IS_PRERELEASE" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Check out repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Create or reuse PR from version branch to main
|
|
||||||
id: cpr
|
|
||||||
uses: peter-evans/create-pull-request@v6
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
head: ${{ steps.meta.outputs.branch }}
|
|
||||||
base: main
|
|
||||||
title: "Merge version ${{ steps.meta.outputs.version }} into main"
|
|
||||||
body: |
|
|
||||||
Automated PR to merge version **${{ steps.meta.outputs.version }}** into **main**.
|
|
||||||
|
|
||||||
- Branch: `${{ steps.meta.outputs.branch }}`
|
|
||||||
- Version: `${{ steps.meta.outputs.version }}`
|
|
||||||
- Prerelease: `${{ steps.meta.outputs.is_prerelease }}`
|
|
||||||
|
|
||||||
This PR was generated by the squash merge workflow.
|
|
||||||
labels: |
|
|
||||||
release
|
|
||||||
version-update
|
|
||||||
|
|
||||||
###########################################################
|
|
||||||
# Only squash merge IF the branch version is NOT prerelease
|
|
||||||
###########################################################
|
|
||||||
- name: Squash merge PR into main (stable only)
|
|
||||||
if: steps.meta.outputs.is_prerelease == 'false'
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
VERSION: ${{ steps.meta.outputs.version }}
|
|
||||||
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
|
|
||||||
run: |
|
|
||||||
if [ -z "$PR_NUMBER" ]; then
|
|
||||||
echo "No pull request number returned. Cannot squash merge."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Performing squash merge PR #${PR_NUMBER} into main"
|
|
||||||
|
|
||||||
curl -sS -X PUT \
|
|
||||||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
|
|
||||||
-H "Accept: application/vnd.github+json" \
|
|
||||||
"https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/merge" \
|
|
||||||
-d "$(jq -n \
|
|
||||||
--arg method "squash" \
|
|
||||||
--arg title "Squash merge version ${VERSION} into main" \
|
|
||||||
'{merge_method: $method, commit_title: $title}')"
|
|
||||||
|
|
||||||
###########################################################
|
|
||||||
# If prerelease, annotate and skip squash
|
|
||||||
###########################################################
|
|
||||||
- name: Skip squash (prerelease detected)
|
|
||||||
if: steps.meta.outputs.is_prerelease == 'true'
|
|
||||||
run: |
|
|
||||||
echo "Prerelease version detected. PR created but squash merge intentionally skipped."
|
|
||||||
|
|
||||||
- name: Optional delete version branch after merge
|
|
||||||
if: steps.meta.outputs.is_prerelease == 'false'
|
|
||||||
env:
|
|
||||||
BRANCH: ${{ steps.meta.outputs.branch }}
|
|
||||||
run: |
|
|
||||||
echo "Deleting branch ${BRANCH} after squash merge"
|
|
||||||
git push origin --delete "${BRANCH}" || echo "Branch already deleted or cannot delete"
|
|
||||||
Reference in New Issue
Block a user