Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#17 - Action migration to composite #18

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
/.idea/
node_modules
/package-lock.json

# Generated outputs
data/
Expand Down
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,9 @@ If you need to build the action locally, follow these steps:

### Prepare the Environment
```
node --version
python3 --version
```

### Install Node.js Dependencies
```
npm install
```

### Compile or Prepare the JavaScript Files
```
npm run build
```

### Set Up Python Environment
```
python3 -m venv venv
Expand Down Expand Up @@ -233,11 +222,7 @@ For running the GitHub action incorporate these commands into the shell script a
```
cd src || exit 1

python3 controller.py --github-token "$GITHUB_TOKEN" \
--project-state-mining "$PROJECT_STATE_MINING" \
--projects-title-filter "$PROJECTS_TITLE_FILTER" \
--repositories "$REPOSITORIES" \
--output-directory "$OUTPUT_DIRECTORY"
python3 living_documenation_generator.py

cd .. || exit 1
```
Expand Down
36 changes: 34 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ inputs:
outputs:
documentation-path:
description: 'Path to the generated living documentation files'

branding:
icon: 'book'
color: 'yellow'

runs:
using: 'node12'
main: 'dist/index.js'
using: 'composite'
steps:
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r ${{ github.action_path }}/requirements.txt
shell: bash

- name: Call command python3
run: python3 --version
shell: bash

- name: Set PROJECT_ROOT and update PYTHONPATH
run: |
ACTION_ROOT="${{ github.action_path }}"
export PYTHONPATH="${PYTHONPATH}:${ACTION_ROOT}/release_notes_generator"
shell: bash

- name: Call Living Documentation Generator
id: liv-doc-generator
env:
INPUT_GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
INPUT_REPOSITORIES: ${{ inputs.repositories }}
INPUT_PROJECT_STATE_MINING: ${{ inputs.project_state_mining }}
INPUT_PROJECTS_TITLE_FILTER: ${{ inputs.projects_title_filter }}

run: |
python3 ${{ github.action_path }}/src/living_documentation_generator.py
shell: bash
30 changes: 0 additions & 30 deletions package.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/action/action_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def load_from_environment(self, validate: bool = True) -> 'ActionInputs':
self.__github_token = os.getenv('GITHUB_TOKEN')
self.__is_project_state_mining_enabled = os.getenv('PROJECT_STATE_MINING').lower() == "true"
self.__projects_title_filter = os.getenv('PROJECTS_TITLE_FILTER')
self.__output_directory = os.getenv('OUTPUT_DIRECTORY')
self.__output_directory = os.getenv('OUTPUT_DIRECTORY', 'output')
repositories_json = os.getenv('REPOSITORIES')

logging.debug(f'Is project state mining allowed: {self.__is_project_state_mining_enabled}')
Expand Down
76 changes: 0 additions & 76 deletions src/controller.py
Original file line number Diff line number Diff line change
@@ -1,76 +0,0 @@
import logging
import os
import subprocess
import argparse
import sys


def extract_args():
""" Extract and return the required arguments using argparse. """
parser = argparse.ArgumentParser(description='Generate Living Documentation from GitHub repositories.')

parser.add_argument('--github-token', required=True, help='GitHub token for authentication.')
parser.add_argument('--project-state-mining', required=True, help='Enable or disable mining of project state data.')
parser.add_argument('--projects-title-filter', required=True, help='Filter projects by titles. Provide a list of project titles.')
parser.add_argument('--repositories', required=True, help='JSON string defining the repositories to be included in the documentation generation.')
parser.add_argument('--output-directory', type=str, required=False, default='../output', help='Output directory, which stores the generated documentation.')

args = parser.parse_args()

env_vars = {
'GITHUB_TOKEN': args.github_token,
'PROJECT_STATE_MINING': args.project_state_mining,
'PROJECTS_TITLE_FILTER': args.projects_title_filter,
'REPOSITORIES': args.repositories,
'OUTPUT_DIRECTORY': args.output_directory
}

return env_vars


def run_script(script_name, env):
""" Helper function to run a Python script with environment variables using subprocess """
try:
# Running the python script with given environment variables
result = subprocess.run(['python3.11', script_name], env=env, text=True, capture_output=True, check=True)
logging.info(f"Output from {script_name}: {result.stdout}")

except subprocess.CalledProcessError as e:
logging.error(f"Error running {script_name}: \n{e.stdout}\n{e.stderr}")
sys.exit(1)


def main():
# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

env_vars = extract_args()

# Create a local copy of the current environment variables
local_env = os.environ.copy()

# Add the script-specific environment variables to the local copy
local_env.update(env_vars)

logging.info("Starting the Living Documentation Generator - mining phase")

# Clean the environment before mining
run_script('clean_env_before_mining.py', local_env)

# Data mine GitHub features from repository
run_script('github_query_issues.py', local_env)

# Data mine GitHub project's state
run_script('github_query_project_state.py', local_env)

# Consolidate all feature data together
run_script('consolidate_issue_data.py', local_env)

# Generate markdown pages
run_script('convert_issues_to_pages.py', local_env)


if __name__ == '__main__':
logging.info("Starting Living Documentation generation.")
main()
logging.info("Living Documentation generation completed.")
64 changes: 0 additions & 64 deletions src/index.js

This file was deleted.

57 changes: 57 additions & 0 deletions src/living_documentation_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import subprocess
import sys


def run_script(script_name, env):
""" Helper function to run a Python script with environment variables using subprocess """
try:
# Running the python script with given environment variables
result = subprocess.run(['python3', script_name], env=env, text=True, capture_output=True, check=True)
MobiTikula marked this conversation as resolved.
Show resolved Hide resolved
print(f"Output from {script_name}: {result.stdout}")

except subprocess.CalledProcessError as e:
print(f"Error running {script_name}: \n{e.stdout}\n{e.stderr}")
sys.exit(1)


def main():
print("Extracting arguments from command line.")

# Create a local copy of the current environment variables
local_env = os.environ.copy()

print("Starting the Living Documentation Generator - mining phase")

# Clean the environment before mining
run_script('clean_env_before_mining.py', local_env)

# Data mine GitHub features from repository
run_script('github_query_issues.py', local_env)

# Data mine GitHub project's state
run_script('github_query_project_state.py', local_env)

# Consolidate all feature data together
run_script('consolidate_issue_data.py', local_env)

# Generate markdown pages
run_script('convert_issues_to_pages.py', local_env)

# TODO ideas to consider during next refactoring iteration
#
# 1. make clean script as method in this script
# 2. can be run_script replaced by method calls? ==> reduction standalone script files to methods using OOP
# - we have ActionInputs class, we will have shared logic in library
# 3. we can introduce a classes
# - LivingDocumentationDataMiner - mines issues from N repositories, projects
# - will define method for issues mining
# - will define method for project state mining
# - LivingDocumentationConsolidator - consolidates mined data
# - LivingDocumentationBuilder - builds markdown pages from consolidated data


if __name__ == '__main__':
print("Starting Living Documentation generation.")
main()
print("Living Documentation generation completed.")