Skip to content

Commit

Permalink
attempt merging
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Mar 22, 2024
1 parent c1e1d58 commit 9fa2b05
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions .github/workflows/create-merge-release-into-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: create-merge-release-into-dev-pr
on:
workflow_dispatch:

env:
BASE_BRANCH: test-dev

permissions: {}
jobs:
setup:
Expand All @@ -25,24 +28,57 @@ jobs:
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
create-pr:
merge-or-create-pr:
permissions:
pull-requests: write # for git push
contents: write # for git push
pull-requests: write # for creating pull request

runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create pull request
run: >
gh pr create
--base "$BASE_BRANCH"
--head "$RELEASE_BRANCH"
--title "Merge $RELEASE_BRANCH into $BASE_BRANCH"
--body 'Created by GitHub action'
with:
ref: ${{ env.BASE_BRANCH }} # TODO: DELETE ME
- name: Fetch dev and release branches
run: |
# Fetching the dev and release branches without fetching their complete history
# First fetch branches themselves excluding commits reachable by the other branch
git fetch --shallow-exclude "$BASE_BRANCH" origin "$RELEASE_BRANCH"
git fetch --shallow-exclude "$RELEASE_BRANCH" origin "$BASE_BRANCH"
# Resolve bug in git https://stackoverflow.com/a/63879454/96823
git repack -d
# Get one commit more to connect the history of dev and release branches
git fetch --deepen 1 origin "$BASE_BRANCH" "$RELEASE_BRANCH"
# Create branch without checkout just to have shorter automatic commit message
git branch "$RELEASE_BRANCH" origin/"$RELEASE_BRANCH"
- name: Required git config
run: |
# Required config
git config user.name "OpenProject Actions CI"
git config user.email "[email protected]"
- name: Try merging or create a PR
run: |
if git diff --exit-code --quiet ..."$RELEASE_BRANCH"; then
echo "Nothing to merge from $RELEASE_BRANCH into $BASE_BRANCH"
else
if git merge --no-edit --no-ff "$RELEASE_BRANCH" && git pull --rebase && git push origin "$BASE_BRANCH"; then
echo "Successfully merged $RELEASE_BRANCH into $BASE_BRANCH and pushed"
else
gh pr create \
--base "$BASE_BRANCH" \
--head "$RELEASE_BRANCH" \
--title "Merge $RELEASE_BRANCH into $BASE_BRANCH" \
--body 'Created by GitHub action' \
--label create-merge-release-into-dev-pr
echo "Created a PR to merge $RELEASE_BRANCH into $BASE_BRANCH"
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: dev
RELEASE_BRANCH: ${{ needs.setup.outputs.latest_release_branch }}

0 comments on commit 9fa2b05

Please sign in to comment.