Skip to content

Commit 4d88e38

Browse files
committed
Updated More Badges
Signed-off-by: Stephen Williams <stephenw@mindpointgroup.com>
1 parent c41ac38 commit 4d88e38

1 file changed

Lines changed: 58 additions & 30 deletions

File tree

.github/workflows/export-badges.yml

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ on:
1414

1515
jobs:
1616
export:
17-
if: github.event_name == 'workflow_dispatch' || github.ref_name == 'latest'
17+
if: github.event_name == 'workflow_dispatch' || github.ref_name == 'latest' || github.ref_name == 'main'
1818
runs-on: ubuntu-latest
19-
2019
steps:
2120
- name: Create output directory
2221
run: mkdir -p output/badges/${{ inputs.repo_name }}
@@ -27,53 +26,82 @@ jobs:
2726
run: |
2827
OUT_DIR=output/badges/${{ inputs.repo_name }}
2928
30-
default_branch=$(gh repo view ansible-lockdown/${{ inputs.repo_name }} --json defaultBranchRef --jq '.defaultBranchRef.name')
31-
echo '{ "schemaVersion": 1, "label": "Release Branch", "message": "'"$default_branch"'", "color": "brightgreen" }' > $OUT_DIR/release-branch.json
32-
33-
status=$(gh run list -R ansible-lockdown/${{ inputs.repo_name }} --workflow="main_pipeline_validation.yml" --json status,conclusion --jq '.[0] | .status + ":" + .conclusion' || echo "unknown:unknown")
34-
if [[ "$status" == "completed:success" ]]; then
35-
color=green; msg=Passing
36-
elif [[ "$status" == "completed:failure" ]]; then
37-
color=red; msg=Failing
29+
# Determine target branch
30+
if [[ "${{ inputs.repo_name }}" == Private-* ]]; then
31+
echo "Private repo detected. Using 'latest' branch."
32+
branch="latest"
3833
else
39-
color=lightgrey; msg=Unknown
34+
echo "Public repo detected. Using 'main' branch."
35+
branch="main"
4036
fi
41-
echo '{ "schemaVersion": 1, "label": "Remediate Pipeline", "message": "'"$msg"'", "color": "'"$color"'" }' > $OUT_DIR/remediate.json
4237
43-
status=$(gh run list -R ansible-lockdown/${{ inputs.repo_name }} --workflow="main_pipeline_validation_gpo.yml" --json status,conclusion --jq '.[0] | .status + ":" + .conclusion' || echo "unknown:unknown")
44-
if [[ "$status" == "completed:success" ]]; then
45-
color=green; msg=Passing
46-
elif [[ "$status" == "completed:failure" ]]; then
47-
color=red; msg=Failing
48-
else
49-
color=lightgrey; msg=Unknown
38+
# Fetch README content from public/private repo
39+
readme_url="https://raw.githubusercontent.com/ansible-lockdown/${{ inputs.repo_name }}/$branch/README.md"
40+
readme=$(curl -s "$readme_url")
41+
42+
# Extract benchmark version from README
43+
version=$(echo "$readme" | grep -oEi 'Benchmark v[0-9]+(\.[0-9]+)*([rR][0-9]+)?|Version [0-9]+,? ?Rel ?[0-9]+' | head -n1 | sed -E 's/.*(v[0-9]+(\.[0-9]+)*([rR][0-9]+)?|Version [0-9]+,? ?Rel ?[0-9]+).*/\\1/')
44+
[ -z "$version" ] && version="No Belease Yet"
45+
echo "Found Benchmark Version: $version"
46+
47+
# Release branch badge
48+
echo '{ "schemaVersion": 1, "label": "Release Branch", "message": "'$branch'", "color": "brightgreen" }' > $OUT_DIR/release-branch.json
49+
50+
# Badge 1: Benchmark Version (generic)
51+
echo '{ "schemaVersion": 1, "label": "Benchmark Version", "message": "'$version'", "color": "blue" }' > $OUT_DIR/benchmark-version.json
52+
53+
# Private repos get full badges
54+
if [[ "$branch" == "latest" ]]; then
55+
# Remediate pipeline status
56+
status=$(gh run list -R ansible-lockdown/${{ inputs.repo_name }} --workflow="main_pipeline_validation.yml" --json status,conclusion --jq '.[0] | .status + ":" + .conclusion' || echo "unknown:unknown")
57+
if [[ "$status" == "completed:success" ]]; then color=brightgreen; msg=Passing
58+
elif [[ "$status" == "completed:failure" ]]; then color=red; msg=Failing
59+
else color=lightgrey; msg=Unknown; fi
60+
echo '{ "schemaVersion": 1, "label": "Remediate Pipeline", "message": "'$msg'", "color": "'$color'" }' > $OUT_DIR/remediate.json
61+
62+
# GPO pipeline status
63+
status=$(gh run list -R ansible-lockdown/${{ inputs.repo_name }} --workflow="main_pipeline_validation_gpo.yml" --json status,conclusion --jq '.[0] | .status + ":" + .conclusion' || echo "unknown:unknown")
64+
if [[ "$status" == "completed:success" ]]; then color=brightgreen; msg=Passing
65+
elif [[ "$status" == "completed:failure" ]]; then color=red; msg=Failing
66+
else color=lightgrey; msg=Unknown; fi
67+
echo '{ "schemaVersion": 1, "label": "GPO Pipeline", "message": "'$msg'", "color": "'$color'" }' > $OUT_DIR/gpo.json
68+
69+
# Pull Requests
70+
prs=$(gh pr list -R ansible-lockdown/${{ inputs.repo_name }} --json number --jq 'length')
71+
echo '{ "schemaVersion": 1, "label": "Pull Requests", "message": "'$prs'", "color": "blue" }' > $OUT_DIR/prs.json
72+
73+
# Closed Issues
74+
closed=$(gh issue list -R ansible-lockdown/${{ inputs.repo_name }} --state closed --json number --jq 'length')
75+
echo '{ "schemaVersion": 1, "label": "Closed Issues", "message": "'$closed'", "color": "success" }' > $OUT_DIR/issues-closed.json
5076
fi
51-
echo '{ "schemaVersion": 1, "label": "GPO Pipeline", "message": "'"$msg"'", "color": "'"$color"'" }' > $OUT_DIR/gpo.json
52-
53-
prs=$(gh pr list -R ansible-lockdown/${{ inputs.repo_name }} --json number --jq 'length')
54-
echo '{ "schemaVersion": 1, "label": "Pull Requests", "message": "'"$prs"'", "color": "blue" }' > $OUT_DIR/prs.json
55-
56-
closed=$(gh issue list -R ansible-lockdown/${{ inputs.repo_name }} --state closed --json number --jq 'length')
57-
echo '{ "schemaVersion": 1, "label": "Closed Issues", "message": "'"$closed"'", "color": "success" }' > $OUT_DIR/issues-closed.json
5877
5978
- name: Add .nojekyll to prevent GitHub Pages filtering
6079
run: touch output/.nojekyll
6180

