PR: troubleshooting the PR not being created

This commit is contained in:
XargonWan 2024-11-06 10:10:26 +09:00
parent 3c6b0c498e
commit ac5344cca5

View file

@ -45,44 +45,41 @@ jobs:
- name: Sync from Upstream Repository - name: Sync from Upstream Repository
env: env:
BRANCH_NAME: "sync-${{ github.run_id }}" # Temporary branch name for the PR BRANCH_NAME: "feat/update-from-upstream"
run: | run: |
echo "Syncing from upstream repository ${{ env.UPSTREAM_REPO }} on branch ${{ env.TARGET_BRANCH }}" echo "Syncing from upstream repository ${{ env.UPSTREAM_REPO }} on branch ${{ env.TARGET_BRANCH }}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
# Fetch and delete the branch if it exists locally
git fetch origin git fetch origin
if git rev-parse --verify "$BRANCH_NAME" >/dev/null 2>&1; then
echo "Branch $BRANCH_NAME exists locally. Deleting it."
git branch -D "$BRANCH_NAME"
fi
# Check if the branch exists on the remote and delete it if it does # Switches or creates update branch
if git ls-remote --heads origin "$BRANCH_NAME" | grep "$BRANCH_NAME"; then if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists on the remote. Deleting it." git checkout "$BRANCH_NAME"
git push origin --delete "$BRANCH_NAME" else
git checkout -b "$BRANCH_NAME"
fi fi
# Fetch changes from the upstream repository without merging # Fetch changes from the upstream repository without merging
git fetch "${{ env.UPSTREAM_REPO }}" "${{ env.TARGET_BRANCH }}" git fetch "${{ env.UPSTREAM_REPO }}" "${{ env.TARGET_BRANCH }}"
# Create a new branch and apply the upstream changes
git checkout -b "$BRANCH_NAME"
git reset --hard FETCH_HEAD
# Check if there are any changes to commit # Check if there are any changes to commit
if git diff --exit-code origin/${{ env.TARGET_BRANCH }}; then if git diff --exit-code "origin/${{ env.TARGET_BRANCH }}"; then
echo "No changes detected from upstream. Exiting without creating PR." echo "No changes detected from upstream. Exiting without creating PR."
echo "SKIP_PR=true" >> $GITHUB_ENV
else
git add -A
git commit -m "Updating ${{ github.event.repository.name }} with upstream changes"
echo "SKIP_PR=false" >> $GITHUB_ENV
fi fi
- name: Push changes to new branch - name: Push changes to new branch
if: success() if: success() && env.SKIP_PR == 'false'
run: | run: |
git push origin "${{ env.BRANCH_NAME }}" git push origin "${{ env.BRANCH_NAME }}"
- name: Create Pull Request - name: Create Pull Request
if: success() if: success() && env.SKIP_PR == 'false'
uses: peter-evans/create-pull-request@v7.0.5 uses: peter-evans/create-pull-request@v7.0.5
with: with:
token: ${{ steps.generate-rekku-token.outputs.token || secrets.GITHUB_TOKEN }} token: ${{ steps.generate-rekku-token.outputs.token || secrets.GITHUB_TOKEN }}
@ -98,34 +95,35 @@ jobs:
If there are conflicts in this PR, you can resolve them locally by following these steps: If there are conflicts in this PR, you can resolve them locally by following these steps:
1. **Fetch the remote branch**: 1. **Fetch the remote branch**:
```bash ```bash
git fetch origin ${{ env.BRANCH_NAME }} git fetch origin ${{ env.BRANCH_NAME }}
``` ```
2. **Checkout the branch**: 2. **Checkout the branch**:
```bash ```bash
git checkout ${{ env.BRANCH_NAME }} git checkout ${{ env.BRANCH_NAME }}
``` ```
3. **Merge the upstream branch manually**: 3. **Merge the upstream branch manually**:
```bash ```bash
git fetch https://github.com/flathub/${{ env.UPSTREAM_REPO }} ${{ env.TARGET_BRANCH }} git fetch https://github.com/flathub/${{ env.UPSTREAM_REPO }} ${{ env.TARGET_BRANCH }}
git merge FETCH_HEAD git merge FETCH_HEAD
``` ```
4. **Resolve any conflicts**: 4. **Resolve any conflicts**:
Open each conflicted file and manually resolve the conflicts. Then mark each file as resolved: Open each conflicted file and manually resolve the conflicts. Then mark each file as resolved:
```bash ```bash
git add <file-with-conflicts> git add <file-with-conflicts>
``` ```
5. **Complete the merge**: 5. **Complete the merge**:
```bash ```bash
git commit git commit
``` ```
6. **Push the resolved branch**: 6. **Push the resolved branch**:
```bash ```bash
git push origin ${{ env.BRANCH_NAME }} git push origin ${{ env.BRANCH_NAME }}
``` ```
base: ${{ env.TARGET_BRANCH }} base: ${{ env.TARGET_BRANCH }}