|
1 | | -# github-org-member-manage-action |
| 1 | +# GitHub Org Member Manage Action |
2 | 2 |
|
3 | | -## Objective |
| 3 | +This GitHub Action allows you to manage your GitHub organization's memberships in a declarative way using a YAML file. This file becomes the single source of truth for your organization's members, making it easy to manage and version control your member list. |
4 | 4 |
|
5 | | -Mange GitHub org memberships in a declarative way (.yaml). |
6 | | -YAML will be the single source of truth for the org memberships. |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Declarative Membership Management:** Define your organization's members and their roles (admin or member) in a simple YAML file. |
| 8 | +- **Synchronization:** The action automatically synchronizes the members of your organization to match the state defined in your YAML file. |
| 9 | +- **Dry Run Mode:** Preview the changes that would be made without actually applying them. |
| 10 | +- **Bootstrap Your Configuration:** `write` mode helps you to create a `members.yaml` from the current state of your GitHub org members. |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +To use this action in your workflow, you need to add a step that uses `codingpot/github-org-member-manage-action`. |
| 15 | + |
| 16 | +### Example Workflow |
| 17 | + |
| 18 | +Here is an example workflow that runs on a schedule and synchronizes the organization's members: |
| 19 | + |
| 20 | +```yaml |
| 21 | +name: Manage Org Members |
| 22 | + |
| 23 | +on: |
| 24 | + schedule: |
| 25 | + - cron: '0 0 * * *' # Run daily at midnight |
| 26 | + workflow_dispatch: |
| 27 | + |
| 28 | +jobs: |
| 29 | + manage-members: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + |
| 35 | + - name: Manage GitHub Org Members |
| 36 | + uses: "codingpot/github-org-member-manage-action@v1" |
| 37 | + with: |
| 38 | + gh_token: ${{ secrets.GH_TOKEN }} |
| 39 | + members_filepath: 'members.yaml' |
| 40 | + mode: 'sync' |
| 41 | +``` |
| 42 | +
|
| 43 | +### `members.yaml` format |
| 44 | + |
| 45 | +The `members.yaml` file defines the members of your organization. Here is an example: |
7 | 46 |
|
8 | 47 | ```yaml |
9 | 48 | # members.yaml |
10 | | -org_name: codingpot |
| 49 | +org_name: your-org-name |
11 | 50 |
|
12 | 51 | admins: |
13 | | - - kkweon |
14 | | - - kkweon2 |
| 52 | + - admin-user-1 |
| 53 | + - admin-user-2 |
15 | 54 |
|
16 | 55 | members: |
17 | | - - deepdiver1 |
18 | | - - deepdiver2 |
| 56 | + - member-user-1 |
| 57 | + - member-user-2 |
19 | 58 | ``` |
20 | 59 |
|
21 | | -## How to use |
| 60 | +## Action Inputs |
22 | 61 |
|
23 | | -```yaml |
24 | | -steps: |
25 | | - - uses: "codingpot/github-org-member-manage-action@v1" |
26 | | - with: |
27 | | - gh_token: ${{ secrets.GH_TOKEN }} # (required) Needs admin:org permission |
28 | | - members_filepath: members.yaml # (optional) |
29 | | - dry_run: false # (optional) |
30 | | - mode: sync # (optional) write or sync |
| 62 | +| Input | Description | Default | |
| 63 | +| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | |
| 64 | +| `gh_token` | A GitHub token with `admin:org` scope. This is required to manage organization memberships. It is recommended to use a secret to store the token. | **Required** | |
| 65 | +| `members_filepath` | The file path to the YAML file containing the list of members. This file will be the single source of truth for the organization's memberships. | `members.yaml` | |
| 66 | +| `dry_run` | If set to `true`, the action will only print the changes that would be made, without actually applying them. This is useful for testing and debugging. | `false` | |
| 67 | +| `mode` | The mode of operation for the action. There are two modes available: `sync` and `write`.<ul><li>`sync`: This mode synchronizes the organization's memberships with the state defined in the `members_filepath` file.</li><li>`write`: This mode fetches the current organization memberships and writes them to the `members_filepath` file.</li></ul> | `sync` | |
| 68 | + |
| 69 | +## Development |
| 70 | + |
| 71 | +This section guides you through setting up your development environment and testing the action locally. |
| 72 | + |
| 73 | +### Prerequisites |
| 74 | + |
| 75 | +- [Java](httpshttps://www.java.com/en/download/) |
| 76 | +- [Gradle](https://gradle.org/install/) |
| 77 | + |
| 78 | +### Local Testing |
| 79 | + |
| 80 | +1. Create a `members.yaml` file in the root of the project with the `org_name` of the organization you want to manage. |
| 81 | + |
| 82 | + ```yaml |
| 83 | + # members.yaml |
| 84 | + org_name: your-org-name |
| 85 | + ``` |
| 86 | + |
| 87 | +2. Run the action in `write` mode to fetch the current members of the organization and populate the `members.yaml` file. You will need to provide a GitHub token with `admin:org` scope as an environment variable. |
| 88 | + |
| 89 | + ```shell |
| 90 | + INPUT_GH_TOKEN=<your-github-token> \ |
| 91 | + INPUT_MODE=write \ |
| 92 | + INPUT_MEMBERS_FILEPATH=$PWD/members.yaml \ |
| 93 | + ./gradlew run |
| 94 | + ``` |
| 95 | + |
| 96 | +3. After the `members.yaml` file is populated, you can run the action in `sync` mode to test the synchronization logic. It's recommended to run with `INPUT_DRY_RUN=true` first to preview the changes. |
| 97 | + |
| 98 | + ```shell |
| 99 | + INPUT_GH_TOKEN=<your-github-token> \ |
| 100 | + INPUT_MODE=sync \ |
| 101 | + INPUT_DRY_RUN=true \ |
| 102 | + INPUT_MEMBERS_FILEPATH=$PWD/members.yaml \ |
| 103 | + ./gradlew run |
| 104 | + ``` |
| 105 | + |
| 106 | +### Unit Tests |
| 107 | + |
| 108 | +To run the unit tests, use the following command: |
| 109 | + |
| 110 | +```bash |
| 111 | +./gradlew test |
31 | 112 | ``` |
| 113 | + |
| 114 | +## Contributing |
| 115 | + |
| 116 | +Contributions are welcome! Please follow these guidelines when contributing: |
| 117 | + |
| 118 | +- **Code Quality:** Write clean, maintainable, and well-documented code. |
| 119 | +- **Conventional Commits:** Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for all commit messages. |
| 120 | +- **Pull Requests:** Create a pull request with a clear description of your changes. |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +*This README was updated by an AI assistant.* |
0 commit comments