Skip to content

Commit b1df11a

Browse files
committed
Provide a common code graph analysis workflow for GitHub
1 parent 7a0276a commit b1df11a

File tree

2 files changed

+223
-89
lines changed

2 files changed

+223
-89
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Analyze Code Graph
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
analysis-name:
7+
description: "The name of the project to analyze. E.g. MyProject-1.0.0"
8+
required: true
9+
type: string
10+
# TODO: Split upload into one for source code folders and one for artifacts like Java JARs
11+
uploaded-artifact-name:
12+
description: "The name of the artifact uploaded with 'actions/upload-artifact' containing the 'source' and 'artifacts' directory with the contents to analyze."
13+
required: true
14+
type: string
15+
outputs:
16+
uploaded-analysis-results:
17+
description: "The name of the artifact uploaded with 'actions/upload-artifact' containing the analysis results."
18+
value: ${{ jobs.analyze-code-graph.outputs.uploaded-analysis-results-artifact-name }}
19+
20+
jobs:
21+
analyze-code-graph:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
uploaded-analysis-results-artifact-name: ${{ steps.set-analysis-results-artifact-name.outputs.uploaded-analysis-results-artifact-name }}
25+
strategy:
26+
matrix:
27+
include:
28+
- os: ubuntu-latest
29+
java: 17
30+
python: 3.11
31+
miniforge: 24.9.0-0
32+
steps:
33+
- name: Checkout code-graph-analysis-pipeline
34+
uses: actions/checkout@v4
35+
with:
36+
repository: JohT/code-graph-analysis-pipeline
37+
ref: 41f3e22b5bd65351474dd23effeee91fab849a12
38+
path: code-graph-analysis-pipeline
39+
persist-credentials: false
40+
41+
- name: (Java Setup) Java Development Kit (JDK) ${{ matrix.java }}
42+
uses: actions/setup-java@v4
43+
with:
44+
distribution: "temurin"
45+
java-version: ${{ matrix.java }}
46+
47+
# "Setup Python" can be skipped if jupyter notebook analysis-results aren't needed
48+
- name: (Python Setup) Setup Cache for Conda package manager Miniforge
49+
uses: actions/cache@v4
50+
env:
51+
# Increase this value to reset cache if etc/example-environment.yml has not changed
52+
# Reference: https://github.com/conda-incubator/setup-miniconda#caching
53+
CACHE_NUMBER: 0
54+
with:
55+
path: ~/conda_pkgs_dir
56+
key:
57+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-environments-${{hashFiles('**/environment.yml', '.github/workflows/*.yml') }}
58+
59+
- name: (Python Setup) Use version ${{ matrix.python }} with Conda package manager Miniforge
60+
uses: conda-incubator/setup-miniconda@v3
61+
with:
62+
python-version: ${{ matrix.python }}
63+
miniforge-version: ${{ matrix.miniforge }}
64+
activate-environment: codegraph
65+
environment-file: ./code-graph-analysis-pipeline/jupyter/environment.yml
66+
auto-activate-base: false
67+
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
68+
- name: (Python Setup) Conda environment info
69+
shell: bash -el {0}
70+
run: conda info
71+
72+
- name: (Code Analysis Setup) Add code-graph-analysis-pipeline temporarily to .gitignore
73+
shell: bash
74+
run: |
75+
echo "" >> .gitignore
76+
echo "# Code Graph Analysis Pipeline" >> .gitignore
77+
echo "code-graph-analysis-pipeline/" >> .gitignore
78+
79+
- name: (Code Analysis Setup) Setup Cache Analysis Downloads
80+
uses: actions/cache@v4
81+
with:
82+
path: ./code-graph-analysis-pipeline/temp/downloads
83+
key:
84+
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
85+
86+
- name: (Code Analysis Setup) Generate Neo4j Initial Password
87+
id: generate-neo4j-initial-password
88+
shell: bash
89+
run: |
90+
generated_password=$( LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c 12; echo )
91+
echo "::add-mask::$generated_password"
92+
echo "neo4j-initial-password=$generated_password" >> "$GITHUB_OUTPUT"
93+
94+
- name: (Code Analysis Setup) Initialize Analysis
95+
shell: bash
96+
working-directory: code-graph-analysis-pipeline
97+
env:
98+
NEO4J_INITIAL_PASSWORD: ${{ steps.generate-neo4j-initial-password.outputs.neo4j-initial-password }}
99+
run: ./init.sh ${{ inputs.analysis-name }}
100+
101+
- name: (Code Analysis Setup) Download source code and artifacts for analysis
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: ${{ inputs.uploaded-artifact-name }}
105+
path: code-graph-analysis-pipeline/temp/${{ inputs.analysis-name }}/source/${{ inputs.analysis-name }}
106+
107+
- name: (Code Analysis) Analyze ${{ inputs.analysis-name }}
108+
working-directory: code-graph-analysis-pipeline/temp/${{ inputs.analysis-name }}
109+
# Shell type can be skipped if jupyter notebook analysis-results (and therefore conda) aren't needed
110+
shell: bash -el {0}
111+
env:
112+
NEO4J_INITIAL_PASSWORD: ${{ steps.generate-neo4j-initial-password.outputs.neo4j-initial-password }}
113+
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
114+
IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT: "" # Options: "none", "aggregated", "full". default = "plugin" or ""
115+
run: |
116+
./../../scripts/analysis/analyze.sh --profile Neo4jv5-low-memory
117+
118+
- name: Assemble ENVIRONMENT_INFO
119+
run: echo "ENVIRONMENT_INFO=-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}" >> $GITHUB_ENV
120+
121+
- name: Set artifact name for uploaded analysis results
122+
id: set-analysis-results-artifact-name
123+
run: echo "uploaded-analysis-results-artifact-name=code-analysis-results-java-${{ env.ENVIRONMENT_INFO }}" >> $GITHUB_OUTPUT
124+
125+
# Upload logs and unfinished analysis-results in case of an error for troubleshooting
126+
- name: (Code Analysis Results) Archive failed run with logs and unfinished analysis-results
127+
if: failure()
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: java-code-analysis-logs-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
131+
path: |
132+
./code-graph-analysis-pipeline/temp/**/runtime/*
133+
./code-graph-analysis-pipeline/temp/**/reports/*
134+
retention-days: 5
135+
136+
# Upload successful analysis-results in case they are needed for troubleshooting
137+
- name: (Code Analysis Results) Archive successful analysis-results
138+
if: success()
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: ${{ steps.set-analysis-results-artifact-name.outputs.uploaded-analysis-results-artifact-name }}
142+
path: ./code-graph-analysis-pipeline/temp/**/reports/*
143+
if-no-files-found: error
144+
retention-days: 5
145+
146+
# Upload Database Export
147+
# Only possible after an export with "./../../scripts/analysis/analyze.sh --report DatabaseCsvExport"
148+
# Won't be done here because of performance and security concerns
149+
#- name: Archive exported database
150+
# uses: actions/upload-artifact@v3
151+
# with:
152+
# name: typescript-code-analysis-database-export-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
153+
# path: ./code-graph-analysis-pipeline/temp/**/import
154+
# if-no-files-found: error
155+
# retention-days: 5

