-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add file-exists action #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f7bf33
feat: add file-exists action
FidelusAleksander 18d9c5e
chore: add permissions block to test-file-exists-action workflow
FidelusAleksander e21c7da
chore: add matrix strategy for different os in file-exists tests
FidelusAleksander 64d9f6c
docs: add documentation for file-exists action
FidelusAleksander 07cf69e
fix: use path.join for file path construction in file-exists action
FidelusAleksander 57ae774
fix: add missing path import
FidelusAleksander b336511
chore: change fail-fast strategy
FidelusAleksander 50c70dd
fix: ensure main branch is specified for push events in workflow
FidelusAleksander e7ff4d9
refactor: pipe file input through env variable in file-exists action
FidelusAleksander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Test File Exists Action | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "actions/file-exists/**" | ||
| pull_request: | ||
| paths: | ||
| - "actions/file-exists/**" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test-file-exists: | ||
| runs-on: ${{ matrix.os }} | ||
| name: Test File Exists Action (${{ matrix.os }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-latest] | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Test with existing file | ||
| uses: ./actions/file-exists | ||
| with: | ||
| file: README.md | ||
|
|
||
| test-failure-case: | ||
| runs-on: ${{ matrix.os }} | ||
| name: Test File Not Exists (${{ matrix.os }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-latest] | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Test with non-existent file | ||
| uses: ./actions/file-exists | ||
| with: | ||
| file: this-file-does-not-exist.txt | ||
| continue-on-error: true | ||
| id: nonexistent | ||
|
|
||
| - name: Verify action failed as expected | ||
| if: steps.nonexistent.outcome == 'failure' | ||
| run: echo "✅ Action correctly failed when file doesn't exist" | ||
|
|
||
| - name: Fail job if action didn't fail | ||
| if: steps.nonexistent.outcome != 'failure' | ||
| run: | | ||
| echo "❌ Action should have failed but didn't" | ||
| exit 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # File Exists :package: | ||
|
|
||
| A GitHub Action that checks if a file exists in the repository. | ||
|
|
||
| This action will fail if the file does not exist | ||
|
|
||
| ## Inputs ⚙️ | ||
|
|
||
| | Name | Description | Required | | ||
| | ------ | -------------------------------------------------------------- | -------- | | ||
| | `file` | The path to the file to check, relative to the repository root | Yes | | ||
|
|
||
| ## Usage 🚀 | ||
FidelusAleksander marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```yaml | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Check if file exists | ||
| uses: skills/exercise-toolkit/actions/file-exists@<git-tag> | ||
| with: | ||
| file: "path/to/your/file.md" | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: "File Exists" | ||
| description: "Checks if a file exists in the repository" | ||
| inputs: | ||
| file: | ||
| description: "The path to the file to check" | ||
| required: true | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Check if file exists | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| FILE_PATH: ${{ inputs.file }} | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const filePath = path.join(process.env.GITHUB_WORKSPACE, process.env.FILE_PATH); | ||
|
|
||
| if (!fs.existsSync(filePath)) { | ||
| core.setFailed(`❌ File does not exist: ${filePath}`); | ||
FidelusAleksander marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| console.log(`✅ File exists: ${filePath}`); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.