Unverified Commit 3412bb46 authored by Josh Gross's avatar Josh Gross
Browse files

Exclude the `.git` directory by default

parent 834a144e
Loading
Loading
Loading
Loading
+26
Changes for README.md: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ See also [download-artifact](https://github.com/actions/download-artifact).
    - [Breaking Changes](#breaking-changes)
  - [Usage](#usage)
    - [Inputs](#inputs)
      - [Uploading the `.git` directory](#uploading-the-git-directory)
    - [Outputs](#outputs)
  - [Examples](#examples)
    - [Upload an Individual File](#upload-an-individual-file)
@@ -64,6 +65,7 @@ There is also a new sub-action, `actions/upload-artifact/merge`. For more info,
    Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you _will_ encounter an error.

3. Limit of Artifacts for an individual job. Each job in a workflow run now has a limit of 500 artifacts.
4. With `v4.4` and later, the `.git` directory is excluded by default.

For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).

@@ -109,6 +111,30 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
    overwrite:
```

#### Uploading the `.git` directory

By default, files in a `.git` directory are ignored in the uploaded artifact.
This is intended to prevent accidentally uploading Git credentials into an artifact that could then
be extracted.
If files in the `.git` directory are needed, ensure that `actions/checkout` is being used with
`persist-credentials: false`.

```yaml
jobs:
  upload:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false # Ensure credentials are not saved in `.git/config`

      - uses: actions/upload-artifact@v4
        with:
          path: .
          include-git-directory: true
```

### Outputs

| Name | Description | Example |
+37
Changes for __tests__/search.test.ts: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -61,6 +61,12 @@ const lonelyFilePath = path.join(
  'lonely-file.txt'
)

const gitConfigPath = path.join(root, '.git', 'config')
const gitHeadPath = path.join(root, '.git', 'HEAD')

const nestedGitConfigPath = path.join(root, 'repository-name', '.git', 'config')
const nestedGitHeadPath = path.join(root, 'repository-name', '.git', 'HEAD')

describe('Search', () => {
  beforeAll(async () => {
    // mock all output so that there is less noise when running tests
@@ -93,6 +99,11 @@ describe('Search', () => {
      recursive: true
    })

    await fs.mkdir(path.join(root, '.git'))
    await fs.mkdir(path.join(root, 'repository-name', '.git'), {
      recursive: true
    })

    await fs.writeFile(searchItem1Path, 'search item1 file')
    await fs.writeFile(searchItem2Path, 'search item2 file')
    await fs.writeFile(searchItem3Path, 'search item3 file')
@@ -110,9 +121,17 @@ describe('Search', () => {
    await fs.writeFile(amazingFileInFolderHPath, 'amazing file')

    await fs.writeFile(lonelyFilePath, 'all by itself')

    await fs.writeFile(gitConfigPath, 'git config file')
    await fs.writeFile(gitHeadPath, 'git head file')
    await fs.writeFile(nestedGitConfigPath, 'nested git config file')
    await fs.writeFile(nestedGitHeadPath, 'nested git head file')
    /*
      Directory structure of files that get created:
      root/
          .git/
              config
              HEAD
          folder-a/
              folder-b/
                  folder-c/
@@ -136,6 +155,10 @@ describe('Search', () => {
              folder-j/
                  folder-k/
                      lonely-file.txt
          repository-name/
            .git/
                config
                HEAD
          search-item5.txt
    */
  })
@@ -352,4 +375,18 @@ describe('Search', () => {
    )
    expect(searchResult.filesToUpload.includes(lonelyFilePath)).toEqual(true)
  })

  it('Excludes .git directory by default', async () => {
    const searchResult = await findFilesToUpload(root)
    expect(searchResult.filesToUpload.length).toEqual(13)
    expect(searchResult.filesToUpload).not.toContain(gitConfigPath)
  })

  it('Includes .git directory when includeGitDirectory is true', async () => {
    const searchResult = await findFilesToUpload(root, {
      includeGitDirectory: true
    })
    expect(searchResult.filesToUpload.length).toEqual(17)
    expect(searchResult.filesToUpload).toContain(gitConfigPath)
  })
})
+3
Changes for action.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ inputs:
      If false, the action will fail if an artifact for the given name already exists.
      Does not fail if the artifact does not exist.
    default: 'false'
  include-git-directory:
    description: 'Include files in the .git directory in the artifact.'
    default: 'false'

outputs:
  artifact-id:
+116 −52

File changed.

Preview size limit exceeded, changes collapsed.

+116 −52

File changed.

Preview size limit exceeded, changes collapsed.

Loading