Skip to content

Sync from fork

Sync from fork #23430

name: Sync from fork
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 * * * *"
workflow_dispatch:
jobs:
check-for-changes:
runs-on: ubuntu-latest
env:
FILES_TO_CHECK: "assets/assets.json|assets/resources/scriptlets.js|web_accessible_resources/|js/redirect-resources.js"
UPSTREAM_URL: "https://github.com/gorhill/ublock.git"
outputs:
changes: ${{ steps.git-check.outputs.changes-present }}
steps:
- uses: actions/checkout@v4
- name: Fetch release version
run: |
git remote add upstream ${UPSTREAM_URL}
git fetch upstream && git diff --name-only --diff-filter AM HEAD..remotes/upstream/master > updatedfiles.txt
- name: Check for modified files
id: git-check
run: echo changes-present=$(if grep -qE "${FILES_TO_CHECK}" updatedfiles.txt; then echo 'true'; else echo 'false'; fi) >> $GITHUB_OUTPUT
- name: Show files
run: cat updatedfiles.txt
- name: Have files changed
if: steps.check-for-changes.outputs.changes-present == 'false'
run: echo "No changes needed to be synchronised"
sync:
if: ${{ needs.check-for-changes.outputs.changes == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: check-for-changes
runs-on: ubuntu-latest
steps:
- name: Create mirror branch
run: |
git clone "https://github.com/gorhill/${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}"
cd ${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}
git checkout -b mirror
git remote add github "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git"
git push -u github mirror
create-pr:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: sync
runs-on: ubuntu-latest
steps:
- name: Create PR
run: |
gh pr create --title "Fork Sync: Update from parent repository" --body "This PR was automatically created by a GitHub Action triggered by a cron schedule. Please review the changes and merge if appropriate." --base master --head mirror --repo ${GITHUB_REPOSITORY} || true
update-pr:
needs: create-pr
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPSTREAM_URL: "https://github.com/gorhill/ublock.git"
steps:
- uses: actions/checkout@v4
- name: Collate Changes
run: |
git remote add upstream ${UPSTREAM_URL}
git fetch upstream
FILES_TO_CHECK=("assets/assets.json" "assets/resources/scriptlets.js" "src/web_accessible_resources" "src/js/redirect-resources.js")
for files in ${FILES_TO_CHECK[*]}; do
echo '```diff' >> changes.txt;
git diff --diff-filter AM HEAD..remotes/upstream/master -- $files >> changes.txt;
echo -e '```\n' >> changes.txt;
done;
git remote remove upstream
- name: Set PR Number to env
run: echo "PR_NUMBER=`gh pr list | grep 'Fork Sync' | awk {'print $1'}`" >> $GITHUB_ENV
- name: Update PR Description
run: gh pr edit $PR_NUMBER -b "`cat "changes.txt"`"
- name: Run puLL-Merge
uses: brave/pull-merge@main
with:
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
prnum: ${{ env.PR_NUMBER }}
github_token: ${{ secrets.GITHUB_TOKEN }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
filterdiff_args: --include=**/assets/assets.json --include=**/assets/resources/scriptlets.js --include=**/web_accessible_resources/ --include=**/js/redirect-resources.js
on-failure:
runs-on: ubuntu-latest
if: ${{ always() && (needs.sync.result == 'failure' || needs.create-pr.result == 'failure' || needs.update-pr.result == 'failure') }}
needs:
- sync
- create-pr
- update-pr
steps:
- uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
author_name: "Github Actions"
status: failure
fields: repo,message,commit,author,eventName,ref,workflow,pullRequest