Skip to content

Commit

Permalink
Add the option to customize working directory and add PR outputs (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhenry authored Aug 26, 2022
1 parent 81a5372 commit 8f3fe2b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,33 @@ jobs:
### Action inputs
<!-- BEGIN_ACTION_INPUT_TABLE -->
| NAME | DESCRIPTION | REQUIRED | DEFAULT |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------------------------------------------------------------|
| `author` | The author name and email address in the format Display Name <[email protected]>. Defaults to the user who triggered the workflow run. | `false` | `${{github.actor}} <${{github.actor}}@users.noreply.github.com>` |
| `commit-message` | The message to use when committing changes. | `false` | `[bot] Bump ${{github.event.repository.name}}` |
| `committer` | The committer name and email address in the format Display Name <[email protected]>. Defaults to the GitHub Actions bot user. | `false` | `GitHub <[email protected]>` |
| `labels` | A comma or newline-separated list of labels. | `false` | `bot` |
| `relevance-filter` | A path filter used to determine if any relevant files where changed as a result of the `update-command`. By default, all changes are considered relevant. | `false` | `- '**'` |
| `repository` | The downstream repository that consumes the library dependency. | `true` | `N/A` |
| `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | `false` | `N/A` |
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. | `false` | `N/A` |
| `title` | The title of the pull request. | `false` | `[bot] Bump ${{github.event.repository.name}}` |
| `token` | Github PAT used to open PRs. This token must have write access against the repository. | `true` | `N/A` |
| `update-command` | The command run from the downstream repo that is used to update the library dependency. | `true` | `N/A` |
| NAME | DESCRIPTION | REQUIRED | DEFAULT |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------------------------------------------------------------|
| `author` | The author name and email address in the format Display Name <[email protected]>. Defaults to the user who triggered the workflow run. | `false` | `${{github.actor}} <${{github.actor}}@users.noreply.github.com>` |
| `commit-message` | The message to use when committing changes. | `false` | `[bot] Bump ${{github.event.repository.name}}` |
| `committer` | The committer name and email address in the format Display Name <[email protected]>. Defaults to the GitHub Actions bot user. | `false` | `GitHub <[email protected]>` |
| `labels` | A comma or newline-separated list of labels. | `false` | `bot` |
| `relevance-filter` | A path filter used to determine if any relevant files where changed as a result of the `update-command`. By default, all changes are considered relevant. | `false` | `- '**'` |
| `repository` | The downstream repository that consumes the library dependency. | `true` | `N/A` |
| `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | `false` | `N/A` |
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. | `false` | `N/A` |
| `title` | The title of the pull request. | `false` | `[bot] Bump ${{github.event.repository.name}}` |
| `token` | Github PAT used to open PRs. This token must have write access against the repository. | `true` | `N/A` |
| `update-command` | The command run from the downstream repo that is used to update the library dependency. | `true` | `N/A` |
| `working-directory` | The relative directory in the downstream repo where all commands will run. | `false` | `N/A` |
<!-- END_ACTION_INPUT_TABLE -->

### Action outputs

<!-- BEGIN_ACTION_OUTPUT_TABLE -->
| NAME | DESCRIPTION |
|--------------------------|---------------------------------------------------------------------------------------|
| `pull-request-head-sha` | The commit SHA of the pull request branch. |
| `pull-request-number` | The pull request number |
| `pull-request-operation` | The pull request operation performed by the action, `created`, `updated` or `closed`. |
| `pull-request-url` | The URL of the pull request. |
<!-- END_ACTION_OUTPUT_TABLE -->

## Development

If you change or add an input, use `./scripts/update-readme.sh` to keep the above **Action inputs** table up to date.
Expand Down
38 changes: 34 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
update-command:
required: true
description: The command run from the downstream repo that is used to update the library dependency.
working-directory:
required: false
default: ""
description: The relative directory in the downstream repo where all commands will run.
relevance-filter:
required: false
default: "- '**'"
Expand Down Expand Up @@ -41,6 +45,20 @@ inputs:
description: A comma or newline-separated list of labels.
default: bot

outputs:
pull-request-number:
description: "The pull request number"
value: ${{steps.create-pr.outputs.pull-request-number}}
pull-request-url:
description: "The URL of the pull request."
value: ${{steps.create-pr.outputs.pull-request-url}}
pull-request-operation:
description: "The pull request operation performed by the action, `created`, `updated` or `closed`."
value: ${{steps.create-pr.outputs.pull-request-description}}
pull-request-head-sha:
description: "The commit SHA of the pull request branch."
value: ${{steps.create-pr.outputs.pull-request-head-sha}}

runs:
using: composite
steps:
Expand All @@ -51,11 +69,22 @@ runs:
token: ${{inputs.token}}
path: ${{inputs.repository}}

- name: Set working directory
shell: bash
id: working-dir
run: |
if [ -z "${{inputs.working-directory}}" ]
then
echo "::set-output name=dir::${{inputs.repository}}"
else
echo "::set-output name=dir::${{inputs.repository}}/${{inputs.working-directory}}"
fi
- uses: actions/setup-go@v3
with:
go-version-file: ${{inputs.repository}}/go.mod
go-version-file: ${{steps.working-dir.outputs.dir}}/go.mod
cache: true
cache-dependency-path: ${{inputs.repository}}/go.sum
cache-dependency-path: ${{steps.working-dir.outputs.dir}}/go.sum

- name: Setup git
shell: bash
Expand All @@ -64,15 +93,15 @@ runs:
- name: Run update command
shell: bash
working-directory: ${{inputs.repository}}
working-directory: ${{steps.working-dir.outputs.dir}}
run: ${{inputs.update-command}}

# If the only files that changed are go.mod, go.sum, and vendor/modules.txt, then it's not worth a PR.
- name: Check if relevant files were changed
uses: dorny/[email protected]
id: changes
with:
working-directory: ${{inputs.repository}}
working-directory: ${{steps.working-dir.outputs.dir}}
base: HEAD
filters: |
relevant:
Expand All @@ -81,6 +110,7 @@ runs:
- name: Create pull request
if: steps.changes.outputs.relevant == 'true'
uses: peter-evans/[email protected]
id: create-pr
with:
branch: bump-${{github.repository}}/patch
path: ${{inputs.repository}}
Expand Down
7 changes: 5 additions & 2 deletions scripts/update-readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if ! (command -v describe-action >/dev/null 2>&1) ; then
fi

PWD=$(cd "$(dirname "$0")" && pwd -P)
export NEW_TABLE=$(describe-action --input --yaml ${PWD}/../action.yml)
export INPUT_TABLE=$(describe-action --input --yaml ${PWD}/../action.yml)
export OUTPUT_TABLE=$(describe-action --output --yaml ${PWD}/../action.yml)

perl -i -0pe "s#<!-- BEGIN_ACTION_INPUT_TABLE -->.*<!-- END_ACTION_INPUT_TABLE -->#<!-- BEGIN_ACTION_INPUT_TABLE -->\n\$ENV{NEW_TABLE}\n<!-- END_ACTION_INPUT_TABLE -->#smg" "${PWD}/../README.md"
perl -i -0pe "s#<!-- BEGIN_ACTION_INPUT_TABLE -->.*<!-- END_ACTION_INPUT_TABLE -->#<!-- BEGIN_ACTION_INPUT_TABLE -->\n\$ENV{INPUT_TABLE}\n<!-- END_ACTION_INPUT_TABLE -->#smg" "${PWD}/../README.md"

perl -i -0pe "s#<!-- BEGIN_ACTION_OUTPUT_TABLE -->.*<!-- END_ACTION_OUTPUT_TABLE -->#<!-- BEGIN_ACTION_OUTPUT_TABLE -->\n\$ENV{OUTPUT_TABLE}\n<!-- END_ACTION_OUTPUT_TABLE -->#smg" "${PWD}/../README.md"

0 comments on commit 8f3fe2b

Please sign in to comment.