diff --git a/.github/workflows/pr_from_upstream.yml b/.github/workflows/pr_from_upstream.yml new file mode 100644 index 0000000..5e2bdb5 --- /dev/null +++ b/.github/workflows/pr_from_upstream.yml @@ -0,0 +1,101 @@ +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 + + - 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.repository }} }" + : "${TARGET_BRANCH:=master}" + + # Format the repository name for flathub + 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 + 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 + } + + + - name: Push changes if there are updates + env: + BRANCH_NAME: "sync-${{ github.run_id }}" # Temporary branch name for the PR + run: | + if [ "$(git status --porcelain)" ]; then + git checkout -b "$BRANCH_NAME" + git push origin "$BRANCH_NAME" + else + echo "No changes to push." + fi + + - name: Create Pull Request + if: success() && steps.push.outputs.BRANCH_NAME != '' # Only run if there are changes + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Sync with upstream changes from $UPSTREAM_REPO" + branch: ${{ steps.push.outputs.BRANCH_NAME }} + 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 + git fetch origin ${{ steps.push.outputs.BRANCH_NAME }} + ``` + + 2. **Checkout the branch**: + ```bash + git checkout ${{ steps.push.outputs.BRANCH_NAME }} + ``` + + 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 + ``` + + 5. **Complete the merge**: + ```bash + git commit + ``` + + 6. **Push the resolved branch**: + ```bash + git push origin ${{ steps.push.outputs.BRANCH_NAME }} + ``` + base: $TARGET_BRANCH + labels: ["sync", "upstream"] diff --git a/.gitignore b/.gitignore index c267f68..b5351ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -build-dir/ -.flatpak-builder/ +artifacts-repo +artifacts-build-dir +tree.html \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..33701de --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# RetroDECK Components Template + +This repository serves as a library for storing common automation workflows and essential files needed when adding new external modules or repositories. + +## How to Use This Repository + +1. **Copy Workflow Templates** + Copy the contents of the `workflow-templates` directory into the `.github/workflows` directory of the repository you want to automate. Edit any necessary variables to customize the workflows to your needs (details TBD). + +2. **Copy Common Files** + Copy files such as `.gitignore` into the root directory of the target repository to ensure consistency in configuration and file management. \ No newline at end of file diff --git a/automation_tools/update_from_upstream.sh b/automation_tools/update_from_upstream.sh index 5b6a7fe..a8d9b40 100755 --- a/automation_tools/update_from_upstream.sh +++ b/automation_tools/update_from_upstream.sh @@ -1,4 +1,7 @@ #!/bin/bash -git fetch https://github.com/flathub/net.rpcs3.RPCS3 master # Fetch the latest changes from the remote master branch +$UPSTREAM_REPO='com.something.else' +$TARGET_BRANCH='master' + +git fetch https://github.com/flathub/"$UPSTREAM_REPO" "$TARGET_BRANCH" # Fetch the latest changes from the remote master branch git merge FETCH_HEAD # Merge the fetched changes into your current branch \ No newline at end of file diff --git a/flathub.json b/flathub.json deleted file mode 100644 index 637604e..0000000 --- a/flathub.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "only-arches": ["x86_64"] -} diff --git a/workflow_templates/build-artifacts.yml b/workflow_templates/build-artifacts.yml new file mode 100644 index 0000000..7ec815a --- /dev/null +++ b/workflow_templates/build-artifacts.yml @@ -0,0 +1,20 @@ +name: "Build Artifacts for RetroDECK main manifest" + +on: + push: + branches: + - master + - main + workflow_call: + +jobs: + Building-project: + runs-on: ubuntu-latest + + steps: + + - name: "Install dependencies" + uses: RetroDECK/components-template/.github/workflows/install_dependencies.yml@main + + - name: "Build project" + uses: RetroDECK/components-template/.github/workflows/build_artifacts.yml@main \ No newline at end of file diff --git a/workflow_templates/pr-from-upstream.yml b/workflow_templates/pr-from-upstream.yml new file mode 100644 index 0000000..2eccbdf --- /dev/null +++ b/workflow_templates/pr-from-upstream.yml @@ -0,0 +1,15 @@ +name: "Sync with Upstream and Create PR" + +on: + workflow_call: + schedule: + - cron: "30 0 * * *" # Run every day at 00:30 UTC (9:30 JST) + +jobs: + Upstream-sync: + runs-on: ubuntu-latest + + steps: + + - name: "Sync with upstream" + uses: RetroDECK/components-template/.github/workflows/pr_from_upstream.yml@main \ No newline at end of file