Skip to content

Commit ff88a17

Browse files
committed
chore(docs): add action specific docs
1 parent a23de5e commit ff88a17

14 files changed

Lines changed: 1369 additions & 7 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Check File Exists Action
2+
3+
[![Keyfactor](https://img.shields.io/badge/Keyfactor-yellow?logo=github)](https://github.com/Keyfactor/actions)
4+
[![GitHub Actions](https://img.shields.io/badge/GitHub_Actions-2088FF?logo=github-actions&logoColor=white)](https://github.com/features/actions)
5+
6+
> Checks whether specified files exist in the repository, with support for glob patterns.
7+
8+
| Branding | |
9+
|----------|---|
10+
| Icon | `search` |
11+
| Color | `yellow` |
12+
13+
## Usage
14+
15+
```yaml
16+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
17+
with:
18+
files: "*.config"
19+
```
20+
21+
## Inputs
22+
23+
| Input | Description | Required | Default |
24+
|-------|-------------|----------|---------|
25+
| `files` | File path or glob pattern to check | Yes | - |
26+
| `working-directory` | Directory to search in | No | `.` |
27+
28+
## Outputs
29+
30+
| Output | Description |
31+
|--------|-------------|
32+
| `exists` | `'true'` if any matching files exist, `'false'` otherwise |
33+
| `matched_files` | Space-separated list of matched file paths |
34+
| `count` | Number of matched files |
35+
36+
## Glob Pattern Support
37+
38+
The action supports standard glob patterns:
39+
40+
| Pattern | Matches |
41+
|---------|---------|
42+
| `*.yml` | All `.yml` files in current directory |
43+
| `**/*.yml` | All `.yml` files recursively |
44+
| `.goreleaser.y*ml` | `.goreleaser.yml` or `.goreleaser.yaml` |
45+
| `src/**/*.cs` | All `.cs` files under `src/` |
46+
| `{Dockerfile,*.dockerfile}` | `Dockerfile` or any `.dockerfile` file |
47+
48+
## Examples
49+
50+
### Basic File Check
51+
52+
```yaml
53+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
54+
id: check
55+
with:
56+
files: "Dockerfile"
57+
58+
- run: echo "Dockerfile exists: ${{ steps.check.outputs.exists }}"
59+
```
60+
61+
### Check for GoReleaser Config
62+
63+
```yaml
64+
jobs:
65+
detect:
66+
runs-on: ubuntu-latest
67+
outputs:
68+
has_goreleaser: ${{ steps.check.outputs.exists }}
69+
steps:
70+
- uses: keyfactor/checkout@v4
71+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
72+
id: check
73+
with:
74+
files: ".goreleaser.y*ml"
75+
76+
build-go:
77+
needs: detect
78+
if: needs.detect.outputs.has_goreleaser == 'true'
79+
uses: Keyfactor/actions/.github/workflows/go-build-and-release.yml@v6
80+
```
81+
82+
### Check Multiple File Types
83+
84+
```yaml
85+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
86+
id: csharp-check
87+
with:
88+
files: "**/*.csproj"
89+
90+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
91+
id: go-check
92+
with:
93+
files: "go.mod"
94+
95+
- run: |
96+
echo "Has C# projects: ${{ steps.csharp-check.outputs.exists }}"
97+
echo "Has Go module: ${{ steps.go-check.outputs.exists }}"
98+
```
99+
100+
### Check in Subdirectory
101+
102+
```yaml
103+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
104+
id: check
105+
with:
106+
files: "*.csproj"
107+
working-directory: "src/MyProject"
108+
```
109+
110+
### Use Matched Files
111+
112+
```yaml
113+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
114+
id: check
115+
with:
116+
files: "**/*.sln"
117+
118+
- name: Build all solutions
119+
if: steps.check.outputs.exists == 'true'
120+
run: |
121+
for sln in ${{ steps.check.outputs.matched_files }}; do
122+
echo "Building $sln..."
123+
dotnet build "$sln"
124+
done
125+
```
126+
127+
### Check for Docker Configuration
128+
129+
```yaml
130+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
131+
id: docker-check
132+
with:
133+
files: "{Dockerfile,docker-compose.yml,*.dockerfile}"
134+
135+
- name: Docker build
136+
if: steps.docker-check.outputs.exists == 'true'
137+
run: docker build -t myapp .
138+
```
139+
140+
### Count Matched Files
141+
142+
```yaml
143+
- uses: Keyfactor/actions/.github/actions/check-file-exists@v6
144+
id: check
145+
with:
146+
files: "**/*.test.js"
147+
148+
- run: echo "Found ${{ steps.check.outputs.count }} test files"
149+
```
150+
151+
## Requirements
152+
153+
- Repository must be checked out before running this action
154+
- Bash shell (available on all GitHub-hosted runners)
155+
156+
## Implementation Details
157+
158+
The action uses bash glob expansion with `nullglob` and `globstar` options:
159+
- `nullglob`: Returns empty if no matches (instead of literal pattern)
160+
- `globstar`: Enables `**` for recursive matching
161+
162+
## Related Actions
163+
164+
- [detect-language](../detect-language/) - Detect repository language
165+
- [parse-manifest](../parse-manifest/) - Parse integration-manifest.json

.github/actions/check-file-exists/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: 'Check File Exists'
2-
description: 'Checks if one or more files exist, supporting glob patterns'
2+
description: 'Checks if one or more files exist in the repository, with support for glob patterns'
3+
author: 'Keyfactor'
4+
5+
branding:
6+
icon: 'search'
7+
color: 'yellow'
38

49
inputs:
510
files:
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Detect Language Action
2+
3+
[![Keyfactor](https://img.shields.io/badge/Keyfactor-blue?logo=github)](https://github.com/Keyfactor/actions)
4+
[![GitHub Actions](https://img.shields.io/badge/GitHub_Actions-2088FF?logo=github-actions&logoColor=white)](https://github.com/features/actions)
5+
6+
> Detects the primary programming language of a repository using the GitHub Linguist API with file extension fallback.
7+
8+
| Branding | |
9+
|----------|---|
10+
| Icon | `code` |
11+
| Color | `blue` |
12+
13+
## Usage
14+
15+
```yaml
16+
- uses: Keyfactor/actions/.github/actions/detect-language@v6
17+
```
18+
19+
## Inputs
20+
21+
This action has no inputs. It automatically detects the repository language.
22+
23+
## Outputs
24+
25+
| Output | Description |
26+
|--------|-------------|
27+
| `primary_language` | The detected primary language (lowercase): `csharp`, `go`, `java`, or `unknown` |
28+
| `is_csharp` | `'true'` if the primary language is C# |
29+
| `is_go` | `'true'` if the primary language is Go |
30+
| `is_java` | `'true'` if the primary language is Java |
31+
32+
## Detection Logic
33+
34+
1. **GitHub Linguist API** (primary method):
35+
- Queries `GET /repos/{owner}/{repo}/languages`
36+
- Uses the language with the highest byte count
37+
- Maps language names to normalized identifiers
38+
39+
2. **File Extension Fallback** (if API fails):
40+
- `.csproj`, `.cs` → `csharp`
41+
- `.go`, `go.mod` → `go`
42+
- `.java`, `pom.xml` → `java`
43+
44+
## Language Mapping
45+
46+
| GitHub Linguist | Output Value |
47+
|-----------------|--------------|
48+
| C# | `csharp` |
49+
| Go | `go` |
50+
| Java | `java` |
51+
| Other | `unknown` |
52+
53+
## Examples
54+
55+
### Basic Usage
56+
57+
```yaml
58+
jobs:
59+
detect:
60+
runs-on: ubuntu-latest
61+
outputs:
62+
language: ${{ steps.detect.outputs.primary_language }}
63+
steps:
64+
- uses: keyfactor/checkout@v4
65+
- uses: Keyfactor/actions/.github/actions/detect-language@v6
66+
id: detect
67+
- run: echo "Detected language: ${{ steps.detect.outputs.primary_language }}"
68+
```
69+
70+
### Conditional Job Execution
71+
72+
```yaml
73+
jobs:
74+
detect:
75+
runs-on: ubuntu-latest
76+
outputs:
77+
is_go: ${{ steps.detect.outputs.is_go }}
78+
steps:
79+
- uses: keyfactor/checkout@v4
80+
- uses: Keyfactor/actions/.github/actions/detect-language@v6
81+
id: detect
82+
83+
build-go:
84+
needs: detect
85+
if: needs.detect.outputs.is_go == 'true'
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: keyfactor/checkout@v4
89+
- run: go build ./...
90+
```
91+
92+
### Multi-Language Build Matrix
93+
94+
```yaml
95+
jobs:
96+
detect:
97+
runs-on: ubuntu-latest
98+
outputs:
99+
primary_language: ${{ steps.detect.outputs.primary_language }}
100+
is_csharp: ${{ steps.detect.outputs.is_csharp }}
101+
is_go: ${{ steps.detect.outputs.is_go }}
102+
is_java: ${{ steps.detect.outputs.is_java }}
103+
steps:
104+
- uses: keyfactor/checkout@v4
105+
- uses: Keyfactor/actions/.github/actions/detect-language@v6
106+
id: detect
107+
108+
build:
109+
needs: detect
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: keyfactor/checkout@v4
113+
114+
- name: Build C#
115+
if: needs.detect.outputs.is_csharp == 'true'
116+
run: dotnet build
117+
118+
- name: Build Go
119+
if: needs.detect.outputs.is_go == 'true'
120+
run: go build ./...
121+
122+
- name: Build Java
123+
if: needs.detect.outputs.is_java == 'true'
124+
run: mvn package
125+
```
126+
127+
## Requirements
128+
129+
- Repository must be checked out before running this action
130+
- `GITHUB_TOKEN` must have `contents: read` permission (default)
131+
132+
## Related Actions
133+
134+
- [parse-manifest](../parse-manifest/) - Parse integration-manifest.json
135+
- [setup-dotnet](../setup-dotnet/) - Setup .NET environment
136+
- [setup-go](../setup-go/) - Setup Go environment
137+
- [setup-java](../setup-java/) - Setup Java environment

.github/actions/detect-language/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: 'Detect Primary Language'
2-
description: 'Detects the primary programming language of the repository'
2+
description: 'Detects the primary programming language of the repository using GitHub API with file extension fallback'
3+
author: 'Keyfactor'
4+
5+
branding:
6+
icon: 'code'
7+
color: 'blue'
38

49
inputs:
510
token:

0 commit comments

Comments
 (0)