Skip to content

A GitHub Action that sets bot secrets as git defaults if present

License

Notifications You must be signed in to change notification settings

devlooped/actions-bot

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

🤖 defaults

A GitHub action that sets git defaults (name, email, author) for automated bot workflows from secrets or environment variables.

Also defaults GH_TOKEN to GITHUB_TOKEN if empty.

Usage

- name: 🤖 defaults
  uses: devlooped/actions-bot@v1
  with:
    # The default name of the bot account. 
    # Defaults to $GITHUB_ACTOR.
    # Set as $BOT_NAME environment variable after run, and as bot-name output.
    name: ''

    # The default email of the bot account. 
    # Defaults to [email protected].
    # Set as $BOT_EMAIL environment variable after run, and as bot-email output.
    email: ''

    # The token to set as $GH_TOKEN environment variable. If empty, 
    # uses the github_token input as a fallback.
    # Defaults to ''. Typically set to ${{ secrets.GH_TOKEN }}.
    # Set as $GH_TOKEN and BOT_TOKEN environment variables after run, 
    # and as bot-token output.
    gh_token: ''

    # Fallback token to use for $GH_TOKEN if it's empty.
    # Defaults to ''. Typically set to ${{ secrets.GITHUB_TOKEN }}.
    github_token: ''

If both gh_token and github_token have empty values, the action will fail.

The additional BOT_AUTHOR environment variable is set to "$BOT_NAME <$BOT_EMAIL>" as well as the bot-author output for easy consumption.

The action also runs:

git config --global user.name $BOT_NAME
git config --global user.email $BOT_EMAIL

so that git commands can be run with the resulting defaults already applied.

Example

To run the action and automatically create a PR with the resolved bot defaults:

on: 
  push:
    branches:
      - main

jobs:
  includes:
    runs-on: ubuntu-latest
    steps:
      - name: 🤖 defaults
        uses: devlooped/actions-bot@v1
        with:
          name: ${{ secrets.BOT_NAME }}
          email: ${{ secrets.BOT_EMAIL }}
          gh_token: ${{ secrets.GH_TOKEN }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: 🤘 checkout
        uses: actions/checkout@v2
        with:
          token: ${{ env.GH_TOKEN }}

      # add some step that changes files

      - name: ✍ pull request
        uses: peter-evans/create-pull-request@v3
        with:
          base: main
          branch: bot-updates
          author: ${{ env.BOT_AUTHOR }}
          committer: ${{ env.BOT_AUTHOR }}
          commit-message: ⬆️ Bot file updates
          title: ⬆️ Bot file updates
          body: Updates made by @${{ env.BOT_NAME }}.
          token: ${{ env.GH_TOKEN }}

In a repository that doesn't define any of the custom secrets passed to the devlooped/actions-bot@v1 action, all environment variables will be properly defaulted, since at least ${{ secrets.GITHUB_TOKEN }} will be present, as well as the $GITHUB_ACTOR which is used to default BOT_NAME, BOT_EMAIL and BOT_AUTHOR.

It would also be possible to just run git commands from a shell and get the same defaults automatically.

Sponsors

Clarius Org Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. David Kean Daniel Gnägi Ashley Medway Keith Pickford bitbonk Thomas Bolon Yurii Rashkovskii Kori Francis Zdenek Havlin Sean Killeen Toni Wenzel Giorgi Dalakishvili Kelly White Allan Ritchie Mike James Uno Platform Dan Siegel Reuben Swartz Jeremy Simmons Jacob Foshee Eric Johnson Norman Mackay Certify The Web Taylor Mansfield Mårten Rånge David Petric Rich Lee Danilo das Neves Dantas Gary Woodfine Steve Bilogan Ix Technologies B.V. New Relic Chris Johnston‮ David JENNI Jonathan Oleg Kyrylchuk Juan Blanco LosManos Mariusz Kogut Charley Wu Thomas Due Jakob Tikjøb Andersen Seann Alexander Tino Hager Badre BSAILA Mark Seemann Angelo Belchior Tony Qu Daniel May Blauhaus Technology (Pty) Ltd Richard Collette Nick Vaughan Ken Bonny Simon Cropp

Sponsor this project  

Learn more about GitHub Sponsors

About

A GitHub Action that sets bot secrets as git defaults if present

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published