Compare commits

..

41 Commits

Author SHA1 Message Date
82c423c73b Merge pull request #508 from peter-evans/update-distribution
Update distribution
2020-08-19 17:40:53 +09:00
7cf22579c6 Update distribution 2020-08-19 08:39:31 +00:00
5893420513 Merge pull request #503 from peter-evans/not-updated-fix
Fix pr create/update for already up to date branches
2020-08-19 17:37:01 +09:00
8bdec9b230 Fix pr create/update for already up to date branches 2020-08-19 17:08:59 +09:00
2570a753e0 Merge pull request #497 from peter-evans/branch-check-fix
Fix branch naming check for push-to-fork
2020-08-19 14:27:34 +09:00
1c466bedd5 Fix branch naming check for push-to-fork 2020-08-19 12:22:50 +09:00
a755ad5ffb Merge pull request #492 from peter-evans/update-distribution
Update distribution
2020-08-19 12:21:35 +09:00
52cabd40b9 Update distribution 2020-08-19 03:20:28 +00:00
12b7e7a141 Merge pull request #467 from peter-evans/update-dependencies
Update dependencies
2020-08-19 12:18:09 +09:00
8f96fd0252 Merge pull request #488 from jsoref/spelling
Spelling
2020-08-19 12:09:20 +09:00
5f45e30ff9 spelling: uncommitted
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-08-18 12:51:12 -04:00
348abed1de spelling: javascript
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-08-17 23:27:12 -04:00
06ab0ad94e Update documentation 2020-08-16 13:34:15 +09:00
de6e791e81 Update documentation 2020-08-15 14:21:58 +09:00
184bc2eccd Update documentation 2020-08-14 11:08:04 +09:00
4dab765cf5 Update dependencies 2020-08-13 01:09:37 +00:00
329417f094 Update documentation 2020-08-04 22:02:58 +09:00
7311df63a5 Update documentation 2020-08-04 15:44:58 +09:00
47a0e6b298 Update documentation 2020-08-04 14:27:36 +09:00
9b02473bb0 Update documentation 2020-08-04 14:20:01 +09:00
40b1b245eb Merge pull request #477 from peter-evans/dev
signoff
2020-07-31 18:08:02 +09:00
64c8d492d5 Update documentation 2020-07-31 16:59:26 +09:00
28fddffcf8 Add test for signoff 2020-07-31 16:57:41 +09:00
ba8309ff9c Refactor setting commit params 2020-07-31 16:57:16 +09:00
ee482f51bd Move input next to commit related inputs for context 2020-07-31 16:56:10 +09:00
bf7dd38b26 Merge pull request #476 from pvogt09/master
Adds option to signoff commits
2020-07-31 15:12:43 +09:00
71a37c5c33 Update documentation 2020-07-31 10:24:31 +09:00
f9af0fbfc0 Merge pull request #3 from pvogt09/update-distribution
Update distribution
2020-07-30 17:18:52 +02:00
0c57887fe8 Update distribution 2020-07-30 15:18:17 +00:00
7ad9f6e012 try -s instead of --signoff
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 16:23:22 +02:00
dd364f2835 adds argument to test cases
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 16:06:07 +02:00
ddd52205b6 adds signoff option to sign off commits
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 15:57:37 +02:00
a81d0faef6 Merge pull request #470 from peter-evans/rem-dep
Remove unnecessary dependency
2020-07-30 12:26:57 +09:00
fc03a820b2 Remove unnecessary dependency 2020-07-30 12:16:48 +09:00
b2cdf099d0 Update ci workflow 2020-07-25 14:02:46 +09:00
f3d08d3f0b Update slash-command-dispatch to v2 2020-07-25 13:23:29 +09:00
3a21b8d668 Update slash-command-dispatch to v2-beta 2020-07-25 12:53:35 +09:00
132b02c8e1 Merge pull request #455 from peter-evans/lodash-vuln
Update lodash to fix vuln
2020-07-23 17:18:11 +09:00
9507cdc7ac Update lodash to fix vuln 2020-07-23 17:06:02 +09:00
f4bf0d40c3 Update workflows to v3 2020-07-23 16:20:49 +09:00
cf325ed84b Update example screenshot 2020-07-23 15:37:47 +09:00
18 changed files with 2977 additions and 6746 deletions

