Compare commits

...

13 Commits
v3 ... v4.0.1

Author SHA1 Message Date
f1a7646cea build: update distribution (#1157)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-03-31 17:14:30 +09:00
15b68d176d fix: strip optional '.git' suffix from https server remote name. (#1153)
* Strip optional '.git' suffix from https server remote name.

* Revert "Strip optional '.git' suffix from https server remote name."

This reverts commit c2e9041213.

* Strip optional '.git' suffix from https server remote name.
2022-03-31 17:10:39 +09:00
0dfc93c104 build(deps): bump peter-evans/create-pull-request from 3 to 4 (#1150) 2022-03-28 21:33:19 +09:00
252fb19db2 build(deps): bump peter-evans/slash-command-dispatch from 2 to 3 (#1122)
Bumps [peter-evans/slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) from 2 to 3.
- [Release notes](https://github.com/peter-evans/slash-command-dispatch/releases)
- [Commits](https://github.com/peter-evans/slash-command-dispatch/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/slash-command-dispatch
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:35 +09:00
4b867c4939 build(deps): bump actions/setup-node from 2 to 3 (#1123)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2 to 3.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:11 +09:00
4fb3835236 build(deps): bump peter-evans/close-pull from 1 to 2 (#1121)
Bumps [peter-evans/close-pull](https://github.com/peter-evans/close-pull) from 1 to 2.
- [Release notes](https://github.com/peter-evans/close-pull/releases)
- [Commits](https://github.com/peter-evans/close-pull/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/close-pull
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:36 +09:00
19ace475b4 build(deps): bump peter-evans/create-or-update-comment from 1 to 2 (#1120)
Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/create-or-update-comment/releases)
- [Commits](https://github.com/peter-evans/create-or-update-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/create-or-update-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:17 +09:00
84d431ad62 build(deps): bump peter-evans/find-comment from 1 to 2 (#1119)
Bumps [peter-evans/find-comment](https://github.com/peter-evans/find-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/find-comment/releases)
- [Commits](https://github.com/peter-evans/find-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/find-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:28:50 +09:00
d6d5519d05 v4 (#1099)
* feat: update action runtime to node 16

* feat: allow add-paths to resolve to no changes

* docs: update readme

* chore: update package lock

* chore: bump dependency

* ci: add dependabot workflow

* docs: update action versions
2022-03-23 14:22:01 +09:00
0e8dfbd57d docs: update guidelines 2022-03-11 13:46:10 +09:00
ffa8cc2261 docs: Skip follow-up steps if there is no pull request (#1083) 2022-03-09 12:40:44 +09:00
00fb6900cb docs: Document how to improve close-and-reopen user experience (#1084) 2022-03-09 12:38:41 +09:00
2fe7e77753 docs: Add word "permissions" (#1082) 2022-03-09 10:46:31 +09:00
18 changed files with 309 additions and 195 deletions

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

View File

@ -14,23 +14,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12.x
- uses: actions/setup-python@v2
with:
python-version: '3.x'
node-version: 16.x
cache: npm
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: action.yml
path: action.yml
@ -43,16 +41,16 @@ jobs:
matrix:
target: [built, committed]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: main
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: action.yml
path: .
@ -77,7 +75,7 @@ jobs:
branch: ci-test-${{ matrix.target }}
- name: Close Pull
uses: peter-evans/close-pull@v1
uses: peter-evans/close-pull@v2
with:
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
comment: '[CI] test ${{ matrix.target }}'
@ -89,7 +87,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Find Comment
uses: peter-evans/find-comment@v1
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.number }}
@ -98,7 +96,7 @@ jobs:
- if: steps.fc.outputs.comment-id == ''
name: Create comment
uses: peter-evans/create-or-update-comment@v1
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.number }}
body: |
@ -112,13 +110,13 @@ jobs:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: 'build: update distribution'
title: Update distribution

View File

@ -6,7 +6,7 @@ jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Make changes to pull request
run: date +%s > report.txt
@ -42,7 +42,7 @@ jobs:
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: Add reaction
uses: peter-evans/create-or-update-comment@v1
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}

View File

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

View File

@ -21,20 +21,20 @@ Create Pull Request action will:
- [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md)
- [Examples](docs/examples.md)
- [Updating to v3](docs/updating.md)
- [Updating to v4](docs/updating.md)
## Usage
```yml
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
```
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v3.x.x`
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v4.x.x`
### Action inputs
@ -44,9 +44,9 @@ All inputs are **optional**. If not set, sensible defaults will be used.
| Name | Description | Default |
| --- | --- | --- |
| `token` | `GITHUB_TOKEN` (`contents: write`, `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `token` | `GITHUB_TOKEN` (permissions `contents: write` and `pull-requests: write`) 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` |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. Defaults to adding all new and modified files. See [Add specific paths](#add-specific-paths). | `-A` |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. See [Add specific paths](#add-specific-paths). | |
| `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>` |
@ -68,7 +68,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
env:
https_proxy: http://<proxy_address>:<port>
```
@ -88,8 +88,9 @@ Note that in order to read the step outputs the action step must have an id.
```yml
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
@ -146,12 +147,11 @@ If there are files or directories you want to ignore you can simply add them to
You can control which files are committed with the `add-paths` input.
Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax.
Each path must resolve to a least one new or modified file to add.
All file changes that do not match one of the paths will be discarded.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
add-paths: |
*.java
@ -165,7 +165,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Create commits
run: |
git config user.name 'Peter Evans'
@ -178,7 +178,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
- name: Uncommitted change
run: date +%s > report.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
```
### Create a project card
@ -188,10 +188,11 @@ To create a project card for the pull request, pass the `pull-request-number` st
```yml
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
- name: Create or Update Project Card
uses: peter-evans/create-or-update-project-card@v1
if: ${{ steps.cpr.outputs.pull-request-number }}
uses: peter-evans/create-or-update-project-card@v2
with:
project-name: My project
column-name: My column
@ -215,14 +216,14 @@ jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Make changes to pull request
run: date +%s > report.txt
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update report

View File

@ -11,8 +11,8 @@ import {v4 as uuidv4} from 'uuid'
const REPO_PATH = '/git/local/test-base'
const REMOTE_NAME = 'origin'
const TRACKED_FILE = 'tracked-file.txt'
const UNTRACKED_FILE = 'untracked-file.txt'
const TRACKED_FILE = 'a/tracked-file.txt'
const UNTRACKED_FILE = 'b/untracked-file.txt'
const DEFAULT_BRANCH = 'tests/master'
const NOT_BASE_BRANCH = 'tests/branch-that-is-not-the-base'
@ -25,12 +25,14 @@ const BASE = DEFAULT_BRANCH
const FORK_REMOTE_URL = 'git://127.0.0.1/test-fork.git'
const FORK_REMOTE_NAME = 'fork'
const ADD_PATHS = ['-A']
const ADD_PATHS_WILDCARD = ['*.txt']
const ADD_PATHS_DEFAULT = []
const ADD_PATHS_MULTI = ['a', 'b']
const ADD_PATHS_WILDCARD = ['a/*.txt', 'b/*.txt']
async function createFile(filename: string, content?: string): Promise<string> {
const _content = content ? content : uuidv4()
const filepath = path.join(REPO_PATH, filename)
await fs.promises.mkdir(path.dirname(filepath), {recursive: true})
await fs.promises.writeFile(filepath, _content, {encoding: 'utf8'})
return _content
}
@ -224,7 +226,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -241,7 +243,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -269,7 +271,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -290,7 +292,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -318,7 +320,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -341,7 +343,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -370,7 +372,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -391,7 +393,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -428,7 +430,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -459,7 +461,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -487,7 +489,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -508,7 +510,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -548,7 +550,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -575,7 +577,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -618,7 +620,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -640,7 +642,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -671,7 +673,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -697,7 +699,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -732,7 +734,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -760,7 +762,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -803,7 +805,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -830,7 +832,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
FORK_REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -859,7 +861,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
FORK_REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -881,7 +883,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
true,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -917,7 +919,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
true,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -935,9 +937,58 @@ describe('create-or-update-branch tests', () => {
)
})
it('tests create and update with wildcard add-paths', async () => {
// The pull request branch will not be updated
it('tests create and update with multiple add-paths', async () => {
// Create tracked and untracked file changes
const changes = await createChanges()
const commitMessage = uuidv4()
const result = await createOrUpdateBranch(
git,
commitMessage,
'',
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS_MULTI
)
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()
// 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,
false,
ADD_PATHS_MULTI
)
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()
})
it('tests create and update with wildcard add-paths', async () => {
// Create tracked and untracked file changes
const changes = await createChanges()
const commitMessage = uuidv4()
@ -988,6 +1039,23 @@ describe('create-or-update-branch tests', () => {
).toBeTruthy()
})
it('tests create with add-paths resolving to no changes when other changes exist', async () => {
// Create tracked and untracked file changes
await createChanges()
const commitMessage = uuidv4()
const result = await createOrUpdateBranch(
git,
commitMessage,
'',
BRANCH,
REMOTE_NAME,
false,
['nonexistent/*']
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
})
// Working Base is Not Base (WBNB)
it('tests no changes resulting in no new branch being created (WBNB)', async () => {
@ -1002,7 +1070,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -1022,7 +1090,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -1053,7 +1121,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1077,7 +1145,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -1108,7 +1176,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1134,7 +1202,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1166,7 +1234,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1190,7 +1258,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1230,7 +1298,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1264,7 +1332,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1295,7 +1363,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -1321,7 +1389,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1364,7 +1432,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -1394,7 +1462,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1440,7 +1508,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy()
@ -1465,7 +1533,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -1499,7 +1567,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1528,7 +1596,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1566,7 +1634,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1597,7 +1665,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1643,7 +1711,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1673,7 +1741,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
FORK_REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1705,7 +1773,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
FORK_REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1734,7 +1802,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1767,7 +1835,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1793,7 +1861,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1834,7 +1902,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
@ -1866,7 +1934,7 @@ describe('create-or-update-branch tests', () => {
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS
ADD_PATHS_DEFAULT
)
// The action cannot successfully create the branch
expect(result.action).toEqual('none')

View File

@ -50,6 +50,12 @@ describe('utils tests', () => {
)
expect(remote3.protocol).toEqual('SSH')
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
const remote4 = utils.getRemoteDetail(
'https://github.com/peter-evans/create-pull-request.git'
)
expect(remote4.protocol).toEqual('HTTPS')
expect(remote4.repository).toEqual('peter-evans/create-pull-request')
})
test('getRemoteDetail fails to parse a remote URL', async () => {

View File

@ -13,8 +13,6 @@ inputs:
A comma or newline-separated list of file paths to commit.
Paths should follow git's pathspec syntax.
Defaults to adding all new and modified files.
default: |
-A
commit-message:
description: 'The message to use when committing changes.'
default: '[create-pull-request] automated change'
@ -81,7 +79,7 @@ outputs:
pull-request-head-sha:
description: 'The commit SHA of the pull request branch.'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
branding:
icon: 'git-pull-request'

44
dist/index.js vendored
View File

@ -122,20 +122,25 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
const tempBranch = (0, uuid_1.v4)();
yield git.checkout(tempBranch, 'HEAD');
// Commit any uncommitted changes
if (yield git.isDirty(true)) {
if (yield git.isDirty(true, addPaths)) {
core.info('Uncommitted changes found. Adding a commit.');
for (const path of addPaths) {
yield git.exec(['add', path], true);
const aopts = ['add'];
if (addPaths.length > 0) {
aopts.push(...['--', ...addPaths]);
}
const params = ['-m', commitMessage];
else {
aopts.push('-A');
}
yield git.exec(aopts, true);
const popts = ['-m', commitMessage];
if (signoff) {
params.push('--signoff');
popts.push('--signoff');
}
yield git.commit(params);
// Remove uncommitted tracked and untracked changes
yield git.exec(['reset', '--hard']);
yield git.exec(['clean', '-f']);
yield git.commit(popts);
}
// Remove uncommitted tracked and untracked changes
yield git.exec(['reset', '--hard']);
yield git.exec(['clean', '-f', '-d']);
// Perform fetch and reset the working base
// Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) {
@ -752,18 +757,23 @@ class GitCommandManager {
return output.exitCode === 1;
});
}
isDirty(untracked) {
isDirty(untracked, pathspec) {
return __awaiter(this, void 0, void 0, function* () {
const pathspecArgs = pathspec ? ['--', ...pathspec] : [];
// Check untracked changes
if (untracked && (yield this.status(['--porcelain', '-unormal']))) {
const sargs = ['--porcelain', '-unormal'];
sargs.push(...pathspecArgs);
if (untracked && (yield this.status(sargs))) {
return true;
}
// Check working index changes
if (yield this.hasDiff()) {
if (yield this.hasDiff(pathspecArgs)) {
return true;
}
// Check staged changes
if (yield this.hasDiff(['--staged'])) {
const dargs = ['--staged'];
dargs.push(...pathspecArgs);
if (yield this.hasDiff(dargs)) {
return true;
}
return false;
@ -1085,9 +1095,9 @@ function run() {
commitMessage: core.getInput('commit-message'),
committer: core.getInput('committer'),
author: core.getInput('author'),
signoff: core.getInput('signoff') === 'true',
signoff: core.getBooleanInput('signoff'),
branch: core.getInput('branch'),
deleteBranch: core.getInput('delete-branch') === 'true',
deleteBranch: core.getBooleanInput('delete-branch'),
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),
pushToFork: core.getInput('push-to-fork'),
@ -1098,7 +1108,7 @@ function run() {
reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')),
draft: core.getInput('draft') === 'true'
draft: core.getBooleanInput('draft')
};
core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`);
yield (0, create_pull_request_1.createPullRequest)(inputs);
@ -1201,7 +1211,7 @@ function getRemoteDetail(remoteUrl) {
if (!githubServerMatch) {
throw new Error('Could not parse GitHub Server name');
}
const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', 'i');
const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$', 'i');
const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i');
const httpsMatch = remoteUrl.match(httpsUrlPattern);
if (httpsMatch) {

View File

@ -36,7 +36,7 @@ For each [event type](https://docs.github.com/en/actions/reference/events-that-t
The default can be overridden by specifying a `ref` on checkout.
```yml
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: develop
```
@ -73,7 +73,7 @@ jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
```
There may be use cases where it makes sense to execute the workflow on a branch that is not the base of the pull request. In these cases, the base branch can be specified with the `base` action input. The action will attempt to rebase changes made during the workflow on to the actual base.
@ -88,7 +88,7 @@ In these cases, you *must supply* the `base` input so the action can rebase chan
Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) events will by default check out a merge commit. Set the `base` input as follows to base the new pull request on the current pull request's branch.
```yml
- uses: peter-evans/create-pull-request@v3
- uses: peter-evans/create-pull-request@v4
with:
base: ${{ github.head_ref }}
```
@ -96,7 +96,7 @@ Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/refer
Workflows triggered by [`release`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release) events will by default check out a tag. For most use cases, you will need to set the `base` input to the branch name of the tagged commit.
```yml
- uses: peter-evans/create-pull-request@v3
- uses: peter-evans/create-pull-request@v4
with:
base: main
```
@ -144,7 +144,7 @@ Pull requests created by the action using the default `GITHUB_TOKEN` cannot trig
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 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. To prevent merging of pull requests without checks erroneously, use [branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests).
- 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.
@ -173,14 +173,14 @@ This action uses [ncc](https://github.com/vercel/ncc) to compile the Node.js cod
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
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
repository: owner/repo
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v3
- uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
```
@ -200,14 +200,14 @@ How to use SSH (deploy keys) with create-pull-request action:
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
```
### Push pull request branches to a fork
@ -225,11 +225,11 @@ It will use their own fork to push code and create the pull request.
6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork.
```yaml
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v3
- uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.MACHINE_USER_PAT }}
push-to-fork: machine-user/fork-of-repository
@ -261,7 +261,7 @@ GitHub App generated tokens are more secure than using a PAT because GitHub App
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: tibdex/github-app-token@v1
id: generate-token
@ -272,7 +272,7 @@ GitHub App generated tokens are more secure than using a PAT because GitHub App
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.generate-token.outputs.token }}
```
@ -301,7 +301,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: crazy-max/ghaction-import-gpg@v3
with:
@ -313,7 +313,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
committer: example <email@example.com>
@ -338,12 +338,12 @@ jobs:
- name: Install dependencies
run: apk --no-cache add git
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
```
**Ubuntu container example:**
@ -361,10 +361,10 @@ jobs:
add-apt-repository -y ppa:git-core/ppa
apt-get install -y git
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
```

View File

@ -43,14 +43,14 @@ jobs:
updateAuthors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update AUTHORS
run: |
git log --format='%aN <%aE>%n%cN <%cE>' | sort -u > AUTHORS
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: update authors
title: Update AUTHORS
@ -74,7 +74,7 @@ jobs:
productionPromotion:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: production
- name: Reset promotion branch
@ -82,7 +82,7 @@ jobs:
git fetch origin main:main
git reset --hard main
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
branch: production-promotion
```
@ -107,7 +107,7 @@ jobs:
updateChangelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update Changelog
@ -117,7 +117,7 @@ jobs:
./git-chglog -o CHANGELOG.md
rm git-chglog
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: update changelog
title: Update Changelog
@ -145,16 +145,16 @@ jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: '16.x'
- name: Update dependencies
run: |
npx -p npm-check-updates ncu -u
npm install
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
@ -181,10 +181,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12.x
node-version: 16.x
- run: npm ci
- run: npm run test
- run: npm run build
@ -205,16 +205,17 @@ jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Perform dependency resolution and write new lockfiles
run: ./gradlew dependencies --write-locks
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
@ -242,14 +243,14 @@ jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- 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
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
@ -277,7 +278,7 @@ jobs:
updateSwagger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get Latest Swagger UI Release
id: swagger-ui
run: |
@ -305,7 +306,7 @@ jobs:
# Update current release
echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }}
title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}
@ -340,7 +341,7 @@ jobs:
updateFork:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
repository: fork-owner/repo
- name: Reset the default branch with upstream changes
@ -349,7 +350,7 @@ jobs:
git fetch upstream main:upstream-main
git reset --hard upstream-main
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
branch: upstream-changes
@ -368,7 +369,7 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download website
run: |
wget \
@ -382,7 +383,7 @@ jobs:
--domains quotes.toscrape.com \
http://quotes.toscrape.com/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: update local website copy
title: Automated Updates to Local Website Copy
@ -427,7 +428,7 @@ An `on: repository_dispatch` workflow can be triggered from another workflow wit
```yml
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: username/my-repo
@ -464,7 +465,7 @@ jobs:
if: startsWith(github.head_ref, 'autopep8-patches') == false && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: autopep8
@ -477,7 +478,7 @@ jobs:
run: echo ::set-output name=branch-name::"autopep8-patches/${{ github.head_ref }}"
- name: Create Pull Request
if: steps.autopep8.outputs.exit-code == 2
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
commit-message: autopep8 action fixes
title: Fixes by autopep8 action
@ -511,13 +512,13 @@ jobs:
if: startsWith(github.ref, 'refs/heads/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
...
someOtherJob:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
...
```
@ -535,7 +536,7 @@ The recommended method is to use [`set-output`](https://docs.github.com/en/actio
echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
title: ${{ steps.vars.outputs.pr_title }}
body: ${{ steps.vars.outputs.pr_body }}
@ -556,7 +557,7 @@ The content must be [escaped to preserve newlines](https://github.community/t/se
echo ::set-output name=body::$body
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
body: ${{ steps.get-pr-body.outputs.body }}
```
@ -573,7 +574,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
```yml
- name: Render template
id: template
uses: chuhlomin/render-template@v1.2
uses: chuhlomin/render-template@v1.4
with:
template: .github/pull-request-template.md
vars: |
@ -581,7 +582,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
bar: that
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
body: ${{ steps.template.outputs.result }}
```

View File

@ -1,3 +1,17 @@
## Updating from `v3` to `v4`
### Breaking changes
- The `add-paths` input no longer accepts `-A` as a valid value. When committing all new and modified files the `add-paths` input should be omitted.
- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v4` to run. See "What's new" below for details.
### What's new
- Updated runtime to Node.js 16
- The action now requires a minimum version of v2.285.0 for the [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0).
- If using GitHub Enterprise Server, the action requires [GHES 3.4](https://docs.github.com/en/enterprise-server@3.4/admin/release-notes) or later.
## Updating from `v2` to `v3`
### Breaking changes
@ -31,7 +45,7 @@
push-to-fork: machine-user/fork-of-repository
```
### New features
### What's new
- The action has been converted to Typescript giving it a significant performance improvement.
@ -66,7 +80,7 @@
If neither `author` or `committer` are set the action will default to making commits as the GitHub Actions bot user.
### New features
### What's new
- Unpushed commits made during the workflow before the action runs will now be considered as changes to be raised in the pull request. See [Create your own commits](https://github.com/peter-evans/create-pull-request#create-your-own-commits) for details.
- New commits made to the pull request base will now be taken into account when pull requests are updated.

16
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "create-pull-request",
"version": "3.0.0",
"version": "4.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "create-pull-request",
"version": "3.0.0",
"version": "4.0.0",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.6.0",
@ -4928,9 +4928,9 @@
}
},
"node_modules/minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"node_modules/ms": {
@ -10068,9 +10068,9 @@
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"ms": {

View File

@ -1,6 +1,6 @@
{
"name": "create-pull-request",
"version": "3.0.0",
"version": "4.0.0",
"private": true,
"description": "Creates a pull request for changes to your repository in the actions workspace",
"main": "lib/main.js",

View File

@ -119,21 +119,26 @@ export async function createOrUpdateBranch(
const tempBranch = uuidv4()
await git.checkout(tempBranch, 'HEAD')
// Commit any uncommitted changes
if (await git.isDirty(true)) {
if (await git.isDirty(true, addPaths)) {
core.info('Uncommitted changes found. Adding a commit.')
for (const path of addPaths) {
await git.exec(['add', path], true)
const aopts = ['add']
if (addPaths.length > 0) {
aopts.push(...['--', ...addPaths])
} else {
aopts.push('-A')
}
const params = ['-m', commitMessage]
await git.exec(aopts, true)
const popts = ['-m', commitMessage]
if (signoff) {
params.push('--signoff')
popts.push('--signoff')
}
await git.commit(params)
// Remove uncommitted tracked and untracked changes
await git.exec(['reset', '--hard'])
await git.exec(['clean', '-f'])
await git.commit(popts)
}
// Remove uncommitted tracked and untracked changes
await git.exec(['reset', '--hard'])
await git.exec(['clean', '-f', '-d'])
// Perform fetch and reset the working base
// Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) {

View File

@ -155,17 +155,22 @@ export class GitCommandManager {
return output.exitCode === 1
}
async isDirty(untracked: boolean): Promise<boolean> {
async isDirty(untracked: boolean, pathspec?: string[]): Promise<boolean> {
const pathspecArgs = pathspec ? ['--', ...pathspec] : []
// Check untracked changes
if (untracked && (await this.status(['--porcelain', '-unormal']))) {
const sargs = ['--porcelain', '-unormal']
sargs.push(...pathspecArgs)
if (untracked && (await this.status(sargs))) {
return true
}
// Check working index changes
if (await this.hasDiff()) {
if (await this.hasDiff(pathspecArgs)) {
return true
}
// Check staged changes
if (await this.hasDiff(['--staged'])) {
const dargs = ['--staged']
dargs.push(...pathspecArgs)
if (await this.hasDiff(dargs)) {
return true
}
return false

View File

@ -12,9 +12,9 @@ async function run(): Promise<void> {
commitMessage: core.getInput('commit-message'),
committer: core.getInput('committer'),
author: core.getInput('author'),
signoff: core.getInput('signoff') === 'true',
signoff: core.getBooleanInput('signoff'),
branch: core.getInput('branch'),
deleteBranch: core.getInput('delete-branch') === 'true',
deleteBranch: core.getBooleanInput('delete-branch'),
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),
pushToFork: core.getInput('push-to-fork'),
@ -25,7 +25,7 @@ async function run(): Promise<void> {
reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')),
draft: core.getInput('draft') === 'true'
draft: core.getBooleanInput('draft')
}
core.debug(`Inputs: ${inspect(inputs)}`)

View File

@ -47,7 +47,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
}
const httpsUrlPattern = new RegExp(
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$',
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$',
'i'
)
const sshUrlPattern = new RegExp(