Skip to content

Commit

Permalink
Merge pull request #189 from actions/jcambass/2024-09-03/only-exclude…
Browse files Browse the repository at this point in the history
…-git-folder

Only Exclude .git Folder
  • Loading branch information
Jcambass authored Sep 3, 2024
2 parents 49e9053 + 8753087 commit b080e88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions __tests__/fs-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('stageActionFiles', () => {
)
})

it('copies all non-hidden files to the staging directory', () => {
it('copies all files (excluding the .git folder) to the staging directory', () => {
fs.writeFileSync(`${sourceDir}/action.yml`, fileContent)

fs.mkdirSync(`${sourceDir}/.git`)
Expand All @@ -44,12 +44,14 @@ describe('stageActionFiles', () => {
expect(fs.existsSync(`${stagingDir}/src/main.js`)).toBe(true)
expect(fs.existsSync(`${stagingDir}/src/other.js`)).toBe(true)

// Hidden files should not be copied
// Hidden files are copied
expect(fs.existsSync(`${stagingDir}/.github`)).toBe(true)

// .git folder is not copied
expect(fs.existsSync(`${stagingDir}/.git`)).toBe(false)
expect(fs.existsSync(`${stagingDir}/.github`)).toBe(false)
})

it('copies all non-hidden files to the staging directory, even if action.yml is in a subdirectory', () => {
it('copies all files (excluding the .git folder) to the staging directory, even if action.yml is in a subdirectory', () => {
fs.mkdirSync(`${sourceDir}/my-sub-action`, { recursive: true })
fs.writeFileSync(`${sourceDir}/my-sub-action/action.yml`, fileContent)

Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/fs-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function readFileContents(filePath: string): Buffer {
return fs.readFileSync(filePath)
}

// Copy actions files from sourceDir to targetDir, excluding files and folders not relevant to the action
// Copy actions files from sourceDir to targetDir, excluding the .git folder.
// Errors if the repo appears to not contain any action files, such as an action.yml file
export function stageActionFiles(actionDir: string, targetDir: string): void {
let actionYmlFound = false
Expand All @@ -103,8 +103,12 @@ export function stageActionFiles(actionDir: string, targetDir: string): void {
actionYmlFound = true
}

// Filter out hidden folers like .git and .github
return basename === '.' || !basename.startsWith('.')
// Filter out the .git folder.
if (basename === '.git') {
return false
}

return true
}
})

Expand Down

0 comments on commit b080e88

Please sign in to comment.