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

Auto docs action added to pull-request.yml #2716

Closed
wants to merge 10 commits into from
Closed
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
35 changes: 35 additions & 0 deletions .github/workflows/convert_html_to_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import markdownify

# Define directories
input_dir = os.path.abspath('docs/temp-docs') # HTML source directory
output_dir = os.path.abspath('docs/docs/auto-docs') # Markdown output directory

# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)

def convert_html_to_md(input_path, output_path):
"""Recursively convert HTML files to Markdown."""
for root, dirs, files in os.walk(input_path):
# Create corresponding directories in output path
relative_path = os.path.relpath(root, input_path)
target_dir = os.path.join(output_path, relative_path)
os.makedirs(target_dir, exist_ok=True)

for file in files:
if file.endswith('.html'):
html_file = os.path.join(root, file)
md_file = os.path.join(target_dir, file.replace('.html', '.md'))

# Read HTML, convert to Markdown, and save
with open(html_file, 'r', encoding='utf-8') as f:
html_content = f.read()
markdown_content = markdownify.markdownify(html_content, heading_style="ATX")

with open(md_file, 'w', encoding='utf-8') as f:
f.write(markdown_content)
print(f"Converted: {html_file} -> {md_file}")

if __name__ == "__main__":
convert_html_to_md(input_dir, output_dir)
print("All HTML files converted to Markdown.")
98 changes: 83 additions & 15 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: PR Workflow
on:
pull_request:
branches-ignore:
- 'master'
- "master"

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
Expand All @@ -33,12 +33,12 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-java@v4
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17.0'
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "17.0"
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.22.3'
channel: 'stable' # or: 'beta', 'dev' or 'master'
flutter-version: "3.22.3"
channel: "stable" # or: 'beta', 'dev' or 'master'
- name: Set default branch.
run: git remote set-head origin --auto
shell: bash
Expand Down Expand Up @@ -94,7 +94,6 @@ jobs:
echo "Error: Close this PR and try again."
exit 1


Branch-check:
if: ${{ github.actor != 'dependabot[bot]' && !contains(github.event.pull_request.labels.*.name, 'ignore-sensitive-files-pr') }}
name: "Base branch check"
Expand Down Expand Up @@ -204,6 +203,73 @@ jobs:
path: "./coverage/lcov.info"
min_coverage: 92.0

generate-docs:
if: github.ref == 'refs/heads/develop-postgres' || (github.event_name == 'pull_request' && github.base_ref == 'develop-postgres')
name: Generate documentation
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: "17.0"

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: "3.22.3"
channel: "stable"

- name: Set up Dart
uses: dart-lang/setup-dart@v1
with:
sdk: "3.4.4"

- name: Set up Python
uses: actions/setup-python@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update actions/setup-python@v4 to v5 for version consistency

The runner compatibility is not an issue, but the workflow uses two different versions of setup-python (v4 and v5). Update to v5 to maintain consistency and use the latest stable version.

  • Line 239: uses: actions/setup-python@v4uses: actions/setup-python@v5
🔗 Analysis chain

Update the runner for actions/setup-python@v4.

Static analysis suggests the current runner might be too old. Consider upgrading or verifying that your workflow environment supports the specified version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Review the available runners for 'actions/setup-python' in your GitHub Actions environment.
# Expected outcome: Confirm that 'actions/setup-python@v4' is fully supported on your runner.

gh run list --limit 10

Length of output: 1515


Script:

#!/bin/bash
# Check the workflow file for runner configuration
cat .github/workflows/pull-request.yml

# Check the latest version of actions/setup-python
curl -s https://api.github.com/repos/actions/setup-python/releases | jq -r '.[0].tag_name'

Length of output: 13056

🧰 Tools
🪛 actionlint (1.7.4)

239-239: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

with:
python-version: "3.x"

- name: Install dependencies
run: |
pip install markdownify

- name: Generate docs with dartdoc
run: |
cd talawa_lint && flutter pub get && cd ..
flutter pub get
flutter analyze --no-fatal-infos
flutter pub global activate dartdoc
flutter pub global run dartdoc \
--output docs/temp-docs \
--exclude 'dart:async,dart:collection,dart:convert,dart:core,dart:developer,dart:io' \

- name: Convert HTML to Markdown
run: |
python .github/workflows/convert_html_to_md.py

- name: Clean up temporary files
run: |
rm -rf docs/temp-docs

- name: Commit and push changes
run: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid using untrusted expressions directly in inline script arguments.

github.event.pull_request.head.ref may be untrusted. Per GitHub security guides, you can safely pass it via an environment variable, then reference that variable in scripts.

- git push origin HEAD:${{ github.event.pull_request.head.ref }}
+ export PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"
+ git push origin HEAD:"${PR_HEAD_REF}"

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 actionlint (1.7.4)

266-266: "github.event.pull_request.head.ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions for more details

(expression)

git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add docs/docs/auto-docs/*
git commit -m "Update documentation"
git push origin HEAD:${{ github.event.pull_request.head.ref }}

Android-Build:
name: Testing build for android
runs-on: ubuntu-latest
Expand Down Expand Up @@ -241,22 +307,24 @@ jobs:
name: Test Deployment to https://docs-mobile.talawa.io
runs-on: ubuntu-latest
needs: [iOS-Build, Android-Build]
# Run only if the develop-postgres branch and not dependabot
# Run only if the develop-postgres branch and not dependabot
if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.base.ref == 'develop-postgres' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
cache-dependency-path: 'docs/'
# Run Docusaurus in the ./docs directory
node-version: "20.x"

- name: Install dependencies
working-directory: ./docs
run: yarn install --frozen-lockfile
run: npm install

- name: Test building the website
working-directory: ./docs
run: yarn build
run: npm run build

Validate-Coderabbit:
name: Validate CodeRabbit Approval
Expand Down
Loading