name: "Sync with Upstream and Create PR" on: workflow_dispatch: workflow_call: secrets: REKKU_PRIVATE_KEY: description: 'Private key for Rekku' required: true jobs: sync-upstream: runs-on: ubuntu-latest steps: - name: Checkout repository run: | # Manually fully clone the repo git clone "https://github.com/${{ github.repository }}" . git fetch --all --tags --prune git remote add upstream "https://github.com/flathub/${{ github.event.repository.name }}" git fetch upstream --tags git checkout "${{ github.ref_name }}" git branch --set-upstream-to=upstream/${{ github.ref_name }} ${{ github.ref_name }} - name: Generate a token for Rekku id: generate-rekku-token uses: actions/create-github-app-token@v1 with: app-id: ${{ vars.REKKU_APP_ID }} private-key: ${{ secrets.REKKU_PRIVATE_KEY }} owner: "RetroDECK" - name: Configuring Git run: | git config --global protocol.file.allow always git config --global user.name "Rekku" git config --global user.email "rekku@retrodeck.net" git config --global pull.rebase false - name: Set default values for UPSTREAM_REPO and TARGET_BRANCH if not set run: | # Use the current repository name if UPSTREAM_REPO is not set : "${UPSTREAM_REPO:=${{ github.event.repository.name }}}" : "${TARGET_BRANCH:=master}" # Format the repository name for flathub, ensure no trailing spaces UPSTREAM_REPO="https://github.com/flathub/${UPSTREAM_REPO}" echo "UPSTREAM_REPO=${UPSTREAM_REPO}" >> $GITHUB_ENV echo "TARGET_BRANCH=${TARGET_BRANCH}" >> $GITHUB_ENV - name: Sync from Upstream Repository continue-on-error: true env: 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 # 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 }}" git pull "${{ env.UPSTREAM_REPO }}" "${{ env.TARGET_BRANCH }}" git diff echo "GIT_DIFF=$git diff --minimal" >> $GITHUB_ENV - name: Push changes to new branch if: success() uses: ad-m/github-push-action@v0.8.0 with: branch: "${{ env.BRANCH_NAME }}" github_token: ${{ secrets.REKKU_PRIVATE_KEY }} - name: Create Pull Request if: success() uses: peter-evans/create-pull-request@v7.0.5 with: token: ${{ steps.generate-rekku-token.outputs.token || secrets.TRIGGER_BUILD_TOKEN }} commit-message: "Sync with upstream changes from ${{ env.UPSTREAM_REPO }}" branch: ${{ env.BRANCH_NAME }} title: "Sync with upstream ${{ env.UPSTREAM_REPO }}" body: | This PR merges the latest changes from the upstream repository: - **Repository**: ${{ env.UPSTREAM_REPO }} - **Branch**: ${{ env.TARGET_BRANCH }} ## Differences ``` ${{ env.GIT_DIFF }} ``` ## 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 }} ``` 2. **Checkout the branch**: ```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 ``` 4. **Resolve any conflicts**: 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 ``` 6. **Push the resolved branch**: ```bash git push origin ${{ env.BRANCH_NAME }} ``` base: ${{ env.TARGET_BRANCH }}