Skip to content

Commit 90843d3

Browse files
committed
Update README
1 parent 90ad96b commit 90843d3

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PUL
8181

8282
If there are files or directories you want to ignore you can simply add them to a `.gitignore` file at the root of your repository. The action will respect this file.
8383

84-
## Example
84+
## Examples
8585

8686
Here is an example that sets all the main environment variables.
8787

@@ -102,10 +102,10 @@ jobs:
102102
env:
103103
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104104
COMMIT_MESSAGE: Add report file
105+
PULL_REQUEST_TITLE: '[Example] Add report file'
105106
PULL_REQUEST_BODY: >
106107
This PR is auto-generated by
107108
[create-pull-request](https://github.com/peter-evans/create-pull-request).
108-
PULL_REQUEST_TITLE: '[Example] Add report file'
109109
PULL_REQUEST_LABELS: report, automated pr
110110
PULL_REQUEST_ASSIGNEES: peter-evans
111111
PULL_REQUEST_REVIEWERS: peter-evans
@@ -120,6 +120,41 @@ This configuration will create pull requests that look like this:
120120

121121
![Pull Request Example](https://github.com/peter-evans/create-pull-request/blob/master/pull-request-example.png?raw=true)
122122

123+
### Dynamic configuration using variables
124+
125+
The following examples show how configuration for the action can be dynamically defined in a previous workflow step.
126+
127+
The recommended method is to use `set-output`. Note that the step where output variables are defined must have an id.
128+
129+
```yml
130+
- name: Set output variables
131+
id: vars
132+
run: |
133+
echo ::set-output name=pr_title::"[Test] Add report file $(date +%d-%m-%Y)"
134+
echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \
135+
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
136+
- name: Create Pull Request
137+
uses: peter-evans/[email protected]
138+
env:
139+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140+
PULL_REQUEST_TITLE: ${{ steps.vars.outputs.pr_title }}
141+
PULL_REQUEST_BODY: ${{ steps.vars.outputs.pr_body }}
142+
```
143+
144+
Since the action reads environment variables from the system, it's technically not necessary to explicitly pass them as long as they exist in the environment. So the following method using `set-env` *also* works, but explicitly passing the configuration parameters using the previous method is perferred for its clarity.
145+
146+
```yml
147+
- name: Set environment variables
148+
run: |
149+
echo ::set-env name=PULL_REQUEST_TITLE::"[Test] Add report file $(date +%d-%m-%Y)"
150+
echo ::set-env name=PULL_REQUEST_BODY::"This PR was auto-generated on $(date +%d-%m-%Y) \
151+
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
152+
- name: Create Pull Request
153+
uses: peter-evans/[email protected]
154+
env:
155+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156+
```
157+
123158
## License
124159

125160
[MIT](LICENSE)

0 commit comments

Comments
 (0)