File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Test File Exists Action
2+
3+ on :
4+ push :
5+ paths :
6+ - ' actions/file-exists/**'
7+ pull_request :
8+ paths :
9+ - ' actions/file-exists/**'
10+
11+ jobs :
12+ test-file-exists :
13+ runs-on : ubuntu-latest
14+ name : Test File Exists Action
15+ steps :
16+ - name : Checkout repository
17+ uses : actions/checkout@v4
18+
19+ - name : Test with existing file
20+ uses : ./actions/file-exists
21+ with :
22+ file : README.md
23+
24+ test-failure-case :
25+ runs-on : ubuntu-latest
26+ name : Test File Not Exists (Should Fail)
27+ steps :
28+ - name : Checkout repository
29+ uses : actions/checkout@v4
30+
31+ - name : Test with non-existent file
32+ uses : ./actions/file-exists
33+ with :
34+ file : this-file-does-not-exist.txt
35+ continue-on-error : true
36+ id : nonexistent
37+
38+ - name : Verify action failed as expected
39+ if : steps.nonexistent.outcome == 'failure'
40+ run : echo "✅ Action correctly failed when file doesn't exist"
41+
42+ - name : Fail job if action didn't fail
43+ if : steps.nonexistent.outcome != 'failure'
44+ run : |
45+ echo "❌ Action should have failed but didn't"
46+ exit 1
Original file line number Diff line number Diff line change 1+ name : " File Exists"
2+ description : " Checks if a file exists in the repository"
3+ inputs :
4+ file :
5+ description : " The path to the file to check"
6+ required : true
7+ runs :
8+ using : " composite"
9+ steps :
10+ - name : Check if file exists
11+ uses : actions/github-script@v7
12+ with :
13+ script : |
14+ const fs = require('fs');
15+ const filePath = process.env.GITHUB_WORKSPACE + '/' + '${{ inputs.file }}';
16+
17+ if (!fs.existsSync(filePath)) {
18+ core.setFailed(`❌ File does not exist: ${filePath}`);
19+ return;
20+ }
21+
22+ console.log(`✅ File exists: ${filePath}`);
You can’t perform that action at this time.
0 commit comments