2024-11-05 02:36:57 +00:00
|
|
|
name: "Sync with Upstream and Create PR"
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
workflow_call:
|
2024-11-08 01:12:09 +00:00
|
|
|
secrets:
|
2024-11-08 01:08:33 +00:00
|
|
|
REKKU_PRIVATE_KEY:
|
|
|
|
description: 'Private key for Rekku'
|
|
|
|
required: true
|
2024-11-05 02:36:57 +00:00
|
|
|
|
|
|
|
jobs:
|
2024-11-12 06:10:56 +00:00
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
sync-upstream:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
2024-11-08 00:35:46 +00:00
|
|
|
run: |
|
2024-11-08 00:41:15 +00:00
|
|
|
# Manually fully clone the repo
|
|
|
|
git clone "https://github.com/${{ github.repository }}" .
|
|
|
|
git fetch --all --tags --prune
|
2024-11-08 00:35:46 +00:00
|
|
|
git remote add upstream "https://github.com/flathub/${{ github.event.repository.name }}"
|
2024-11-08 00:41:15 +00:00
|
|
|
git fetch upstream --tags
|
|
|
|
git checkout "${{ github.ref_name }}"
|
|
|
|
git branch --set-upstream-to=upstream/${{ github.ref_name }} ${{ github.ref_name }}
|
2024-11-08 00:35:46 +00:00
|
|
|
|
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-06 01:37:41 +00:00
|
|
|
git config --global pull.rebase false
|
2024-11-05 13:26:06 +00:00
|
|
|
|
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
|
2024-11-06 01:48:06 +00:00
|
|
|
continue-on-error: true
|
2024-11-05 13:49:57 +00:00
|
|
|
env:
|
2024-11-06 01:10:26 +00:00
|
|
|
BRANCH_NAME: "feat/update-from-upstream"
|
2024-11-05 02:36:57 +00:00
|
|
|
run: |
|
2024-11-05 13:58:19 +00:00
|
|
|
echo "Syncing from upstream repository ${{ env.UPSTREAM_REPO }} on branch ${{ env.TARGET_BRANCH }}"
|
2024-11-06 01:10:26 +00:00
|
|
|
|
2024-11-06 00:51:53 +00:00
|
|
|
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
|
2024-11-06 00:56:59 +00:00
|
|
|
|
2024-11-06 01:10:26 +00:00
|
|
|
# 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"
|
2024-11-05 14:10:07 +00:00
|
|
|
fi
|
2024-11-06 00:56:59 +00:00
|
|
|
|
2024-11-06 01:01:05 +00:00
|
|
|
# Fetch changes from the upstream repository without merging
|
2024-11-05 13:58:19 +00:00
|
|
|
git fetch "${{ env.UPSTREAM_REPO }}" "${{ env.TARGET_BRANCH }}"
|
2024-11-08 01:55:37 +00:00
|
|
|
git merge "${{ env.UPSTREAM_REPO }}/$TARGET_BRANCH" --no-ff || true
|
2024-11-06 01:27:11 +00:00
|
|
|
|
|
|
|
git diff
|
2024-11-06 01:48:06 +00:00
|
|
|
|
2024-11-06 02:16:44 +00:00
|
|
|
echo "GIT_DIFF=$git diff --minimal" >> $GITHUB_ENV
|
2024-11-06 02:04:02 +00:00
|
|
|
|
2024-11-13 04:18:39 +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:38:55 +00:00
|
|
|
- name: Push changes to new branch
|
2024-11-06 01:54:32 +00:00
|
|
|
if: success()
|
2024-11-08 01:26:19 +00:00
|
|
|
uses: ad-m/github-push-action@master
|
2024-11-08 01:16:27 +00:00
|
|
|
with:
|
|
|
|
branch: "${{ env.BRANCH_NAME }}"
|
2024-11-08 01:35:16 +00:00
|
|
|
github_token: ${{ steps.generate-rekku-token.outputs.token || secrets.TRIGGER_BUILD_TOKEN }}
|
2024-11-06 01:10:26 +00:00
|
|
|
|
2024-11-05 03:02:38 +00:00
|
|
|
- name: Create Pull Request
|
2024-11-06 01:54:32 +00:00
|
|
|
if: success()
|
2024-11-05 14:03:24 +00:00
|
|
|
uses: peter-evans/create-pull-request@v7.0.5
|
2024-11-05 02:36:57 +00:00
|
|
|
with:
|
2024-11-08 01:43:54 +00:00
|
|
|
delete-branch: true
|
2024-11-08 00:50:32 +00:00
|
|
|
token: ${{ steps.generate-rekku-token.outputs.token || secrets.TRIGGER_BUILD_TOKEN }}
|
2024-11-05 13:58:19 +00:00
|
|
|
commit-message: "Sync with upstream changes from ${{ env.UPSTREAM_REPO }}"
|
2024-11-05 13:34:32 +00:00
|
|
|
branch: ${{ env.BRANCH_NAME }}
|
2024-11-05 13:58:19 +00:00
|
|
|
title: "Sync with upstream ${{ env.UPSTREAM_REPO }}"
|
2024-11-05 02:36:57 +00:00
|
|
|
body: |
|
|
|
|
This PR merges the latest changes from the upstream repository:
|
2024-11-05 13:58:19 +00:00
|
|
|
- **Repository**: ${{ env.UPSTREAM_REPO }}
|
|
|
|
- **Branch**: ${{ env.TARGET_BRANCH }}
|
2024-11-06 01:48:06 +00:00
|
|
|
|
|
|
|
## Differences
|
|
|
|
```
|
|
|
|
${{ env.GIT_DIFF }}
|
|
|
|
```
|
2024-11-06 01:10:26 +00:00
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
## Conflict Resolution Instructions
|
|
|
|
If there are conflicts in this PR, you can resolve them locally by following these steps:
|
2024-11-06 01:10:26 +00:00
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
1. **Fetch the remote branch**:
|
2024-11-06 01:10:26 +00:00
|
|
|
```bash
|
|
|
|
git fetch origin ${{ env.BRANCH_NAME }}
|
|
|
|
```
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
2. **Checkout the branch**:
|
2024-11-06 01:10:26 +00:00
|
|
|
```bash
|
|
|
|
git checkout ${{ env.BRANCH_NAME }}
|
|
|
|
```
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
3. **Merge the upstream branch manually**:
|
2024-11-06 01:10:26 +00:00
|
|
|
```bash
|
|
|
|
git fetch https://github.com/flathub/${{ env.UPSTREAM_REPO }} ${{ env.TARGET_BRANCH }}
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
```
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
4. **Resolve any conflicts**:
|
2024-11-06 01:10:26 +00:00
|
|
|
Open each conflicted file and manually resolve the conflicts. Then mark each file as resolved:
|
|
|
|
```bash
|
|
|
|
git add <file-with-conflicts>
|
|
|
|
```
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
5. **Complete the merge**:
|
2024-11-06 01:10:26 +00:00
|
|
|
```bash
|
|
|
|
git commit
|
|
|
|
```
|
|
|
|
|
2024-11-05 02:36:57 +00:00
|
|
|
6. **Push the resolved branch**:
|
2024-11-06 01:10:26 +00:00
|
|
|
```bash
|
|
|
|
git push origin ${{ env.BRANCH_NAME }}
|
|
|
|
```
|
2024-11-05 14:15:41 +00:00
|
|
|
base: ${{ env.TARGET_BRANCH }}
|
2024-11-06 01:10:26 +00:00
|
|
|
|