Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
upload-cloud

GitHub Action

File Sync

v2.1.0

File Sync

upload-cloud

File Sync

Github Action to sync files across repositories

Installation

Copy and paste the following snippet into your .yml file.

              

- name: File Sync

uses: kbrashears5/[email protected]

Learn more about this action in kbrashears5/github-action-file-sync

Choose a version

github-action-file-sync

Github Action to sync files across repos

version

Use Cases

Great for keeping your files in sync across multiple repositories. A good use case for me was the .github/dependabot.yml files.

I have a master repo where these are synced from, and then they are kept in sync with the master repository.

If I need to make a change, rather than go make a change x many times across all my repositories, I make the change once, and on push to the master repository, all my child repositories are updated.

Another example is if you're creating new Github Actions for a repository, you can make them once, check them into master repository, and then deploy them all across all your repositories all at once.

This also isn't limited to Github Action yaml files - another use case could be keeping the .editorconfig, LICENSE, tsconfig.json, tslint.json, .gitignore, azure-pieplines.yml, etc. in sync across all your repositories.

If I have a file that gets out of sync for whatever reason, the cron side of the on will take care of putting it back in sync with the master repository.

See my master sync repo for examples on how I use it across all my repositories.

Setup

Create a new file called /.github/workflows/file-sync.yml that looks like so:

name: File Sync

on:
  push:
    branches:
      - master
  schedule:
    - cron: 0 0 * * *

jobs:
  file_sync:
    runs-on: ubuntu-latest
    steps:
      - name: Fetching Local Repository
        uses: actions/checkout@master
      - name: File Sync
        uses: kbrashears5/[email protected]
        with:
          REPOSITORIES: |
            username/repo@master
          FILES: |
            ./sync/dependabot.yml=.github/dependabot.yml
          TOKEN: ${{ secrets.ACTIONS }}

Parameters

Parameter Required Description
REPOSITORIES true List of repositories to sync the files to. Optionally provide branch name
FILES true List of files to sync across repositories. See below for details
TOKEN true Personal Access Token with Repo scope
PULL_REQUEST false Whether or not you want to do a pull request. Only works when branch name is provided. Default false

Examples

REPOSITORIES parameter

Push to the master branch

REPOSITORIES: |
    username/repo

Push to the dev branch

REPOSITORIES: |
    username/repo@dev

FILES parameter

Root file with root destination

FILES: |
    dependabot.yml

Root file with new destination

FILES: |
    dependabot.yml=.github/dependabot.yml

Nested file with same nested file structure destination

FILES: |
    ./.github/dependabot.yml

Nested file with new destination

FILES: |
    ./sync/dependabot.yml=.github/dependabot.yml

TOKEN parameter

Use the repository secret named ACTIONS

TOKEN: ${{ secrets.ACTIONS }}