nmfs-fish-tools / ghactions4r

Reusable github actions workflows for R packages
https://nmfs-fish-tools.github.io/ghactions4r/
12 stars 1 forks source link

feat: add option for PAT to style-and-doc-r.yml #89

Closed k-doering-NOAA closed 1 year ago

k-doering-NOAA commented 1 year ago

Addresses #85 . Add ability to add a PAT to the doc-and-style-r workflows, which would allow pull requests or commits created by the run to trigger new github action runs (without a PAT, no github action runs will be started by pull requests or commits created).

No breaking changes to existing functionality.

Passing in a token can be done by using a workflow like:

# document and style using reusable workflow
# This workflow runs devtools::document and styler::style_active_package(), then opens a pull request to the branch
# That started the workflow with the changes
name: call-doc-and-style-r
# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
  push:
    branches: [main, master]
jobs:
  call-workflow:
    uses: nmfs-fish-tools/ghactions4r/.github/workflows/doc-and-style-r.yml@main
    # note a PAT can trigger recursive runs, so should be used with caution. See github documentation for more info:
    # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
    # Need to add a personal access token as a secret to your github repository.
    # can change secrets.API to a different 
    # secret name if it is named differently in the repository.
    secrets:
      PAT: ${{ secrets.PAT }}

as comments in the example workflow show, care must be taken to not cause recursive runs when using a PAT.

This was tested using the branch: https://github.com/nmfs-fish-tools/ghactions4r/tree/feat-pat-style-doc

I tested:

Committing directly with a PAT likely results in recursive runs, so shouldn't be used.

Additional testing will be done on opening a PR with a PAT for use in https://github.com/noaa-fims/fims