62-
- name: Clone and prepare badge folder
81+
- name: Clone and prepare self_hosted branch
6382
run: |
6483
git config --global user.email "actions@github.com"
6584
git config --global user.name "GitHub Actions"
6685
6786
echo "Cloning self_hosted branch of github_windows_IaC..."
6887
git clone --branch self_hosted https://x-access-token:${{ secrets.BADGE_PUSH_TOKEN }}@github.com/ansible-lockdown/github_windows_IaC.git target
6988
70-
echo "Cleaning previous badge data for repo: ${{ inputs.repo_name }}"
71-
rm -rf target/badges/${{ inputs.repo_name }} || true
89+
echo "Ensuring badge folder exists for repo: ${{ inputs.repo_name }}"
7290
mkdir -p target/badges/${{ inputs.repo_name }}
7391
7492
echo "Copying new badge files..."
7593
if [ -d "output/badges/${{ inputs.repo_name }}" ]; then
76-
cp -r output/badges/${{ inputs.repo_name }}/* target/badges/${{ inputs.repo_name }}
94+
for file in output/badges/${{ inputs.repo_name }}/*.json; do
95+
filename=$(basename "$file")
96+
target="target/badges/${{ inputs.repo_name }}/$filename"
97+
98+
if [ -f "$target" ] && cmp -s "$file" "$target"; then
99+
echo "No changes in $filename, skipping copy."
100+
else
101+
cp "$file" "$target"
102+
echo "Updated $filename"
103+
fi
104+
done
77105
else
78106
echo "Warning: No badge output found in output/badges/${{ inputs.repo_name }}"
79107
fi

0 commit comments

Comments
 (0)