Skip to content

Commit

Permalink
Merge pull request #199 from actions/jcambass/2024-09-16/do-not-check…
Browse files Browse the repository at this point in the history
…-for-action-yml

Do not assume action.yml exists
  • Loading branch information
Jcambass authored Sep 16, 2024
2 parents d34ce15 + 2acc8d8 commit 4b1aa5c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: actions/checkout@v4
- name: Publish
id: publish
uses: actions/publish-immutable-action@0.0.2
uses: actions/publish-immutable-action@0.0.3
```
<!-- end usage -->
Expand Down
23 changes: 0 additions & 23 deletions __tests__/fs-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ describe('stageActionFiles', () => {
fs.rmSync(stagingDir, { recursive: true })
})

it('returns an error if no action.yml file is present', () => {
expect(() => fsHelper.stageActionFiles(sourceDir, stagingDir)).toThrow(
/^No action.yml or action.yaml file found in source repository/
)
})

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

Expand All @@ -50,23 +44,6 @@ describe('stageActionFiles', () => {
// .git folder is not copied
expect(fs.existsSync(`${stagingDir}/.git`)).toBe(false)
})

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)

fsHelper.stageActionFiles(sourceDir, stagingDir)
expect(fs.existsSync(`${stagingDir}/src/main.js`)).toBe(true)
expect(fs.existsSync(`${stagingDir}/src/other.js`)).toBe(true)
expect(fs.existsSync(`${stagingDir}/my-sub-action/action.yml`)).toBe(true)
})

it('accepts action.yaml as a valid action file as well as action.yml', () => {
fs.writeFileSync(`${sourceDir}/action.yaml`, fileContent)

fsHelper.stageActionFiles(sourceDir, stagingDir)
expect(fs.existsSync(`${stagingDir}/action.yaml`)).toBe(true)
})
})

describe('createArchives', () => {
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.
8 changes: 0 additions & 8 deletions dist/index.js

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

13 changes: 0 additions & 13 deletions src/fs-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,11 @@ export function readFileContents(filePath: string): Buffer {
}

// 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

fsExtra.copySync(actionDir, targetDir, {
filter: (src: string) => {
const basename = path.basename(src)

if (basename === 'action.yml' || basename === 'action.yaml') {
actionYmlFound = true
}

// Filter out the .git folder.
if (basename === '.git') {
return false
Expand All @@ -111,12 +104,6 @@ export function stageActionFiles(actionDir: string, targetDir: string): void {
return true
}
})

if (!actionYmlFound) {
throw new Error(
`No action.yml or action.yaml file found in source repository`
)
}
}

// Ensure the correct SHA is checked out for the tag by inspecting the git metadata in the workspace
Expand Down

0 comments on commit 4b1aa5c

Please sign in to comment.