2024-11-05 02:36:57 +00:00
|
|
|
name: "Sync with Upstream and Create PR"
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
workflow_call:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
sync-upstream:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
fetch-depth: 0 # Retrieve full history to allow merging
|
|
|
|
|
2024-11-05 13:18:16 +00:00
|
|
|
- name: Generate a token for Rekku
|
|
|
|
if: ${{ github.repository == 'RetroDECK/RetroDECK' }}
|
|
|
|
id: generate-rekku-token
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
with:
|
|
|
|
app-id: ${{ vars.REKKU_APP_ID }}
|
|
|
|
private-key: ${{ secrets.REKKU_PRIVATE_KEY }}
|
|
|
|
repositories: "RetroDECK,Cooker"
|
|
|
|
owner: "RetroDECK"
|
|
|
|
|
2024-11-05 13:26:06 +00:00
|
|
|
- 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"
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
- 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
|
2024-11-05 06:22:56 +00:00
|
|
|
: "${UPSTREAM_REPO:=${{ github.event.repository.name }}}"
|
2024-11-05 02:36:57 +00:00
|
|
|
: "${TARGET_BRANCH:=master}"
|
|
|
|
|
2024-11-05 06:22:56 +00:00
|
|
|
# Format the repository name for flathub, ensure no trailing spaces
|
2024-11-05 02:36:57 +00:00
|
|
|
UPSTREAM_REPO="https://github.com/flathub/${UPSTREAM_REPO}"
|
|
|
|
|
2024-11-05 06:22:56 +00:00
|
|
|
echo "UPSTREAM_REPO=${UPSTREAM_REPO}" >> $GITHUB_ENV
|
|
|
|
echo "TARGET_BRANCH=${TARGET_BRANCH}" >> $GITHUB_ENV
|
2024-11-05 02:36:57 +00:00
|
|
|
|
|
|
|
- name: Sync from Upstream Repository
|
|
|
|
run: |
|
|
|
|
echo "Syncing from upstream repository $UPSTREAM_REPO on branch $TARGET_BRANCH"
|
|
|
|
|
|
|
|
# Perform fetch and merge, attempting to resolve conflicts by preferring the upstream changes
|
|
|
|
git fetch "$UPSTREAM_REPO" "$TARGET_BRANCH"
|
|
|
|
git merge FETCH_HEAD -m "Merge changes from upstream $UPSTREAM_REPO/$TARGET_BRANCH" || {
|
|
|
|
echo "Conflict detected. Resolving by preferring upstream changes..."
|
|
|
|
git merge --strategy-option theirs --no-edit FETCH_HEAD
|
|
|
|
}
|
|
|
|
|
2024-11-05 13:38:55 +00:00
|
|
|
- name: Create a new branch for PR if changes detected
|
|
|
|
id: create_branch
|
2024-11-05 02:36:57 +00:00
|
|
|
env:
|
|
|
|
BRANCH_NAME: "sync-${{ github.run_id }}" # Temporary branch name for the PR
|
|
|
|
run: |
|
|
|
|
if [ "$(git status --porcelain)" ]; then
|
|
|
|
git checkout -b "$BRANCH_NAME"
|
2024-11-05 13:38:55 +00:00
|
|
|
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
|
2024-11-05 02:36:57 +00:00
|
|
|
else
|
2024-11-05 13:38:55 +00:00
|
|
|
echo "No changes detected. Exiting."
|
|
|
|
exit 0
|
2024-11-05 02:36:57 +00:00
|
|
|
fi
|
|
|
|
|
2024-11-05 13:38:55 +00:00
|
|
|
- name: Push changes to new branch
|
|
|
|
if: success()
|
|
|
|
run: |
|
|
|
|
git push origin "$BRANCH_NAME"
|
|
|
|
|
2024-11-05 03:02:38 +00:00
|
|
|
- name: Create Pull Request
|
2024-11-05 13:38:55 +00:00
|
|
|
if: success()
|
2024-11-05 02:36:57 +00:00
|
|
|
uses: peter-evans/create-pull-request@v4
|
|
|
|
with:
|
2024-11-05 13:34:32 +00:00
|
|
|
token: ${{ steps.generate-rekku-token.outputs.token || secrets.GITHUB_TOKEN }}
|
2024-11-05 02:36:57 +00:00
|
|
|
commit-message: "Sync with upstream changes from $UPSTREAM_REPO"
|
2024-11-05 13:34:32 +00:00
|
|
|
branch: ${{ env.BRANCH_NAME }}
|
2024-11-05 02:36:57 +00:00
|
|
|
title: "Sync with upstream $UPSTREAM_REPO"
|
|
|
|
body: |
|
|
|
|
This PR merges the latest changes from the upstream repository:
|
|
|
|
- **Repository**: $UPSTREAM_REPO
|
|
|
|
- **Branch**: $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
|
2024-11-05 13:34:32 +00:00
|
|
|
git fetch origin ${{ env.BRANCH_NAME }}
|
2024-11-05 02:36:57 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
2. **Checkout the branch**:
|
|
|
|
```bash
|
2024-11-05 13:34:32 +00:00
|
|
|
git checkout ${{ env.BRANCH_NAME }}
|
2024-11-05 02:36:57 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
3. **Merge the upstream branch manually**:
|
|
|
|
```bash
|
|
|
|
git fetch https://github.com/flathub/$UPSTREAM_REPO $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 <file-with-conflicts>
|
|
|
|
```
|
|
|
|
|
|
|
|
5. **Complete the merge**:
|
|
|
|
```bash
|
|
|
|
git commit
|
|
|
|
```
|
|
|
|
|
|
|
|
6. **Push the resolved branch**:
|
|
|
|
```bash
|
2024-11-05 13:34:32 +00:00
|
|
|
git push origin ${{ env.BRANCH_NAME }}
|
2024-11-05 02:36:57 +00:00
|
|
|
```
|
2024-11-05 13:38:55 +00:00
|
|
|
base: $TARGET_BRANCH
|