Skip to content

Commit 141581b

Browse files
committed
Generate analysis results references documentation
1 parent 4da7f9e commit 141581b

File tree

5 files changed

+264
-0
lines changed

5 files changed

+264
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# Generates "CSV_REPORTS.md" containing a reference to all CSV cypher query reports in this directory and its subdirectories.
4+
5+
# Note: This script was generated by Chat-GPT after some messages back and forth:
6+
# https://chat.openai.com/share/0bd3cde7-32d0-460d-830c-79b7d00a2492
7+
8+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
9+
set -o errexit -o pipefail
10+
11+
# Output Markdown file name
12+
markdown_file="CSV_REPORTS.md"
13+
14+
# Function to count rows in a CSV file
15+
count_rows() {
16+
wc -l < "$1"
17+
}
18+
19+
# Function to extract the source query name from CSV header
20+
get_source_query() {
21+
header=$(head -n 1 "$1")
22+
source_query=$(echo "$header" | sed -n 's/.*Source Cypher File: \(.*\)"/\1/p')
23+
echo "$source_query"
24+
}
25+
26+
echo "generateCsvReportReference: Generating ${markdown_file}..."
27+
28+
# Create the Markdown header
29+
{
30+
echo "# CSV Cypher Query Reports Reference"
31+
echo ""
32+
echo "This document serves as a reference for all CSV Cypher query reports in the current directory and its subdirectories. It provides a table listing each file, its corresponding analysis, the row count and the source query. This file was generated with the script [generateCsvReportsReference](./../scripts/documentation/generateCsvReportsReference.sh)."
33+
echo ""
34+
35+
# Create the Markdown table header
36+
echo "| CSV File | Analysis | Number of Rows | Source Query |"
37+
echo "| -------- | -------- | -------------- | ------------ |"
38+
} > "$markdown_file"
39+
40+
# Find and process CSV files
41+
find . -type f -name "*.csv" | sort | while IFS= read -r csv_file; do
42+
num_rows=$(count_rows "$csv_file")
43+
source_query=$(get_source_query "$csv_file")
44+
45+
# Get the main directory name
46+
main_dir=$(dirname "$csv_file" | cut -d '/' -f 2)
47+
48+
# Get the base name of the file
49+
base_name=$(basename "$csv_file")
50+
51+
# Escape special characters for Markdown
52+
csv_link=$(echo "$csv_file" | sed 's/\[/\\[/g; s/\]/\\]/g')
53+
54+
# Create a link to the source query
55+
source_query_link="./../cypher/$source_query"
56+
57+
# Append a new row to the Markdown table
58+
echo "| [$base_name]($csv_link) | $main_dir | $num_rows | [$source_query]($source_query_link) |" >> "$markdown_file"
59+
done
60+
61+
echo "generateCsvReportReference: Successfully generated ${markdown_file}."
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
# Generates "IMAGES.md" containing a reference to all images (PNG) in this directory and its subdirectories.
4+
5+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
6+
set -o errexit -o pipefail
7+
8+
# Markdown file name
9+
markdown_file="IMAGES.md"
10+
11+
echo "generateImageReference: Generating ${markdown_file}..."
12+
13+
{
14+
echo "# Image Reference"
15+
echo ""
16+
echo "This document serves as a reference for all images (PNG) in the current directory and its subdirectories."
17+
echo "It provides a table listing each file and the analysis it belongs to."
18+
echo "This file was generated with the script [generateImageReference.sh](./../scripts/documentation/generateImageReference.sh)."
19+
echo ""
20+
echo "Image | Analysis |"
21+
echo "-------|----------|"
22+
} > ${markdown_file}
23+
24+
# Loop through all Markdown files in the current directory
25+
find . -type f -name "*.png" | sort | while read -r image_file; do
26+
# Trim leading and trailing whitespace
27+
description=$(echo "${description}" | awk '{$1=$1;print}')
28+
29+
# Extract the script file name without the path
30+
filename=$(basename "$image_file")
31+
32+
if [ "$filename" = "${markdown_file}" ]; then
33+
continue
34+
fi
35+
36+
# Extract the script file path without the name
37+
pathname=$(dirname "$image_file")
38+
39+
# Extract the second part of the path after ./ that contains the analysis directory name
40+
analysisname=$(echo "${pathname}" | cut -d/ -f2)
41+
42+
# Create a link to the script file in the table
43+
link="[${filename}](${image_file})"
44+
45+
# Add the script file and its description to the Markdown table
46+
echo "| ${link} | ${analysisname%%.} |" >> ${markdown_file}
47+
done
48+
49+
echo "generateImageReference: Successfully generated ${markdown_file}."
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# Generates "JUPYTER_REPORTS.md" containing a reference to all Jupyter Notebook Markdown reports in this directory and its subdirectories.
4+
# This script was generated by Chat-GPT after some messages back and forth and then tuned manually.
5+
6+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
7+
set -o errexit -o pipefail
8+
9+
# Markdown file name
10+
markdown_file="JUPYTER_REPORTS.md"
11+
12+
echo "generateJupyterReportReference: Generating ${markdown_file}..."
13+
14+
{
15+
echo "# Jupyter Notebook Reports Reference"
16+
echo ""
17+
echo "This document serves as a reference for all Jupyter Notebook reports in the current directory and its subdirectories."
18+
echo "It provides a table listing each file and its corresponding description found in the first header line."
19+
echo "This file was generated with the script [generateMarkdownReference.sh](./../scripts/documentation/generateMarkdownReference.sh)."
20+
echo ""
21+
echo "Report | Analysis | Description"
22+
echo "-------|----------|------------"
23+
} > ${markdown_file}
24+
25+
# Loop through all Markdown files in the current directory
26+
find . -type f -name "*.md" | sort | while read -r report_file; do
27+
# Extract the first non-empty line that starts with '#'
28+
report_file_header_line=$(grep -m 1 -e '^#\+.*' "${report_file}")
29+
30+
# Remove leading '#' characters and trim leading/trailing spaces
31+
description=$(echo "${report_file_header_line}" | sed -E 's/^#+\s*//')
32+
33+
# Trim leading and trailing whitespace
34+
description=$(echo "${description}" | awk '{$1=$1;print}')
35+
36+
# Extract the script file name without the path
37+
filename=$(basename "$report_file")
38+
39+
if [ "$filename" = "${markdown_file}" ]; then
40+
continue
41+
fi
42+
43+
# Extract the script file path without the name
44+
pathname=$(dirname "$report_file")
45+
46+
# Extract the second part of the path after ./ that contains the analysis directory name
47+
analysisname=$(echo "${pathname}" | cut -d/ -f2)
48+
49+
# Create a link to the script file in the table
50+
link="[${filename}](${report_file})"
51+
52+
# Add the script file and its description to the Markdown table
53+
echo "| ${link} | ${analysisname%%.} | ${description} |" >> ${markdown_file}
54+
done
55+
56+
echo "generateJupyterReportReference: Successfully generated ${markdown_file}."
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# Triggers the regeneration of all reference documentations for the reports inside the "results" directory.
4+
# The generation to the reference documentations is delegated to the dedicated scripts.
5+
6+
# Notice that this scripts needs to be executed within the "results" directory.
7+
8+
# Requires generateJupyterReportReference.sh, generateCsvReportReference.sh, generateImageReference.sh
9+
10+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
11+
set -o errexit -o pipefail
12+
13+
## Get this "scripts" directory if not already set
14+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
15+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
16+
# This way non-standard tools like readlink aren't needed.
17+
DOCUMENTATION_SCRIPT_DIR=${DOCUMENTATION_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
18+
echo "generateReportReferences: SCRIPTS_DIR=${DOCUMENTATION_SCRIPT_DIR}"
19+
20+
# Generate JUPYTER_REPORTS.md containing a reference to all Jupyter Notebook Markdown reports in the "results" directory and its subdirectories.
21+
source "${DOCUMENTATION_SCRIPT_DIR}/generateJupyterReportReference.sh"
22+
23+
# Generate CSV_REPORTS.md containing a reference to all CSV cypher query reports in the "results" directory and its subdirectories.
24+
source "${DOCUMENTATION_SCRIPT_DIR}/generateCsvReportReference.sh"
25+
26+
# Generate IMAGES.md containing a reference to all PNG images in the "results" directory and its subdirectories.
27+
source "${DOCUMENTATION_SCRIPT_DIR}/generateImageReference.sh"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Generate report reference documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "analysis-results/**" # Only run on changed analysis results
9+
- "!analysis-results/*.md" # Ignore report reference documentation changes (endless loop prevention)
10+
- ".github/workflows/internal-report-reference-documentation.yml" # Also run when this file was changed
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- "analysis-results/**" # Only run on changed analysis results
16+
- "!analysis-results/*.md" # Ignore report reference documentation changes (endless loop prevention)
17+
- ".github/workflows/internal-report-reference-documentation.yml" # Also run when this file was changed
18+
19+
jobs:
20+
generate-report-reference-documentation:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
generated_documents_changed: ${{ steps.set-generated_documents_changed.outputs.generated_documents_changed }}
24+
documentation-upload-name: ${{ steps.set-documentation-upload-name.outputs.documentation-upload-name }}
25+
26+
steps:
27+
- name: Checkout git repository
28+
uses: actions/checkout@v4
29+
30+
- name: Generate report reference document
31+
working-directory: analysis-results
32+
run: |
33+
./../documentation/analysis-reports-reference/generateReportReferences.sh
34+
35+
- name: Use git to detect changes in the regenerated documentation and set generated_documents_changed
36+
id: set-generated_documents_changed
37+
run: git diff --quiet || echo "generated_documents_changed=true" >> "$GITHUB_OUTPUT"
38+
39+
- name: Display generated_documents_changed
40+
run: echo "generated_documents_changed=${{ steps.set-generated_documents_changed.outputs.generated_documents_changed }}"
41+
42+
- name: Generate ARTIFACT_UPLOAD_ID
43+
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
44+
45+
- name: Set documentation-upload-name
46+
id: set-documentation-upload-name
47+
run: echo "documentation-upload-name=report-reference-documentation-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
48+
49+
- name: Archive generated report references documents
50+
if: steps.set-generated_documents_changed.outputs.generated_documents_changed == 'true'
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: report-reference-documentation
54+
path: ./analysis-results/*.md
55+
if-no-files-found: error
56+
retention-days: 5
57+
58+
59+
commit-analysis-results:
60+
name: Commit Analysis Results
61+
needs: [generate-report-reference-documentation]
62+
uses: ./.github/workflows/internal-commit-results.yml
63+
if: needs.generate-report-reference-documentation.outputs.generated_documents_changed == 'true'
64+
with:
65+
commit-author-name: "${{ github.event.repository.name }} Continuous Integration"
66+
commit-author-email: "7671054+JohT@users.noreply.github.com"
67+
commit-message: "Automated code structure analysis results (CI)"
68+
commit-directory: "./analysis-results/*.md"
69+
uploaded-artifact-name: ${{ needs.generate-report-reference-documentation.outputs.documentation-upload-name }}
70+
secrets:
71+
repository-commit-token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}

0 commit comments

Comments
 (0)