-
Notifications
You must be signed in to change notification settings - Fork 11
76 lines (73 loc) · 2.98 KB
/
find-dockerfile.yml
File metadata and controls
76 lines (73 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Check Dockerfile in All Repositories
on:
workflow_dispatch:
inputs:
username:
description: 'GitHub Username'
required: true
branch:
description: 'Branch to check for Dockerfile'
required: true
jobs:
check-repos:
runs-on: ubuntu-latest
steps:
# Install jq for JSON parsing
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
# Fetch all repositories for the GitHub user
- name: Get repositories for the GitHub user
id: get-repos
run: |
USERNAME=${{ github.event.inputs.username }}
# Fetch all repositories, handling pagination
page=1
> repos_list.txt
while : ; do
repos=$(curl -s -H "Authorization: Bearer ${{ secrets.ACTION_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/users/$USERNAME/repos?per_page=100&page=$page")
if [[ $(echo "$repos" | jq '. | length') -eq 0 ]]; then
break
fi
echo "$repos" | jq -r '.[].full_name' >> repos_list.txt
((page++))
done
# Check for Dockerfile in each repository
- name: Check Dockerfile in each repository
run: |
BRANCH=${{ github.event.inputs.branch }}
# Initialize results file
echo "Dockerfile Check Results for ${{ github.event.inputs.username }} on Branch $BRANCH" > results.txt
while IFS= read -r repo; do
echo "Checking repository: $repo on branch: $BRANCH..."
# Check if branch exists
branch_check=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.ACTION_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$repo/branches/$BRANCH")
if [[ "$branch_check" -ne 200 ]]; then
echo "$repo: Branch $BRANCH NOT found (HTTP $branch_check)." >> results.txt
continue
fi
# Fetch the full tree recursively
tree_response=$(curl -s -H "Authorization: Bearer ${{ secrets.ACTION_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$repo/git/trees/$BRANCH?recursive=1")
# Parse and log all Dockerfile paths
dockerfile_paths=$(echo "$tree_response" | jq -r '.tree[] | select(.path | test("(?i)Dockerfile$")) | .path')
if [[ -n "$dockerfile_paths" ]]; then
for path in $dockerfile_paths; do
echo "$repo: Dockerfile FOUND at $path" >> results.txt
done
else
echo "$repo: Dockerfile NOT found" >> results.txt
fi
done < repos_list.txt
# Upload results as an artifact
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: dockerfile-check-results
path: results.txt