.github/workflows/typescript-code-analysis.yml

Lines changed: 68 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: react-router Typescript Code Structure Graph Analysis
1+
name: react-router Code Graph Analysis (TypeScript)
22

33
on:
44
push:
@@ -37,121 +37,94 @@ on:
3737
- '.github/workflows/*documentation.yml'
3838

3939
jobs:
40-
analysis-results:
40+
prepare-code-to-analyze:
4141
runs-on: ubuntu-latest
42-
strategy:
43-
matrix:
44-
include:
45-
- os: ubuntu-latest
46-
java: 17
47-
python: 3.11
48-
miniforge: 24.9.0-0
42+
outputs:
43+
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
44+
uploaded-artifact-name: ${{ steps.set-uploaded-artifact-name.outputs.uploaded-artifact-name }}
4945

5046
env:
51-
CI_COMMIT_MESSAGE: Automated code structure analysis analysis-results (CI)
52-
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
5347
PROJECT_NAME: react-router
5448
# Version variable name matches renovate.json configuration entry
5549
REACT_ROUTER_VERSION: 6.28.1
5650

5751
steps:
58-
- name: Checkout GIT Repository
52+
- name: (Prepare Code to Analyze) Checkout react-router repository
5953
uses: actions/checkout@v4
6054
with:
61-
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
62-
63-
- name: (Code Analysis Setup) Set ANALYSIS_NAME
64-
run: echo "ANALYSIS_NAME=${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}" >> $GITHUB_ENV
65-
66-
- name: (Code Analysis Setup) Generate Neo4j Initial Password
67-
id: generate_neo4j_initial_password
68-
shell: bash
69-
run: |
70-
generated_password=$( LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c 12; echo )
71-
echo "::add-mask::$generated_password"
72-
echo "neo4j_initial_password=$generated_password" >> "$GITHUB_OUTPUT"
73-
74-
- name: Setup Code Analysis
75-
uses: ./.github/actions/setup-code-analysis
76-
with:
77-
java-version: ${{ matrix.java }}
78-
python-version: ${{ matrix.python }}
79-
miniforge-version: ${{ matrix.miniforge }}
80-
analysis-name: ${{ env.ANALYSIS_NAME }}
81-
neo4j-password: ${{ steps.generate_neo4j_initial_password.outputs.neo4j_initial_password }}
82-
83-
- name: (Code Analysis Setup) Download ${{ env.ANALYSIS_NAME }}
84-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
85-
run: |
86-
./../../scripts/downloader/downloadReactRouter.sh ${{ env.REACT_ROUTER_VERSION }}
87-
88-
- name: (Code Analysis Setup) Setup pnpm for react-router
55+
repository: remix-run/react-router
56+
ref: react-router@${{ env.REACT_ROUTER_VERSION }}
57+
58+
- name: (Prepare Code to Analyze) Setup pnpm for react-router
8959
uses: pnpm/[email protected]
90-
with:
91-
package_json_file: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}/source/${{ env.ANALYSIS_NAME }}/package.json
9260

