From d6d5519d05f5814158ef015b8448f2f74648c421 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Wed, 23 Mar 2022 14:22:01 +0900 Subject: [PATCH] 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 --- .github/dependabot.yml | 8 + .github/workflows/ci.yml | 24 ++- .github/workflows/cpr-example-command.yml | 2 +- README.md | 29 ++- __test__/create-or-update-branch.int.test.ts | 186 +++++++++++++------ action.yml | 4 +- dist/index.js | 42 +++-- docs/concepts-guidelines.md | 36 ++-- docs/examples.md | 67 +++---- docs/updating.md | 18 +- package-lock.json | 16 +- package.json | 2 +- src/create-or-update-branch.ts | 23 ++- src/git-command-manager.ts | 13 +- src/main.ts | 6 +- 15 files changed, 291 insertions(+), 185 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..b85dc1893d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb4b151ed..d5298e3bba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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@v2 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: . @@ -112,8 +110,8 @@ 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 diff --git a/.github/workflows/cpr-example-command.yml b/.github/workflows/cpr-example-command.yml index d383f45d64..c14f765f23 100644 --- a/.github/workflows/cpr-example-command.yml +++ b/.github/workflows/cpr-example-command.yml @@ -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 diff --git a/README.md b/README.md index 0980ba683b..fcfd8668ba 100644 --- a/README.md +++ b/README.md @@ -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 @@ -46,7 +46,7 @@ All inputs are **optional**. If not set, sensible defaults will be used. | --- | --- | --- | | `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 `. Defaults to the GitHub Actions bot user. | `GitHub ` | | `author` | The author name and email address in the format `Display Name `. 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://: ``` @@ -88,7 +88,7 @@ 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: | @@ -147,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 @@ -166,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' @@ -179,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 @@ -189,11 +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 if: ${{ steps.cpr.outputs.pull-request-number }} - uses: peter-evans/create-or-update-project-card@v1 + uses: peter-evans/create-or-update-project-card@v2 with: project-name: My project column-name: My column @@ -217,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 diff --git a/__test__/create-or-update-branch.int.test.ts b/__test__/create-or-update-branch.int.test.ts index 49db5bf7b2..213dc83392 100644 --- a/__test__/create-or-update-branch.int.test.ts +++ b/__test__/create-or-update-branch.int.test.ts @@ -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 { 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') diff --git a/action.yml b/action.yml index 60e3adeb7d..4cb37f6972 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index f4a2a38390..790a920ee6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); diff --git a/docs/concepts-guidelines.md b/docs/concepts-guidelines.md index 4430fc0d36..80d0336286 100644 --- a/docs/concepts-guidelines.md +++ b/docs/concepts-guidelines.md @@ -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 ``` @@ -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 @@ -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 ``` diff --git a/docs/examples.md b/docs/examples.md index 7930e84fce..66973e76a2 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -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 }} ``` diff --git a/docs/updating.md b/docs/updating.md index db64ed332b..980ed5868d 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -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. diff --git a/package-lock.json b/package-lock.json index 9ff13ec589..aa6911ab3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index b758ea4e69..86bb83e168 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 5dafc0d105..cfb60bc2a5 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -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) { diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 367f796c0a..d9c91648fc 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -155,17 +155,22 @@ export class GitCommandManager { return output.exitCode === 1 } - async isDirty(untracked: boolean): Promise { + async isDirty(untracked: boolean, pathspec?: string[]): Promise { + 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 diff --git a/src/main.ts b/src/main.ts index 45a1ae85ea..f3d9171cbe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,9 +12,9 @@ async function run(): Promise { 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 { 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)}`)