Skip to content

Commit

Permalink
feat!: enable files removal and action rename (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Mar 27, 2023
1 parent 33516bd commit 54b11fb
Show file tree
Hide file tree
Showing 8 changed files with 4,405 additions and 9,199 deletions.
80 changes: 60 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Copy Files to Other Repositories
# Manage Files in Multiple Repositories

GitHub Action that enables you to keep a file in `Repository A` and copy it over to `Repository N`.
GitHub Action that enables you to keep a file in `Repository A` and copy it over, update or remove it from `Repository N`.
It is useful for use cases like:
- you have a GitHub Actions workflow files that are the same for every repo and you want to edit it only once and then see change in all the other repositories
- you have a `CODE_OF_CONDUCT.md` or `CONTRIBUTING.md` file that you want to have in the same form in all the repositories. You want to edit it in one repo and then have the change replicated in other repositories
- you have a file that has to be removed from multiple repositories

## Some breaking changes

If you used `Copy Files to Other Repositories` action before it became `Manage Files in Multiple Repositories` the only breaking change that you need to be aware of, except new features, is that now this action is also able to pick up deletions. In other words, imagine a situation where `patterns_to_include` has value `./github/workflows/another_file.yml`. The new version of action not only will pick up modifications of `another_file.yml` but also if you remove that file, this action will pick that info up and also remove the file in other repositories that have it, respecting `destination` field.

<!-- toc -->

Expand All @@ -24,7 +29,7 @@ It is useful for use cases like:

In [AsyncAPI](https://www.asyncapi.com/) we have over 50 repositories. We use GitHub Actions at scale. Many workflows are exactly the same. We keep all workflows in [.github](https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/creating-a-default-community-health-file). This action replicates all changes to workflows to all the other repos.

Use case mentione above was first. Then more folks started using this action. So this action evolved to support any file replication, not only workflows.
Use case mentione above was first. Then more folks started using this action. So this action evolved to support any file modifications, not only workflows.

## Supported Event Triggers

Expand Down Expand Up @@ -59,8 +64,9 @@ This action can be triggered by:
Name | Description | Required | Default
--|------|--|--
github_token | Token to use GitHub API. It must have "repo" and "workflow" scopes so it can push to repo and edit workflows. It cannot be the default GitHub Actions token GITHUB_TOKEN. GitHub Action token's permissions are limited to the repository that contains your workflows. Provide token of the user who has the right to push to the repos that this action is supposed to update. The same token is used for pulling repositories - important to know for those that want to use this action with private repositories. | true | -
patterns_to_ignore | Comma-separated list of file paths or directories that should be handled by this action and updated in other repositories. This option is useful if you use "patterns_to_include" with large amount of files, and some of them you want to ignore. In the format `./github/workflows/another_file.yml`. Internally it is handled by standard JavaScript `includes` function. | true | -
patterns_to_include | Comma-separated list of file paths or directories that should be handled by this action and updated in other repositories. In the format `.github/workflows`. Internally it is handled by standard JavaScript `includes` function. | true | -
patterns_to_ignore | Comma-separated list of file paths or directories that should be handled by this action and updated in other repositories. This option is useful if you use "patterns_to_include" or "patterns_to_remove" with large amount of files, and some of them you want to ignore. In the format `./github/workflows/another_file.yml`. Internally it is handled by standard JavaScript `includes` function. | true | -
patterns_to_remove | Comma-separated list of file paths or directories that should be handled by this action and removed from other repositories. This option do not perform any removal of files that are located in repository there this action is used. This option cannot be used at the same time with "patterns_to_include", these fields are mutually exclusive. In the format `./github/workflows`. | true | -
patterns_to_include | Comma-separated list of file paths or directories that should be handled by this action and copied or updated or removed in other repositories. Now this option is self aware not only of creation and modification but also deletion of file that match the pattern. This option cannot be used at the same time with "patterns_to_remove", these fields are mutually exclusive. In the format `.github/workflows`. Internally it is handled by standard JavaScript `includes` function. | true | -
committer_username | The username (not display name) of the committer will be used to commit changes in the workflow file in a specific repository. In the format `web-flow`. | false | `web-flow`
committer_email | The committer's email that will be used in the commit of changes in the workflow file in a specific repository. In the format `[email protected]`.| false | `[email protected]`
commit_message | It is used as a commit message when pushing changes with global workflows. It is also used as a title of the pull request that is created by this action. | false | `Update global workflows`
Expand All @@ -69,10 +75,44 @@ topics_to_include | Comma-separated list of topics that should get updates from
exclude_private | Boolean value on whether to exclude private repositories from this action. | false | false
exclude_forked | Boolean value on whether to exclude forked repositories from this action. | false | false
branches | By default, action creates branch from default branch and opens PR only against default branch. With this property you can override this behaviour. You can provide a comma-separated list of branches this action shoudl work against. You can also provide regex, but without comma as list of branches is split in code by comma. | false | default branch is used
destination | Name of the directory where all files matching "patterns_to_include" will be copied. In the format `.github/workflows`. | false | -
destination | Name of the directory where all files matching "patterns_to_include" will be copied. It doesn't work with "patterns_to_remove". In the format `.github/workflows`. | false | -

## Examples

### Minimum Workflow to Remove a File from Other Repos

Below workflow will remove `LICENSE` file from all repos in organization. The repo where this workflow runs, does not need to have `LICENSE` file.

> of course you should never remove licenses from repos :smiley:

```yml
name: I want to remove LICENSE file
on:
push:
branches: [ master ] #or main
workflow_dispatch: {} #to enable manual triggering of the action
jobs:
removal:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.CUSTOM_TOKEN }}
#you must specify what pattern to include otherwise all files from the repository will be replicated
patterns_to_remove: 'LICENSE'
#must have, so the workflow do not copy this workflow file to all other repos. It should be only in one, main, .github repo
patterns_to_ignore: '.github/workflows/name_of_file_where_this_action_is_used.yml'
committer_username: santiago-bernabeu
committer_email: [email protected]
commit_message: "ci: removal of license files"
```

### Minimum Workflow to Support Only Workflows Replication

```yml
Expand All @@ -90,8 +130,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: derberg/copy-files-to-other-repositories@v1.0.0
- uses: actions/checkout@v3
- uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.CUSTOM_TOKEN }}
#you must specify what pattern to include otherwise all files from the repository will be replicated
Expand All @@ -118,9 +158,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating global workflow
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.CUSTOM_TOKEN }}
patterns_to_ignore: '.github/workflows/name_of_file_where_this_action_is_used.yml'
Expand Down Expand Up @@ -203,9 +243,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating file
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: CODE_OF_CONDUCT.md
Expand All @@ -219,9 +259,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating file
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: CONTRIBUTING.md
Expand All @@ -235,9 +275,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating file
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: .github/workflows/if-go-pr-testing.yml
Expand All @@ -251,9 +291,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating file
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: .github/workflows/if-nodejs-pr-testing.yml,.github/workflows/if-nodejs-release.yml,.github/workflows/if-nodejs-version-bump.yml,.github/workflows/bump.yml
Expand All @@ -267,9 +307,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Replicating file
uses: derberg/copy-files-to-other-repositories@v1.0.0
uses: derberg/manage-files-in-multiple-repositories@v2
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: .github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/sentiment-analysis.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,
Expand Down
19 changes: 13 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Copy Files to Other Repositories
description: This action enables you to copy/replicate from one repo to another automatically.
name: Manage Files in Multiple Repositories
description: This action enables you to copy/update/remove files from one repo to multiple other repos automatically in one shot.
inputs:
github_token:
description: >
Expand Down Expand Up @@ -28,12 +28,19 @@ inputs:
patterns_to_ignore:
description: >
Comma-separated list of file paths or directories that should be handled by this action and updated in other repositories.
This option is useful if you use "patterns_to_include" with large amount of files, and some of them you want to ignore.
This option is useful if you use "patterns_to_include" or "patterns_to_remove" with large amount of files, and some of them you want to ignore.
In the format `./github/workflows/another_file.yml`.
required: true
patterns_to_remove:
description: >
Comma-separated list of file paths or directories that should be handled by this action and removed from other repositories. This option do not perform any removal of files that are located in repository there this action is used.
This option cannot be used at the same time with "patterns_to_include", these fields are mutually exclusive.
In the format `./github/workflows`.
required: true
patterns_to_include:
description: >
Comma-separated list of file paths or directories that should be handled by this action and updated in other repositories.
Comma-separated list of file paths or directories that should be handled by this action and copied or updated in other repositories.
This option cannot be used at the same time with "patterns_to_remove", these fields are mutually exclusive.
In the format `.github/workflows`.
required: true
repos_to_ignore:
Expand Down Expand Up @@ -66,10 +73,10 @@ inputs:
required: false
destination:
description: >
Name of the directory where all files matching "patterns_to_include" will be copied. In the format `.github/workflows`.
Name of the directory where all files matching "patterns_to_include" will be copied. It doesn't work with "patterns_to_remove". In the format `.github/workflows`.
required: false
runs:
using: node12
using: node16
main: dist/index.js
branding:
icon: compass
Expand Down
Loading

0 comments on commit 54b11fb

Please sign in to comment.