93-
- name: (Code Analysis Setup) Install dependencies with pnpm
94-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}/source/${{ env.ANALYSIS_NAME }}
95-
run: |
96-
pnpm install --frozen-lockfile --strict-peer-dependencies
61+
- name: (Prepare Code to Analyze) Install dependencies with pnpm
62+
run: pnpm install --frozen-lockfile --strict-peer-dependencies
9763

98-
- name: Analyze ${{ env.ANALYSIS_NAME }}
99-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
100-
# Shell type can be skipped if jupyter notebook analysis-results (and therefore conda) aren't needed
101-
shell: bash -el {0}
102-
env:
103-
NEO4J_INITIAL_PASSWORD: ${{ steps.generate_neo4j_initial_password.outputs.neo4j_initial_password }}
104-
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
105-
IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT: "" # Options: "none", "aggregated", "full". default = "plugin" or ""
106-
run: |
107-
./../../scripts/analysis/analyze.sh --profile Neo4jv5-low-memory
108-
109-
- name: (Code Analysis) Collect analysis results
110-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
111-
run: |
112-
mkdir -p ./../../../analysis-results/${{ env.ANALYSIS_NAME }}
113-
cp -Rp reports ./../../../analysis-results/${{ env.ANALYSIS_NAME }}
114-
115-
# Upload logs and unfinished analysis-results in case of an error for troubleshooting
116-
- name: Archive failed run with logs and unfinished analysis-results
117-
if: failure()
118-
uses: actions/upload-artifact@v4
119-
with:
120-
name: typescript-code-analysis-logs-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
121-
path: |
122-
./code-graph-analysis-pipeline/temp/**/runtime/*
123-
./code-graph-analysis-pipeline/temp/**/results/*
124-
retention-days: 5
64+
- name: (Prepare Code to Analyze) Assemble ANALYSIS_NAME
65+
run: echo "ANALYSIS_NAME=${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}" >> $GITHUB_ENV
66+
67+
- name: (Prepare Code to Analyze) Generate ARTIFACT_UPLOAD_ID
68+
shell: bash
69+
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
70+
71+
- name: (Prepare Code to Analyze) Assemble ARTIFACT_NAME
72+
shell: bash
73+
run: echo "ARTIFACT_NAME=${{ env.ANALYSIS_NAME }}-analysis-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> $GITHUB_ENV
12574

126-
# Upload successful analysis-results in case they are needed for troubleshooting
127-
- name: Archive successful analysis-results
75+
- name: (Prepare Code to Analyze) Upload code to analyze
12876
if: success()
12977
uses: actions/upload-artifact@v4
13078
with:
131-
name: typescript-code-analysis-analysis-results-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
132-
path: ./analysis-results/${{ env.ANALYSIS_NAME }}/*
79+
name: ${{ env.ARTIFACT_NAME }}
80+
path: .
13381
if-no-files-found: error
13482
retention-days: 5
83+
84+
- name: (Prepare Code to Analyze) Set output variable analysis-name
85+
id: set-analysis-name
86+
run: echo "analysis-name=${{ env.ANALYSIS_NAME }}" >> "$GITHUB_OUTPUT"
87+
88+
- name: (Prepare Code to Analyze) Set output variable uploaded-artifact-name
89+
id: set-uploaded-artifact-name
90+
run: echo "uploaded-artifact-name=${{ env.ARTIFACT_NAME }}" >> "$GITHUB_OUTPUT"
91+
92+
93+
analyze-code-graph:
94+
needs: [prepare-code-to-analyze]
95+
uses: ./.github/workflows/analyze-code-graph.yml
96+
with:
97+
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
98+
uploaded-artifact-name: ${{ needs.prepare-code-to-analyze.outputs.uploaded-artifact-name }}
13599

136-
# Upload Database Export
137-
# Only possible after an export with "./../../scripts/analysis/analyze.sh --report DatabaseCsvExport"
138-
# Won't be done here because of performance and security concerns
139-
#- name: Archive exported database
140-
# uses: actions/upload-artifact@v3
141-
# with:
142-
# name: typescript-code-analysis-database-export-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
143-
# path: ./code-graph-analysis-pipeline/temp/**/import
144-
# if-no-files-found: error
145-
# retention-days: 5
100+
101+
analysis-results:
102+
needs: [prepare-code-to-analyze, analyze-code-graph]
103+
runs-on: ubuntu-latest
104+
105+
env:
106+
CI_COMMIT_MESSAGE: Automated code structure analysis analysis-results (CI)
107+
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
108+
109+
steps:
110+
- name: Checkout GIT Repository
111+
uses: actions/checkout@v4
112+
with:
113+
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
114+
115+
- name: (Code Analysis Setup) Download source code and artifacts for analysis
116+
uses: actions/download-artifact@v4
117+
with:
118+
name: ${{ needs.analyze-code-graph.outputs.uploaded-analysis-results }}
119+
path: analysis-results/${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
146120

147121
# Commit and push the native image agent analysis-results
148122
- name: Display environment variable "github.event_name"
149123
run: echo "github.event_name=${{ github.event_name }}"
150-
- name: Commit changes in the "analysis-results" directory
124+
- name: Display changes in the "analysis-results" directory and prepare commit
151125
# Only run when a pull request gets merged or a commit is pushed to the main branch
152126
# git add parameters need to match paths-ignore parameters above
153127
# Git pull before add/commit/push to reduce race conditions on parallel builds
154-
if: github.event_name == 'push'
155128
run: |
156129
git config --global user.name '${{ env.CI_COMMIT_AUTHOR }}'
157130
git config --global user.email "[email protected]"
@@ -160,6 +133,12 @@ jobs:
160133
git status
161134
git add analysis-results
162135
git status
136+
- name: Commit and push changes in the "analysis-results" directory
137+
# Only run when a pull request gets merged or a commit is pushed to the main branch
138+
# git add parameters need to match paths-ignore parameters above
139+
# Git pull before add/commit/push to reduce race conditions on parallel builds
140+
if: github.event_name == 'push'
141+
run: |
163142
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
164143
git status
165144
git rebase --strategy-option=theirs origin/main --verbose

0 commit comments

Comments
 (0)