Merge pull request #28 from vsoch/add/outputs
First test to add outputs
This commit is contained in:
@@ -14,5 +14,6 @@ represented by the pull requests that fixed them. Critical items to know are:
|
|||||||
Versions correspond with GitHub releases that can be referenced with @ using actions.
|
Versions correspond with GitHub releases that can be referenced with @ using actions.
|
||||||
|
|
||||||
## [master](https://github.com/vsoch/pull-request-action/tree/master) (master)
|
## [master](https://github.com/vsoch/pull-request-action/tree/master) (master)
|
||||||
|
- output and environment variables for PR number and return codes (1.0.5)
|
||||||
- added support for reviewer (individual and team) assignments (1.0.4)
|
- added support for reviewer (individual and team) assignments (1.0.4)
|
||||||
- added support for maintainer can modify and assignees (1.0.3)
|
- added support for maintainer can modify and assignees (1.0.3)
|
||||||
|
|||||||
27
README.md
27
README.md
@@ -22,14 +22,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: pull-request-action
|
- name: pull-request-action
|
||||||
uses: vsoch/pull-request-action@1.0.2
|
uses: vsoch/pull-request-action@1.0.5
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
BRANCH_PREFIX: "update/"
|
BRANCH_PREFIX: "update/"
|
||||||
PULL_REQUEST_BRANCH: "master"
|
PULL_REQUEST_BRANCH: "master"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variable Inputs
|
||||||
|
|
||||||
Unlike standard actions, this action just uses variables from the environment.
|
Unlike standard actions, this action just uses variables from the environment.
|
||||||
|
|
||||||
@@ -60,6 +60,27 @@ an issue or PR, they are ignored otherwise.
|
|||||||
The `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open
|
The `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open
|
||||||
the pull request. The example is [deployed here](https://github.com/vsoch/pull-request-action-example) with an example opened (and merged) [pull request here](https://github.com/vsoch/pull-request-action-example/pull/1) if needed.
|
the pull request. The example is [deployed here](https://github.com/vsoch/pull-request-action-example) with an example opened (and merged) [pull request here](https://github.com/vsoch/pull-request-action-example/pull/1) if needed.
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
The action sets a few useful output and environment variables. An output can
|
||||||
|
be referenced later as `${{ steps.<stepname>.outputs.<output-name> }}`.
|
||||||
|
An environment variable of course can be referenced as you usually would.
|
||||||
|
|
||||||
|
| Name | Description | Environment |
|
||||||
|
|------|-------------|-------------|
|
||||||
|
| pull_request_number |If the pull request is opened, this is the number for it. | PULL_REQUEST_NUMBER |
|
||||||
|
| pull_request_url |If the pull request is opened, the html url for it. | PULL_REQUEST_URL |
|
||||||
|
| pull_request_return_code | Return code for the pull request | PULL_REQUEST_RETURN_CODE |
|
||||||
|
| assignees_return_code | Return code for the assignees request | ASSIGNEES_RETURN_CODE |
|
||||||
|
| reviewers_return_code | Return code for the reviewers request | REVIEWERS_RETURN_CODE |
|
||||||
|
|
||||||
|
See the [examples/outputs-example.yml](examples/outputs-example.yml) for how this works.
|
||||||
|
In this example, we can reference `${{ steps.pull_request.outputs.pull_request_url }}`
|
||||||
|
in either another environment variable declaration, or within a run statement to access
|
||||||
|
our variable `pull_request_url` that was generated in a step with id `pull_request`.
|
||||||
|
The screenshot below shows the example in action to interact with outputs in several ways.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -85,7 +106,7 @@ jobs:
|
|||||||
PR_BRANCH_FROM=release-v$(cat VERSION)
|
PR_BRANCH_FROM=release-v$(cat VERSION)
|
||||||
::set-env name=PULL_REQUEST_FROM_BRANCH::${PR_BRANCH_FROM}
|
::set-env name=PULL_REQUEST_FROM_BRANCH::${PR_BRANCH_FROM}
|
||||||
- name: pull-request-action
|
- name: pull-request-action
|
||||||
uses: vsoch/pull-request-action@1.0.2
|
uses: vsoch/pull-request-action@1.0.5
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
PULL_REQUEST_BRANCH: "master"
|
PULL_REQUEST_BRANCH: "master"
|
||||||
|
|||||||
11
action.yml
11
action.yml
@@ -7,3 +7,14 @@ runs:
|
|||||||
branding:
|
branding:
|
||||||
icon: 'activity'
|
icon: 'activity'
|
||||||
color: 'yellow'
|
color: 'yellow'
|
||||||
|
outputs:
|
||||||
|
pull_request_number:
|
||||||
|
description: 'If the pull request is opened, this is the number for it.'
|
||||||
|
pull_request_url:
|
||||||
|
description: 'If the pull request is opened, the html url for it.'
|
||||||
|
pull_request_return_code:
|
||||||
|
description: 'The pull request return code.'
|
||||||
|
assignees_return_code:
|
||||||
|
description: 'The add assignees post return code.'
|
||||||
|
reviewers_return_code:
|
||||||
|
description: 'The add reviewers post return code.'
|
||||||
|
|||||||
28
examples/outputs-example.yml
Normal file
28
examples/outputs-example.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: Pull Request on Branch Push
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- devel
|
||||||
|
jobs:
|
||||||
|
auto-pull-request:
|
||||||
|
name: PullRequestAction
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: pull-request-action
|
||||||
|
id: pull_request
|
||||||
|
uses: vsoch/pull-request-action@1.0.5
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
BRANCH_PREFIX: "update/"
|
||||||
|
PULL_REQUEST_BRANCH: "master"
|
||||||
|
PULL_REQUEST_REVIEWERS: vsoch
|
||||||
|
- name: Test outputs
|
||||||
|
env:
|
||||||
|
pull_request_number_output: ${{ steps.pull_request.outputs.pull_request_number }}
|
||||||
|
pull_request_url_output: ${{ steps.pull_request.outputs.pull_request_url }}
|
||||||
|
run: |
|
||||||
|
echo "Pull request number from output: ${pull_request_number_output}"
|
||||||
|
echo "Pull request url from output: ${pull_request_url_output}"
|
||||||
|
echo "Pull request number from environment: ${PULL_REQUEST_NUMBER}"
|
||||||
|
echo "Pull request url from environment: ${PULL_REQUEST_URL}"
|
||||||
|
echo "Another way to specify from output ${{ steps.pull_request.outputs.pull_request_number }}"
|
||||||
BIN
img/outputs.png
Normal file
BIN
img/outputs.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -82,6 +82,14 @@ create_pull_request() {
|
|||||||
|
|
||||||
NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number')
|
NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number')
|
||||||
printf "Number opened for PR is ${NUMBER}\n"
|
printf "Number opened for PR is ${NUMBER}\n"
|
||||||
|
HTML_URL=$(echo "${RESPONSE}" | jq --raw-output '.html_url')
|
||||||
|
|
||||||
|
echo ::set-env name=PULL_REQUEST_NUMBER::${NUMBER}
|
||||||
|
echo ::set-output name=pull_request_number::${NUMBER}
|
||||||
|
echo ::set-env name=PULL_REQUEST_RETURN_CODE::${RETVAL}
|
||||||
|
echo ::set-output name=pull_request_return_code::${RETVAL}
|
||||||
|
echo ::set-env name=PULL_REQUEST_URL::${HTML_URL}
|
||||||
|
echo ::set-output name=pull_request_url::${HTML_URL}
|
||||||
|
|
||||||
# Assignees are defined
|
# Assignees are defined
|
||||||
if [[ "$ASSIGNEES" != '""' ]]; then
|
if [[ "$ASSIGNEES" != '""' ]]; then
|
||||||
@@ -98,7 +106,11 @@ create_pull_request() {
|
|||||||
echo "${DATA}"
|
echo "${DATA}"
|
||||||
ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees"
|
ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees"
|
||||||
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL}
|
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL}
|
||||||
printf "$?\n"
|
RETVAL=$?
|
||||||
|
printf "Add assignees return code: ${RETVAL}\n"
|
||||||
|
echo ::set-env name=ASSIGNEES_RETURN_CODE::${RETVAL}
|
||||||
|
echo ::set-output name=assignees_return_code::${RETVAL}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reviewers or team reviewers are defined
|
# Reviewers or team reviewers are defined
|
||||||
@@ -120,7 +132,11 @@ create_pull_request() {
|
|||||||
DATA="{\"reviewers\":[${REVIEWERS}], \"team_reviewers\":[${TEAM_REVIEWERS}]}"
|
DATA="{\"reviewers\":[${REVIEWERS}], \"team_reviewers\":[${TEAM_REVIEWERS}]}"
|
||||||
echo "${DATA}"
|
echo "${DATA}"
|
||||||
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${REVIEWERS_URL}
|
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${REVIEWERS_URL}
|
||||||
printf "$?\n"
|
|
||||||
|
RETVAL=$?
|
||||||
|
printf "Add reviewers return code: ${RETVAL}\n"
|
||||||
|
echo ::set-env name=REVIEWERS_RETURN_CODE::${RETVAL}
|
||||||
|
echo ::set-output name=reviewers_return_code::${RETVAL}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user