View File

@ -113,17 +113,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: rm -rf dist
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update distribution
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: Update distribution
body: |
- Updates the distribution for changes on `master`

View File

@ -18,6 +18,7 @@ jobs:
commit-message: Update report
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
title: '[Example] Update report'
body: |
Update report

View File

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
config: >

View File

@ -15,7 +15,7 @@ jobs:
npx -p npm-check-updates ncu -u
npm install
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: Update dependencies

View File

@ -36,27 +36,28 @@ You can also pin to a [specific release](https://github.com/peter-evans/create-p
All inputs are **optional**. If not set, sensible defaults will be used.
**Note**: If you want pull requests created by this action to trigger an `on: push` or `on: pull_request` workflow then you cannot use the default `GITHUB_TOKEN`. See the [documentation here](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) for workarounds.
**Note**: If you want pull requests created by this action to trigger an `on: push` or `on: pull_request` workflow then you cannot use the default `GITHUB_TOKEN`. See the [documentation here](docs/concepts-guidelines.md#triggering-further-workflow-runs) for workarounds.
| Name | Description | Default |
| --- | --- | --- |
| `token` | `GITHUB_TOKEN` or a `repo` scoped [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | `GITHUB_TOKEN` |
| `token` | `GITHUB_TOKEN` or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
| `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` |
| `committer` | The committer name and email address in the format `Display Name <email@address.com>`. Defaults to the GitHub Actions bot user. | `GitHub <noreply@github.com>` |
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
| `signoff` | Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. | `false` |
| `branch` | The pull request branch name. | `create-pull-request/patch` |
| `branch-suffix` | The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Alternative strategy](#alternative-strategy---always-create-a-new-pull-request-branch) for details. | |
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
| `push-to-fork` | A fork of the checked out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
| `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
| `title` | The title of the pull request. | `Changes by create-pull-request action` |
| `body` | The body of the pull request. | `Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action` |
| `labels` | A comma or newline separated list of labels. | |
| `assignees` | A comma or newline separated list of assignees (GitHub usernames). | |
| `reviewers` | A comma or newline separated list of reviewers (GitHub usernames) to request a review from. | |
| `team-reviewers` | A comma or newline separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | |
| `labels` | A comma or newline-separated list of labels. | |
| `assignees` | A comma or newline-separated list of assignees (GitHub usernames). | |
| `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | |
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | |
| `milestone` | The number of the milestone to associate this pull request with. | |
| `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
| `draft` | Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
### Action outputs
@ -91,8 +92,8 @@ Any subsequent changes will be committed to the *same* branch and reflected in t
How the action behaves:
- If there are changes (i.e. a diff exists with the checked out base branch), the changes will be pushed to a new `branch` and a pull request created.
- If there are no changes (i.e. no diff exists with the checked out base branch), no pull request will be created and the action exits silently.
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
- If a pull request already exists and there are no further changes (i.e. no diff with the current pull request branch) then the action exits silently.
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the base and pull request branch), the pull request is automatically closed and the branch deleted.
@ -156,7 +157,7 @@ To create a project card for the pull request, pass the `pull-request-number` st
## Reference Example
The following workflow is a reference example that sets all the main inputs.
The following workflow is a reference example that sets many of the main inputs.
See [examples](docs/examples.md) for more realistic use cases.
@ -180,6 +181,7 @@ jobs:
commit-message: Update report
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: example-patches
title: '[Example] Update report'
body: |

View File

@ -200,7 +200,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -215,7 +216,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -241,7 +243,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -260,7 +263,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -286,7 +290,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -307,7 +312,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -334,9 +340,10 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('none')
expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(changes.untracked)
expect(
@ -353,7 +360,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -388,7 +396,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -417,7 +426,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -443,7 +453,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -462,7 +473,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -500,7 +512,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -520,7 +533,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -549,7 +563,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -573,7 +588,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -606,7 +622,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -632,7 +649,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -673,7 +691,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -698,7 +717,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
'',
BRANCH,
FORK_REMOTE_NAME
FORK_REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -725,7 +745,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
'',
BRANCH,
FORK_REMOTE_NAME
FORK_REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -736,6 +757,69 @@ describe('create-or-update-branch tests', () => {
).toBeTruthy()
})
it('tests create and update with signoff on commit', async () => {
// Create tracked and untracked file changes
const changes = await createChanges()
const commitMessage = uuidv4()
const result = await createOrUpdateBranch(
git,
commitMessage,
'',
BRANCH,
REMOTE_NAME,
true
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(changes.untracked)
expect(
await gitLogMatches([commitMessage, INIT_COMMIT_MESSAGE])
).toBeTruthy()
// Check signoff in commit body
const commitBody = (
await git.exec(['log', `-1`, '--format=%b'])
).stdout.trim()
expect(commitBody).toEqual(
'Signed-off-by: Committer Name <committer@example.com>'
)
// Push pull request branch to remote
await git.push([
'--force-with-lease',
REMOTE_NAME,
`HEAD:refs/heads/${BRANCH}`
])
await afterTest(false)
await beforeTest()
// Create tracked and untracked file changes
const _changes = await createChanges()
const _commitMessage = uuidv4()
const _result = await createOrUpdateBranch(
git,
_commitMessage,
'',
BRANCH,
REMOTE_NAME,
true
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
expect(await getFileContent(TRACKED_FILE)).toEqual(_changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(_changes.untracked)
expect(
await gitLogMatches([_commitMessage, INIT_COMMIT_MESSAGE])
).toBeTruthy()
// Check signoff in commit body
const _commitBody = (
await git.exec(['log', `-1`, '--format=%b'])
).stdout.trim()
expect(_commitBody).toEqual(
'Signed-off-by: Committer Name <committer@example.com>'
)
})
// Working Base is Not Base (WBNB)
it('tests no changes resulting in no new branch being created (WBNB)', async () => {
@ -748,7 +832,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -766,7 +851,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -795,7 +881,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -817,7 +904,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -846,7 +934,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -870,7 +959,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -900,9 +990,10 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('none')
expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(changes.untracked)
expect(
@ -922,7 +1013,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -960,7 +1052,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -992,7 +1085,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1021,7 +1115,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -1045,7 +1140,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1086,7 +1182,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -1109,7 +1206,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -1141,7 +1239,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1168,7 +1267,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1204,7 +1304,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1233,7 +1334,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1277,7 +1379,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
REMOTE_NAME
REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1305,7 +1408,8 @@ describe('create-or-update-branch tests', () => {
commitMessage,
BASE,
BRANCH,
FORK_REMOTE_NAME
FORK_REMOTE_NAME,
false
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1335,7 +1439,8 @@ describe('create-or-update-branch tests', () => {
_commitMessage,
BASE,
BRANCH,
FORK_REMOTE_NAME
FORK_REMOTE_NAME,
false
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()

View File

@ -21,6 +21,9 @@ inputs:
The author name and email address in the format `Display Name <email@address.com>`.
Defaults to the user who triggered the workflow run.
default: '${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>'
signoff:
description: 'Add `Signed-off-by` line by the committer at the end of the commit log message.'
default: false
branch:
description: 'The pull request branch name.'
default: 'create-pull-request/patch'

5206
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
master.commit("Last commit on base");
const localMaster = gitgraph.branch("<#1> master (local)");
localMaster.commit({
subject: "<uncommited changes>",
subject: "<uncommitted changes>",
body: "Changes made to the local base during the workflow",
})
const remotePatch = gitgraph.branch("create-pull-request/patch");
@ -48,7 +48,7 @@
const localMaster2 = gitgraph.branch("<#2> master (local)");
localMaster2.commit({
subject: "<uncommited changes>",
subject: "<uncommitted changes>",
body: "Changes made to the updated local base during the workflow",
})
remotePatch.merge({

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 327 KiB

View File

@ -8,7 +8,7 @@ This document covers terminology, how the action works, general usage guidelines
- [Guidelines](#guidelines)
- [Providing a consistent base](#providing-a-consistent-base)
- [Pull request events](#pull-request-events)
- [Restrictions on forked repositories](#restrictions-on-forked-repositories)
- [Restrictions on repository forks](#restrictions-on-repository-forks)
- [Triggering further workflow runs](#triggering-further-workflow-runs)
- [Security](#security)
- [Advanced usage](#advanced-usage)
@ -21,7 +21,7 @@ This document covers terminology, how the action works, general usage guidelines
## Terminology
[Pull requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#about-pull-requests) are proposed changes to a repository branch that can be reviewed by a repository's collaborators before being accepted or rejected.
[Pull requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#about-pull-requests) are proposed changes to a repository branch that can be reviewed by a repository's collaborators before being accepted or rejected.
A pull request references two branches:
@ -30,7 +30,7 @@ A pull request references two branches:
## Events and checkout
For each [event type](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows) there is a default `GITHUB_SHA` that will be checked out by the GitHub Actions [checkout](https://github.com/actions/checkout) action.
For each [event type](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) there is a default `GITHUB_SHA` that will be checked out by the GitHub Actions [checkout](https://github.com/actions/checkout) action.
The majority of events will default to checking out the "last commit on default branch," which in most cases will be the latest commit on `master`.
@ -64,7 +64,7 @@ For the action to work correctly it should be executed in a workflow that checks
This means your workflow should be consistently checking out the branch that you intend to modify once the PR is merged.
In the following example, the [`push`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#push-event-push) and [`create`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#create-event-create) events both trigger the same workflow. This will cause the checkout action to checkout commits from inconsistent branches. Do *not* do this. It will cause multiple pull requests to be created for each additional `base` the action is executed against.
In the following example, the [`push`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push) and [`create`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#create) events both trigger the same workflow. This will cause the checkout action to checkout commits from inconsistent branches. Do *not* do this. It will cause multiple pull requests to be created for each additional `base` the action is executed against.
```yml
on:
@ -81,7 +81,7 @@ Although rare, there may be use cases where it makes sense to execute the workfl
### Pull request events
Workflows triggered by `pull_request` events will by default check out a [merge commit](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#pull-request-event-pull_request). To prevent the merge commit being included in created pull requests it is necessary to checkout the `head_ref`.
Workflows triggered by `pull_request` events will by default check out a [merge commit](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request). To prevent the merge commit being included in created pull requests it is necessary to checkout the `head_ref`.
```yml
- uses: actions/checkout@v2
@ -89,20 +89,23 @@ Workflows triggered by `pull_request` events will by default check out a [merge
ref: ${{ github.head_ref }}
```
### Restrictions on forked repositories
### Restrictions on repository forks
GitHub Actions have imposed restrictions on events triggered by a forked repository. Specifically, the `pull_request` event triggered by a fork opening a pull request in the upstream repository.
GitHub Actions have imposed restrictions on workflow runs triggered by public repository forks.
Private repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction.
- Events from forks cannot access secrets, except for for the default `GITHUB_TOKEN`.
The restrictions apply to the `pull_request` event triggered by a fork opening a pull request in the upstream repository.
- Events from forks cannot access secrets, except for the default `GITHUB_TOKEN`.
> With the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository.
[GitHub Actions: Using encrypted secrets in a workflow](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#using-encrypted-secrets-in-a-workflow)
[GitHub Actions: Using encrypted secrets in a workflow](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#using-encrypted-secrets-in-a-workflow)
- The `GITHUB_TOKEN` has read-only access when an event is triggered by a forked repository.
[GitHub Actions: Permissions for the GITHUB_TOKEN](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#permissions-for-the-github_token)
[GitHub Actions: Permissions for the GITHUB_TOKEN](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token)
These restrictions mean that during a `pull_request` event triggered by a forked repository, actions have no write access to GitHub resources and will fail on attempt.
These restrictions mean that during a `pull_request` event triggered by a forked repository, actions have no write access to GitHub resources and will fail on any attempt.
A job condition can be added to prevent workflows from executing when triggered by a repository fork.
@ -121,14 +124,14 @@ Pull requests created by the action using the default `GITHUB_TOKEN` cannot trig
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run.
[GitHub Actions: Events that trigger workflows](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token)
[GitHub Actions: Events that trigger workflows](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token)
#### Workarounds to trigger further workflow runs
There are a number of workarounds with different pros and cons.
- Use the default `GITHUB_TOKEN` and allow the action to create pull requests that have no checks enabled. Manually close pull requests and immediately reopen them. This will enable `on: pull_request` workflows to run and be added as checks.
- Use a `repo` scoped [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). However, the PAT cannot be scoped to a specific repository so the token becomes a very sensitive secret. If this is a concern, the PAT can instead be created for a dedicated [machine account](https://help.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request.
- Use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). However, the PAT cannot be scoped to a specific repository so the token becomes a very sensitive secret. If this is a concern, the PAT can instead be created for a dedicated [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request.
- Use [SSH (deploy keys)](#push-using-ssh-deploy-keys) to push the pull request branch. This is arguably more secure than using a PAT because deploy keys can be set per repository. However, this method will only trigger `on: push` workflows.
- Use a [machine account that creates pull requests from its own fork](#push-pull-request-branches-to-a-fork). This is the most secure because the PAT created only grants access to the machine account's fork, not the main repository. This method will trigger `on: pull_request` workflows to run. Workflows triggered `on: push` will not run because the push event is in the fork.
- Use a [GitHub App to generate a token](#authenticating-with-github-app-generated-tokens) that can be used with this action. GitHub App generated tokens are more secure than using a PAT because GitHub App access permissions can be set with finer granularity and are scoped to only repositories where the App is installed. This method will trigger both `on: push` and `on: pull_request` workflows.
@ -139,17 +142,17 @@ From a security perspective it's good practice to fork third-party actions, revi
By using third-party actions directly the risk exists that it could be modified to do something malicious, such as capturing secrets.
Alternatively, use the action directly and reference the commit hash for the version you want to target.
```
```yml
- uses: thirdparty/foo-action@172ec762f2ac8e050062398456fccd30444f8f30
```
This action uses [ncc](https://github.com/zeit/ncc) to compile the Node.js code and dependencies into a single Javascript file under the [dist](https://github.com/peter-evans/create-pull-request/tree/master/dist) directory.
This action uses [ncc](https://github.com/zeit/ncc) to compile the Node.js code and dependencies into a single JavaScript file under the [dist](https://github.com/peter-evans/create-pull-request/tree/master/dist) directory.
## Advanced usage
### Creating pull requests in a remote repository
Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, a `repo` scoped [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) is required.
Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) is required.
```yml
- uses: actions/checkout@v2
@ -166,12 +169,13 @@ Checking out a branch from a different repository from where the workflow is exe
### Push using SSH (deploy keys)
[Deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) can be set per repository and so are arguably more secure than using a `repo` scoped [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
[Deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) can be set per repository and so are arguably more secure than using a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
Allowing the action to push with a configured deploy key will trigger `on: push` workflows. This makes it an alternative to using a PAT to trigger checks for pull requests.
Note that you cannot use deploy keys alone to [create a pull request in a remote repository](#creating-pull-requests-in-a-remote-repository) because then using a PAT would become a requirement. This method only makes sense if creating a pull request in the repository where the workflow is running.
How to use SSH (deploy keys) with create-pull-request action:
1. [Create a new SSH key pair](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) for your repository. Do not set a passphrase.
1. [Create a new SSH key pair](https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) for your repository. Do not set a passphrase.
2. Copy the contents of the public key (.pub file) to a new repository [deploy key](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) and check the box to "Allow write access."
3. Add a secret to the repository containing the entire contents of the private key.
4. As shown in the example below, configure `actions/checkout` to use the deploy key you have created.
@ -191,14 +195,14 @@ How to use SSH (deploy keys) with create-pull-request action:
### Push pull request branches to a fork
Instead of pushing pull request branches to the repository you want to update, you can push them to a fork of that repository.
This allows you to employ the [principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege) by using a dedicated user acting as a [machine account](https://help.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements).
This allows you to employ the [principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege) by using a dedicated user acting as a [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements).
This user has no access to the main repository.
It will use their own fork to push code and create the pull request.
1. Create a new GitHub user and login.
2. Fork the repository that you will be creating pull requests in.
3. Create a [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
4. Logout and log back in to your main user account.
3. Create a [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
4. Logout and log back into your main user account.
5. Add a secret to your repository containing the above PAT.
6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork.
@ -216,10 +220,10 @@ It will use their own fork to push code and create the pull request.
### Authenticating with GitHub App generated tokens
A GitHub App can be created for the sole purpose of generating tokens for use with GitHub actions.
These tokens can be used in place of `GITHUB_TOKEN` or a [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
These tokens can be used in place of `GITHUB_TOKEN` or a [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
GitHub App generated tokens are more secure than using a PAT because GitHub App access permissions can be set with finer granularity and are scoped to only repositories where the App is installed.
1. Create a minimal [GitHub App](https://developer.github.com/apps/building-github-apps/creating-a-github-app/), setting the following fields:
1. Create a minimal [GitHub App](https://docs.github.com/en/developers/apps/creating-a-github-app), setting the following fields:
- Set `GitHub App name`.
- Set `Homepage URL` to anything you like, such as your GitHub profile page.

View File

@ -6,6 +6,7 @@
- [Use case: Create a pull request to update X periodically](#use-case-create-a-pull-request-to-update-x-periodically)
- [Update NPM dependencies](#update-npm-dependencies)
- [Update Gradle dependencies](#update-gradle-dependencies)
- [Update Cargo dependencies](#update-cargo-dependencies)
- [Update SwaggerUI for GitHub Pages](#update-swaggerui-for-github-pages)
- [Spider and download a website](#spider-and-download-a-website)
- [Use case: Create a pull request to update X by calling the GitHub API](#use-case-create-a-pull-request-to-update-x-by-calling-the-github-api)
@ -89,7 +90,7 @@ This pattern will work well for updating any kind of static content from an exte
This workflow will create a pull request for npm dependencies.
It works best in combination with a build workflow triggered on `push` and `pull_request`.
A [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) can be used in order for the creation of the pull request to trigger further workflows. See the [documentation here](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) for further details.
A [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) can be used in order for the creation of the pull request to trigger further workflows. See the [documentation here](concepts-guidelines.md#triggering-further-workflow-runs) for further details.
```yml
name: Update Dependencies
@ -183,6 +184,41 @@ jobs:
branch: update-dependencies
```
### Update Cargo dependencies
The following workflow will create a pull request for Cargo dependencies.
It optionally uses [`cargo-edit`](https://github.com/killercup/cargo-edit) to update `Cargo.toml` and keep it in sync with `Cargo.lock`.
```yml
name: Update Dependencies
on:
schedule:
- cron: '0 1 * * 1'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update dependencies
run: |
cargo install cargo-edit
cargo update
cargo upgrade --to-lockfile
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies
```
### Update SwaggerUI for GitHub Pages
When using [GitHub Pages to host Swagger documentation](https://github.com/peter-evans/swagger-github-pages), this workflow updates the repository with the latest distribution of [SwaggerUI](https://github.com/swagger-api/swagger-ui).
@ -277,7 +313,7 @@ jobs:
## Use case: Create a pull request to update X by calling the GitHub API
You can use the GitHub API to trigger a webhook event called [`repository_dispatch`](https://help.github.com/en/github/automating-your-workflow-with-github-actions/events-that-trigger-workflows#external-events-repository_dispatch) when you want to trigger a workflow for activity that happens outside of GitHub.
You can use the GitHub API to trigger a webhook event called [`repository_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#repository_dispatch) when you want to trigger a workflow for any activity that happens outside of GitHub.
This pattern will work well for updating any kind of static content from an external source.
You can modify any of the examples in the previous section to work in this fashion.
@ -295,7 +331,7 @@ on:
An `on: repository_dispatch` workflow can be triggered by a call to the GitHub API as follows.
- `[username]` is a GitHub username
- `[token]` is a `repo` scoped [Personal Access Token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)
- `[token]` is a `repo` scoped [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
- `[repository]` is the name of the repository the workflow resides in.
```
@ -326,7 +362,8 @@ An `on: repository_dispatch` workflow can be triggered from another workflow wit
This is a pattern that lends itself to automated code linting and fixing. A pull request can be created to fix or modify something during an `on: pull_request` workflow. The pull request containing the fix will be raised with the original pull request as the base. This can be then be merged to update the original pull request and pass any required tests.
Note that due to [limitations on forked repositories](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#permissions-for-the-github_token) workflows for this use case do not work for pull requests raised from forks.
Note that due to [token restrictions on public repository forks](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token), workflows for this use case do not work for pull requests raised from forks.
Private repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction.
### autopep8
@ -409,7 +446,7 @@ jobs:
The following examples show how configuration for the action can be dynamically defined in a previous workflow step.
The recommended method is to use [`set-output`](https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-output-parameter-set-output). Note that the step where output variables are defined must have an id.
The recommended method is to use [`set-output`](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter). Note that the step where output variables are defined must have an id.
```yml
- name: Set output variables
@ -425,7 +462,7 @@ The recommended method is to use [`set-output`](https://help.github.com/en/githu
body: ${{ steps.vars.outputs.pr_body }}
```
Alternatively, [`set-env`](https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-environment-variable-set-env) can be used to create environment variables.
Alternatively, [`set-env`](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable) can be used to create environment variables.
```yml
- name: Set environment variables
@ -440,16 +477,36 @@ Alternatively, [`set-env`](https://help.github.com/en/github/automating-your-wor
body: ${{ env.PULL_REQUEST_BODY }}
```
### Setting the pull request body from a file
This example shows how file content can be read into a variable and passed to the action.
The content must be [escaped to preserve newlines](https://github.community/t/set-output-truncates-multiline-strings/16852/3).
```yml
- id: get-pr-body
run: |
body=$(cat pr-body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
body: ${{ steps.get-pr-body.outputs.body }}
```
### Debugging GitHub Actions
#### Runner Diagnostic Logging
[Runner diagnostic logging](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/managing-a-workflow-run#enabling-runner-diagnostic-logging) provides additional log files that contain information about how a runner is executing an action.
[Runner diagnostic logging](https://docs.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#enabling-runner-diagnostic-logging) provides additional log files that contain information about how a runner is executing an action.
To enable runner diagnostic logging, set the secret `ACTIONS_RUNNER_DEBUG` to `true` in the repository that contains the workflow.
#### Step Debug Logging
[Step debug logging](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/managing-a-workflow-run#enabling-step-debug-logging) increases the verbosity of a job's logs during and after a job's execution.
[Step debug logging](https://docs.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#enabling-step-debug-logging) increases the verbosity of a job's logs during and after a job's execution.
To enable step debug logging set the secret `ACTIONS_STEP_DEBUG` to `true` in the repository that contains the workflow.
#### Output Various Contexts

View File

@ -59,7 +59,7 @@
run: git checkout "${GITHUB_REF:11}"
```
- The two branch naming strategies have been swapped. Fixed branch naming strategy is now the default. i.e. `branch-suffix: none` is now the default and should be removed from configuration if set.
- The two branch naming strategies have been swapped. Fixed-branch naming strategy is now the default. i.e. `branch-suffix: none` is now the default and should be removed from configuration if set.
- `author-name`, `author-email`, `committer-name`, `committer-email` have been removed in favour of `author` and `committer`.
They can both be set in the format `Display Name <email@address.com>`

4072
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,25 +31,24 @@
"dependencies": {
"@actions/core": "1.2.4",
"@actions/exec": "1.0.4",
"@actions/tool-cache": "1.3.4",
"@octokit/core": "3.1.0",
"@octokit/plugin-paginate-rest": "2.2.3",
"@octokit/plugin-rest-endpoint-methods": "4.0.0",
"uuid": "8.2.0"
"@octokit/core": "3.1.2",
"@octokit/plugin-paginate-rest": "2.3.0",
"@octokit/plugin-rest-endpoint-methods": "4.1.2",
"uuid": "8.3.0"
},
"devDependencies": {
"@types/jest": "25.2.2",
"@types/node": "14.0.1",
"@typescript-eslint/parser": "2.33.0",
"@zeit/ncc": "0.22.1",
"eslint": "7.0.0",
"eslint-plugin-github": "3.4.1",
"eslint-plugin-jest": "23.11.0",
"jest": "26.0.1",
"jest-circus": "26.0.1",
"js-yaml": "3.13.1",
"@types/jest": "26.0.9",
"@types/node": "14.0.27",
"@typescript-eslint/parser": "3.9.0",
"@zeit/ncc": "0.22.3",
"eslint": "7.6.0",
"eslint-plugin-github": "4.1.1",
"eslint-plugin-jest": "23.20.0",
"jest": "26.4.0",
"jest-circus": "26.4.0",
"js-yaml": "3.14.0",
"prettier": "2.0.5",
"ts-jest": "25.5.1",
"typescript": "3.9.2"
"ts-jest": "26.2.0",
"typescript": "3.9.7"
}
}

View File

@ -77,7 +77,8 @@ export async function createOrUpdateBranch(
commitMessage: string,
base: string,
branch: string,
branchRemoteName: string
branchRemoteName: string,
signoff: boolean
): Promise<CreateOrUpdateBranchResult> {
// Get the working base. This may or may not be the actual base.
const workingBase = await git.symbolicRef('HEAD', ['--short'])
@ -95,11 +96,15 @@ export async function createOrUpdateBranch(
// Save the working base changes to a temporary branch
const tempBranch = uuidv4()
await git.checkout(tempBranch, 'HEAD')
// Commit any uncomitted changes
// Commit any uncommitted changes
if (await git.isDirty(true)) {
core.info('Uncommitted changes found. Adding a commit.')
await git.exec(['add', '-A'])
await git.commit(['-m', commitMessage])
const params = ['-m', commitMessage]
if (signoff) {
params.push('--signoff')
}
await git.commit(params)
}
// Perform fetch and reset the working base
@ -173,6 +178,7 @@ export async function createOrUpdateBranch(
result.action = 'updated'
core.info(`Updated branch '${branch}'`)
} else {
result.action = 'not-updated'
core.info(
`Branch '${branch}' is even with its remote and will not be updated`
)

View File

@ -11,6 +11,7 @@ export interface Inputs {
commitMessage: string
committer: string
author: string
signoff: boolean
branch: string
branchSuffix: string
base: string
@ -98,12 +99,14 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
)
}
const workingBase = symbolicRefResult.stdout.trim()
// Exit if the working base is a PR branch created by this action.
// This may occur when using a PAT instead of GITHUB_TOKEN because
// a PAT allows workflow actions to trigger further events.
if (workingBase.startsWith(inputs.branch)) {
// If the base is not specified it is assumed to be the working base.
const base = inputs.base ? inputs.base : workingBase
// Throw an error if the base and branch are not different branches
// of the 'origin' remote. An identically named branch in the `fork`
// remote is perfectly fine.
if (branchRemoteName == 'origin' && base == inputs.branch) {
throw new Error(
`Working base branch '${workingBase}' was created by this action. Unable to continue.`
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
)
}
core.endGroup()
@ -166,7 +169,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
inputs.commitMessage,
inputs.base,
inputs.branch,
branchRemoteName
branchRemoteName,
inputs.signoff
)
core.endGroup()
@ -181,19 +185,21 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
`HEAD:refs/heads/${inputs.branch}`
])
core.endGroup()
}
// Set the base. It would have been '' if not specified as an input
inputs.base = result.base
// Set the base. It would have been '' if not specified as an input
inputs.base = result.base
if (result.hasDiffWithBase) {
// Create or update the pull request
await githubHelper.createOrUpdatePullRequest(
inputs,
baseRemote.repository,
branchRepository
)
} else {
// If there is no longer a diff with the base delete the branch
if (result.hasDiffWithBase) {
// Create or update the pull request
await githubHelper.createOrUpdatePullRequest(
inputs,
baseRemote.repository,
branchRepository
)
} else {
// If there is no longer a diff with the base delete the branch
if (['updated', 'not-updated'].includes(result.action)) {
core.info(
`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`
)

View File

@ -11,6 +11,7 @@ async function run(): Promise<void> {
commitMessage: core.getInput('commit-message'),
committer: core.getInput('committer'),
author: core.getInput('author'),
signoff: core.getInput('signoff') === 'true',
branch: core.getInput('branch'),
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),