npm package: @jamesives/github-sponsors-readme-action
Description: This GitHub Action will automatically add your GitHub Sponsors to your README. It can be configured in multiple ways allowing you to display and breakdown your sponsors by price tier with fallbacks.
Author: James Ives
Latest version: 1.6.0

<p align="center">
  <a href="https://github.com/JamesIves/github-sponsors-readme-action">
    <img width="200px" src="https://github.com/JamesIves/github-sponsors-readme-action/raw/dev/.github/assets/icon.png">
  </a>
</p>

<h1 align="center">
  ✨ GitHub Sponsors Readme Action ✨
</h1>

<p align="center">
  This <a href="https://github.com/features/actions">GitHub Action</a> will automatically add your <a href="https://github.com/sponsors">GitHub Sponsors</a> to your README. It can be configured in multiple ways allowing you to display and breakdown your sponsors by price tier with fallbacks. It also includes templating support so you can display your sponsors how you'd like.
</p>
<p align="center">
 Maintenance of this project is made possible by all the <a href="https://github.com/JamesIves/github-pages-deploy-action/graphs/contributors">contributors</a> and <a href="https://github.com/sponsors/JamesIves">sponsors</a>. If you'd like to sponsor this project and have your avatar or company logo appear below <a href="https://github.com/sponsors/JamesIves">click here</a>. 💖
</p>

<p align="center">
<!-- real-premium --><a href="https://github.com/github"><img src="https:&#x2F;&#x2F;github.com&#x2F;github.png" width="80px" alt="User avatar: github" /></a>&nbsp;&nbsp;<a href="https://github.com/annegentle"><img src="https:&#x2F;&#x2F;github.com&#x2F;annegentle.png" width="80px" alt="User avatar: annegentle" /></a>&nbsp;&nbsp;<a href="https://github.com/tonjohn"><img src="https:&#x2F;&#x2F;github.com&#x2F;tonjohn.png" width="80px" alt="User avatar: tonjohn" /></a>&nbsp;&nbsp;<a href="https://github.com/Zhenglei-BCS"><img src="https:&#x2F;&#x2F;github.com&#x2F;Zhenglei-BCS.png" width="80px" alt="User avatar: Zhenglei-BCS" /></a>&nbsp;&nbsp;<a href="https://github.com/"><img src="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;JamesIves&#x2F;github-sponsors-readme-action&#x2F;dev&#x2F;.github&#x2F;assets&#x2F;placeholder.png" width="80px" alt="User avatar: " /></a>&nbsp;&nbsp;<!-- real-premium -->
</p>

<p align="center">
<!-- real-sponsors --><a href="https://github.com/Chooksta69"><img src="https:&#x2F;&#x2F;github.com&#x2F;Chooksta69.png" width="50px" alt="User avatar: Chooksta69" /></a>&nbsp;&nbsp;<a href="https://github.com/MattWillFlood"><img src="https:&#x2F;&#x2F;github.com&#x2F;MattWillFlood.png" width="50px" alt="User avatar: MattWillFlood" /></a>&nbsp;&nbsp;<a href="https://github.com/jonathan-milan-pollock"><img src="https:&#x2F;&#x2F;github.com&#x2F;jonathan-milan-pollock.png" width="50px" alt="User avatar: jonathan-milan-pollock" /></a>&nbsp;&nbsp;<a href="https://github.com/raoulvdberge"><img src="https:&#x2F;&#x2F;github.com&#x2F;raoulvdberge.png" width="50px" alt="User avatar: raoulvdberge" /></a>&nbsp;&nbsp;<a href="https://github.com/robjtede"><img src="https:&#x2F;&#x2F;github.com&#x2F;robjtede.png" width="50px" alt="User avatar: robjtede" /></a>&nbsp;&nbsp;<a href="https://github.com/hadley"><img src="https:&#x2F;&#x2F;github.com&#x2F;hadley.png" width="50px" alt="User avatar: hadley" /></a>&nbsp;&nbsp;<a href="https://github.com/kevinchalet"><img src="https:&#x2F;&#x2F;github.com&#x2F;kevinchalet.png" width="50px" alt="User avatar: kevinchalet" /></a>&nbsp;&nbsp;<a href="https://github.com/Yousazoe"><img src="https:&#x2F;&#x2F;github.com&#x2F;Yousazoe.png" width="50px" alt="User avatar: Yousazoe" /></a>&nbsp;&nbsp;<a href="https://github.com/planetoftheweb"><img src="https:&#x2F;&#x2F;github.com&#x2F;planetoftheweb.png" width="50px" alt="User avatar: planetoftheweb" /></a>&nbsp;&nbsp;<a href="https://github.com/melton1968"><img src="https:&#x2F;&#x2F;github.com&#x2F;melton1968.png" width="50px" alt="User avatar: melton1968" /></a>&nbsp;&nbsp;<a href="https://github.com/szepeviktor"><img src="https:&#x2F;&#x2F;github.com&#x2F;szepeviktor.png" width="50px" alt="User avatar: szepeviktor" /></a>&nbsp;&nbsp;<a href="https://github.com/sckott"><img src="https:&#x2F;&#x2F;github.com&#x2F;sckott.png" width="50px" alt="User avatar: sckott" /></a>&nbsp;&nbsp;<a href="https://github.com/provinzkraut"><img src="https:&#x2F;&#x2F;github.com&#x2F;provinzkraut.png" width="50px" alt="User avatar: provinzkraut" /></a>&nbsp;&nbsp;<a href="https://github.com/electrovir"><img src="https:&#x2F;&#x2F;github.com&#x2F;electrovir.png" width="50px" alt="User avatar: electrovir" /></a>&nbsp;&nbsp;<a href="https://github.com/Griefed"><img src="https:&#x2F;&#x2F;github.com&#x2F;Griefed.png" width="50px" alt="User avatar: Griefed" /></a>&nbsp;&nbsp;<a href="https://github.com/MontezumaIves"><img src="https:&#x2F;&#x2F;github.com&#x2F;MontezumaIves.png" width="50px" alt="User avatar: MontezumaIves" /></a>&nbsp;&nbsp;<a href="https://github.com/wylie"><img src="https:&#x2F;&#x2F;github.com&#x2F;wylie.png" width="50px" alt="User avatar: wylie" /></a>&nbsp;&nbsp;<a href="https://github.com/pylapp"><img src="https:&#x2F;&#x2F;github.com&#x2F;pylapp.png" width="50px" alt="User avatar: pylapp" /></a>&nbsp;&nbsp;<a href="https://github.com/leoxeno"><img src="https:&#x2F;&#x2F;github.com&#x2F;leoxeno.png" width="50px" alt="User avatar: leoxeno" /></a>&nbsp;&nbsp;<a href="https://github.com/"><img src="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;JamesIves&#x2F;github-sponsors-readme-action&#x2F;dev&#x2F;.github&#x2F;assets&#x2F;placeholder.png" width="50px" alt="User avatar: " /></a>&nbsp;&nbsp;<a href="https://github.com/"><img src="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;JamesIves&#x2F;github-sponsors-readme-action&#x2F;dev&#x2F;.github&#x2F;assets&#x2F;placeholder.png" width="50px" alt="User avatar: " /></a>&nbsp;&nbsp;<!-- real-sponsors -->
</p>

