diff --git a/.github/workflows/pr_from_upstream.yml b/.github/workflows/pr_from_upstream.yml index ae78d1b..057b755 100644 --- a/.github/workflows/pr_from_upstream.yml +++ b/.github/workflows/pr_from_upstream.yml @@ -45,44 +45,41 @@ jobs: - name: Sync from Upstream Repository env: - BRANCH_NAME: "sync-${{ github.run_id }}" # Temporary branch name for the PR + BRANCH_NAME: "feat/update-from-upstream" run: | echo "Syncing from upstream repository ${{ env.UPSTREAM_REPO }} on branch ${{ env.TARGET_BRANCH }}" - + echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV - # Fetch and delete the branch if it exists locally 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 - if git ls-remote --heads origin "$BRANCH_NAME" | grep "$BRANCH_NAME"; then - echo "Branch $BRANCH_NAME exists on the remote. Deleting it." - git push origin --delete "$BRANCH_NAME" + # Switches or creates update branch + if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then + git checkout "$BRANCH_NAME" + else + git checkout -b "$BRANCH_NAME" fi # Fetch changes from the upstream repository without merging 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 - 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 "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 - + - name: Push changes to new branch - if: success() + if: success() && env.SKIP_PR == 'false' run: | git push origin "${{ env.BRANCH_NAME }}" - + - name: Create Pull Request - if: success() + if: success() && env.SKIP_PR == 'false' uses: peter-evans/create-pull-request@v7.0.5 with: token: ${{ steps.generate-rekku-token.outputs.token || secrets.GITHUB_TOKEN }} @@ -93,39 +90,40 @@ jobs: This PR merges the latest changes from the upstream repository: - **Repository**: ${{ env.UPSTREAM_REPO }} - **Branch**: ${{ env.TARGET_BRANCH }} - + ## Conflict Resolution Instructions If there are conflicts in this PR, you can resolve them locally by following these steps: - + 1. **Fetch the remote branch**: - ```bash - git fetch origin ${{ env.BRANCH_NAME }} - ``` - + ```bash + git fetch origin ${{ env.BRANCH_NAME }} + ``` + 2. **Checkout the branch**: - ```bash - git checkout ${{ env.BRANCH_NAME }} - ``` - + ```bash + git checkout ${{ env.BRANCH_NAME }} + ``` + 3. **Merge the upstream branch manually**: - ```bash - git fetch https://github.com/flathub/${{ env.UPSTREAM_REPO }} ${{ env.TARGET_BRANCH }} - git merge FETCH_HEAD - ``` - + ```bash + git fetch https://github.com/flathub/${{ env.UPSTREAM_REPO }} ${{ env.TARGET_BRANCH }} + git merge FETCH_HEAD + ``` + 4. **Resolve any conflicts**: - Open each conflicted file and manually resolve the conflicts. Then mark each file as resolved: - ```bash - git add - ``` - + Open each conflicted file and manually resolve the conflicts. Then mark each file as resolved: + ```bash + git add + ``` + 5. **Complete the merge**: - ```bash - git commit - ``` - + ```bash + git commit + ``` + 6. **Push the resolved branch**: - ```bash - git push origin ${{ env.BRANCH_NAME }} - ``` + ```bash + git push origin ${{ env.BRANCH_NAME }} + ``` base: ${{ env.TARGET_BRANCH }} +