## Getting Started ✈️

You can include the action in your workflow to trigger on any event that [GitHub Actions supports](https://help.github.com/en/articles/events-that-trigger-workflows).

> [!IMPORTANT]
> You'll need to provide the action with a **Personal Access Token (PAT)** scoped to `read:user` and `read:org`.
>
> Additionally, this action only applies the template within the workspace. You will need to combine it with a deployment action in order to commit it to your project. You can see a full example of this below.

```yml
name: Generate Sponsors README
on:
  workflow_dispatch:
  schedule:
    - cron: 30 15 * * 0-6
permissions:
  contents: write
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v2

      - name: Generate Sponsors 💖
        uses: JamesIves/github-sponsors-readme-action@v1
        with:
          token: ${{ secrets.PAT }}
          file: 'README.md'

      # ⚠️ Note: You can use any deployment step here to automatically push the README
      # changes back to your branch.
      - name: Deploy to GitHub Pages 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          branch: main
          folder: '.'
```

You'll also need to add the following `<!-- sponsors --><!-- sponsors -->` in your `.md` file so the action knows where to place the data.

```md
# Awesome Project

Go you!

## Sponsors

These are our really cool sponsors!

<!-- sponsors --><!-- sponsors -->
```

> [!TIP]
> Looking for a more guided walkthrough? [Check out the following article for more details on how to set everything up in your project](https://jamesiv.es/blog/github/actions/2023/06/30/add-your-github-sponsors-to-your-project-readme).

#### Install as a Node Module 📦

If you'd like to use the functionality provided by this action in your own action you can either [create a composite action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action), or you can install it using [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/get-npm) by running the following commands. It's available on both the [npm](https://www.npmjs.com/package/@jamesives/github-sponsors-readme-action) and [GitHub registry](https://github.com/JamesIves/github-sponsors-readme-action/packages/229982).

```
yarn add @jamesives/github-sponsors-readme-action
```

```
npm install @jamesives/github-sponsors-readme-action
```

It can then be imported into your project like so.

```javascript
import run from '@jamesives/github-sponsors-readme-action'

run({
  token: process.env.GITHUB_TOKEN
})
```

Calling the functions directly will require you to pass in an object containing the variables found in the [configuration section](https://github.com/JamesIves/github-sponsors-readme-action#configuration-).

## Configuration 📁

The `with` portion of the workflow **must** be configured before the action will work. You can add these in the `with` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repository's `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets).

#### Required Setup

The following options must be configured.

| Key     | Value Information                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Type   | Required |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `token` | You must provide the action with a Personal Access Token (PAT) with the `read:user` and `read:org` permission scope and store it in the `secrets / with` menu **as a secret**. This should be generated from the account or organization that receives sponsorship, and depending on your use case you may need to provide additional scopes. [Learn more about creating and using encrypted secrets here](https://docs.github.com/en/actions/reference/encrypted-secrets). | `with` | **Yes**  |
| `file`  | This should point to the file that you're generating, for example `README.md` or `path/to/CREDITS.md`. Defaults to `README.md` if no value is provided.                                                                                                                                                                                                                                                                                                                     | `with` | **Yes**  |

#### Optional Choices

| Key               | Value Information                                                                                                                                                                                                                                                 | Type   | Required |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `organization`    | If you're displaying sponsorship information as or for an organization you should toggle this option to `true`. You also need to provide the action with an `read:org` and `read:user` scoped PAT. **Note**: The PAT must belong to an owner of the organization. | `with` | **No**   |
| `minimum`         | Using this input you can set the minimum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and more. By default the action will display all of your sponsors.                                              | `with` | **No**   |
| `maximum`         | Using this input you can set the maximum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and less. By default the action will display all of your sponsors.                                              | `with` | **No**   |
| `marker`          | This allows you to modify the marker comment that is placed in your file. By default this is set to sponsors - `<!-- sponsors --> <!-- sponsors -->`, if you set this to `gold` for example you can place `<!-- gold --> <!-- gold -->` in your file.             | `with` | **No**   |
| `fallback`        | Allows you to specify a fallback if you have no sponsors. By default nothing is displayed.                                                                                                                                                                        | `with` | **No**   |
| `template`        | Allows you to modify the default template. Please refer to the `template` section of this README for more information.                                                                                                                                            | `with` | **No**   |
| `active-only`     | If set to `false`, inactive sponsors will be displayed. This can be useful if you want to display all sponsors, regardless of their status. By default this is set to `true`.                                                                                     | `with` | **No**   |
| `include-private` | If set to `true`, private sponsors will be displayed in the list, however any identifying information will be redacted. This can be useful if you want to display all sponsors, regardless of their privacy settings.                                             | `with` | **No**   |

#### Deployment Status

The action will export a step output as `sponsorship-status` that you can use in your workflow to determine if the task was successful or not. You can find an explanation of each status type below.

| Status    | Description                                                                                             |
| --------- | ------------------------------------------------------------------------------------------------------- |
| `success` | The `success` status indicates that the action was able to successfully generate the README.            |
| `failed`  | The `failed` status indicates that the action encountered an error while trying to generate the README. |
| `skipped` | The `skipped` status indicates that the action could not locate the markers in your .md file.           |
| `running` | The `running` status indicates that the action is actively working.                                     |

---

### Modifying the Template 🔧

You can modify the template that gets generated in your file by using the `template` input. This input allows you to leverage mustache templating to modify what is displayed. The following values are available.

| Status       | Description                                                                                                                                                              |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`       | The users full name. This can sometimes be `null` if the user hasn't set one. This can be accessed using `{{ name }}`                                                    |
| `login`      | The users login, this can be accessed using `{{ login }}`                                                                                                                |
| `url`        | The users GitHub profile url, this can be accessed using `{{ url }}`.                                                                                                    |
| `avatarUrl`  | The users avatar url, this can be accessed using `{{ avatarUrl }}`.                                                                                                      |
| `websiteUrl` | The users website url. This can sometimes be `null` if the user hasn't set one, if so this field will fall back to `url`. This can be accessed using `{{ websiteUrl }}`. |

You're able to use markdown or GitHub approved basic HTML. The default template can be found [here](./src/constants.ts#L38).

<details><summary>You can view a full example of this here.</summary>
<p>

```yml
name: Generate Sponsors README
on:
  push:
    branches:
      - main
permissions:
  contents: write
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v2

      - name: Generate Sponsors 💖
        uses: JamesIves/github-sponsors-readme-action@v1
        with:
          token: ${{ secrets.PAT }}
          file: 'README.md'
          template: '* [{{ name }}]({{ url }}) - {{ login }}'

      - name: Deploy to GitHub Pages 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          branch: main
          folder: '.'
```

```md
# Awesome Project

Go you!

## Sponsors

These are our really cool sponsors!

<!-- sponsors --><!-- sponsors -->
```

</p>
</details>

---

### Separating by Sponsorship Tier ✨

If you'd like to highlight certain users who contribute to a specific sponsorship tier you can do so using a combination of the `minimum`, `maximum` and `marker` inputs. The `minimum / maximum` inputs equal their dollar contribution in cents.

<details><summary>You can view a full example of this here.</summary>
<p>

```yml
name: Generate Sponsors README
on:
  push:
    branches:
      - main
permissions:
  contents: write
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v2

      - name: Generate Sponsors 💖
        uses: JamesIves/github-sponsors-readme-action@v1
        with:
          token: ${{ secrets.PAT }}
          file: 'README.md'
          minimum: 500
          maximum: 999
          marker: 'silver'

      - name: Generate Sponsors 💖
        uses: JamesIves/github-sponsors-readme-action@v1
        with:
          token: ${{ secrets.PAT }}
          file: 'README.md'
          minimum: 1000
          marker: 'gold'

      - name: Deploy to GitHub Pages 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          branch: main
          folder: '.'
```

```md
# Awesome Project

Go you!

## Gold Sponsors

<!-- gold -->
<!-- gold -->

## Silver Sponsors

<!-- silver -->
<!-- silver -->
```

</p>
</details>