Skip to content

Commit 297db07

Browse files
committed
Refined github action with proper parameter passing.
1 parent 75a27bb commit 297db07

File tree

3 files changed

+117
-23
lines changed

3 files changed

+117
-23
lines changed

.github/workflows/example-usage.yml

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ name: Example Usage of CodeBoarding Action
33
on:
44
workflow_dispatch:
55
inputs:
6-
test_repo:
6+
repository_url:
77
description: 'Repository URL to test with'
88
required: false
9-
default: 'https://github.com/CodeBoarding/insights-core'
9+
default: 'https://github.com/microsoft/markitdown'
1010
type: string
11+
source_branch:
12+
description: 'Source branch for comparison'
13+
required: false
14+
default: 'main'
15+
type: string
16+
target_branch:
17+
description: 'Target branch for comparison'
18+
required: false
19+
default: 'develop'
20+
type: string
21+
output_format:
22+
description: 'Output format for documentation'
23+
required: false
24+
default: '.md'
25+
type: choice
26+
options:
27+
- '.md'
28+
- '.rst'
29+
30+
pull_request:
31+
branches: [ main, master ]
32+
types: [opened, synchronize, reopened]
33+
1134
schedule:
1235
# Run daily at 2 AM UTC
1336
- cron: '0 2 * * *'
@@ -24,22 +47,54 @@ jobs:
2447
uses: actions/checkout@v4
2548
with:
2649
token: ${{ secrets.GITHUB_TOKEN }}
50+
fetch-depth: 0 # Required to access branch history
51+
52+
# Determine branches based on context
53+
- name: Set branch variables
54+
id: set-branches
55+
run: |
56+
if [ "${{ github.event_name }}" = "pull_request" ]; then
57+
echo "source_branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT
58+
echo "target_branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT
59+
elif [ "${{ github.event.inputs.source_branch }}" != "" ] && [ "${{ github.event.inputs.target_branch }}" != "" ]; then
60+
echo "source_branch=${{ github.event.inputs.source_branch }}" >> $GITHUB_OUTPUT
61+
echo "target_branch=${{ github.event.inputs.target_branch }}" >> $GITHUB_OUTPUT
62+
else
63+
# Default to current branch and main
64+
echo "source_branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
65+
echo "target_branch=main" >> $GITHUB_OUTPUT
66+
fi
2767
2868
- name: Fetch CodeBoarding Documentation
2969
id: codeboarding
30-
uses: ./ # Use the local action (when this is published, users would use: owner/repo@version)
70+
uses: ./
3171
with:
32-
repository_url: ${{ github.repository }}
33-
output_directory: '.codeboarding'
72+
repository_url: ${{ github.event.inputs.repository_url }}
73+
source_branch: ${{ steps.set-branches.outputs.source_branch }}
74+
target_branch: ${{ steps.set-branches.outputs.target_branch }}
75+
output_directory: 'docs'
76+
output_format: ${{ github.event.inputs.output_format || '.md' }}
3477

3578
- name: Display Action Results
3679
run: |
37-
echo "Files created: ${{ steps.codeboarding.outputs.files_created }}"
38-
echo "Output directory: ${{ steps.codeboarding.outputs.output_directory }}"
80+
echo "Documentation files created: ${{ steps.codeboarding.outputs.markdown_files_created }}"
81+
echo "JSON files created: ${{ steps.codeboarding.outputs.json_files_created }}"
82+
echo "Documentation directory: ${{ steps.codeboarding.outputs.output_directory }}"
83+
echo "JSON directory: ${{ steps.codeboarding.outputs.json_directory }}"
3984
echo "Has changes: ${{ steps.codeboarding.outputs.has_changes }}"
4085
86+
# Check if we have any changes to commit
87+
- name: Check for changes
88+
id: git-changes
89+
run: |
90+
if [ -n "$(git status --porcelain)" ]; then
91+
echo "has_git_changes=true" >> $GITHUB_OUTPUT
92+
else
93+
echo "has_git_changes=false" >> $GITHUB_OUTPUT
94+
fi
95+
4196
- name: Create Pull Request
42-
if: steps.git-changes.outputs.has_git_changes == 'true'
97+
if: steps.git-changes.outputs.has_git_changes == 'true' && steps.codeboarding.outputs.has_changes == 'true'
4398
uses: peter-evans/create-pull-request@v5
4499
with:
45100
token: ${{ secrets.GITHUB_TOKEN }}
@@ -51,17 +106,21 @@ jobs:
51106
This PR contains updated documentation files fetched from the CodeBoarding service.
52107
53108
### 📊 Summary
54-
- **Files created/updated**: ${{ steps.codeboarding.outputs.files_created }}
55-
- **Output directory**: `${{ steps.codeboarding.outputs.output_directory }}/`
56-
- **Source endpoint**: ${{ vars.CODEBOARDING_ENDPOINT || 'codeboarding endpoint' }}
57-
- **Repository analyzed**: ${{ github.event.inputs.test_repo || github.repository }}
109+
- **Documentation files created/updated**: ${{ steps.codeboarding.outputs.markdown_files_created }}
110+
- **JSON files created/updated**: ${{ steps.codeboarding.outputs.json_files_created }}
111+
- **Documentation directory**: `${{ steps.codeboarding.outputs.output_directory }}/`
112+
- **JSON directory**: `${{ steps.codeboarding.outputs.json_directory }}/`
113+
- **Source branch**: `${{ steps.set-branches.outputs.source_branch }}`
114+
- **Target branch**: `${{ steps.set-branches.outputs.target_branch }}`
115+
- **Output format**: `${{ github.event.inputs.output_format || '.md' }}`
116+
- **Repository analyzed**: `${{ steps.codeboarding.outputs.repo_url }}`
58117
59118
### 🔍 Changes
60-
Files have been updated in the `${{ steps.codeboarding.outputs.output_directory }}/` directory with fresh documentation content.
119+
Files have been updated with fresh documentation content based on code changes between branches.
61120
62121
---
63122
64123
🤖 This PR was automatically generated by the CodeBoarding documentation update workflow.
65124
branch: docs/codeboarding-update
66-
base: main
125+
base: ${{ steps.set-branches.outputs.target_branch }}
67126
delete-branch: true

README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,65 @@ on:
1717
branches: [ main ]
1818
pull_request:
1919
branches: [ main ]
20+
types: [opened, synchronize, reopened]
2021

2122
jobs:
2223
documentation:
2324
runs-on: ubuntu-latest
2425
steps:
2526
- name: Checkout
2627
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Required to access branch history
2730

2831
- name: Generate Documentation
29-
uses: your-username/CodeBoarding-GHAction@v1
32+
uses: codeboarding/codeboarding-ghaction@v1
3033
with:
3134
repository_url: ${{ github.server_url }}/${{ github.repository }}
32-
output_directory: '.codeboarding'
35+
source_branch: ${{ github.head_ref || github.ref_name }}
36+
target_branch: ${{ github.base_ref || 'main' }}
37+
output_directory: 'docs'
38+
output_format: '.md'
3339

3440
- name: Upload Documentation
3541
uses: actions/upload-artifact@v4
3642
with:
3743
name: documentation
38-
path: .codeboarding/
44+
path: |
45+
docs/
46+
.codeboarding/
3947
```
4048
4149
## Inputs
4250
4351
| Input | Description | Required | Default |
4452
|-------|-------------|----------|---------|
4553
| `repository_url` | Repository URL for which documentation will be generated | Yes | - |
46-
| `output_directory` | Directory where documentation files will be saved | No | `.codeboarding` |
54+
| `source_branch` | Source branch for comparison (typically the PR branch) | Yes | - |
55+
| `target_branch` | Target branch for comparison (typically the base branch) | Yes | - |
56+
| `output_directory` | Directory where documentation files will be saved | No | `docs` |
57+
| `output_format` | Format for documentation files (either `.md` or `.rst`) | No | `.md` |
4758

4859
## Outputs
4960

5061
| Output | Description |
5162
|--------|-------------|
52-
| `files_created` | Number of files created |
53-
| `output_directory` | Directory where files were saved |
63+
| `markdown_files_created` | Number of documentation files created |
64+
| `json_files_created` | Number of JSON files created |
65+
| `output_directory` | Directory where documentation files were saved |
66+
| `json_directory` | Directory where JSON files were saved (always `.codeboarding`) |
5467
| `has_changes` | Whether any files were created or changed |
5568

69+
## How It Works
70+
71+
The action works by:
72+
73+
1. Analyzing the differences introduced in the source branch and putting the results in the target branch
74+
2. Generating documentation files based on the latest version of the source branch
75+
3. Outputting two types of files:
76+
- Documentation files (Markdown or RST) in the specified output directory
77+
- Metadata files in the `.codeboarding` directory
78+
5679
## License
5780

5881
MIT License - see [LICENSE](LICENSE) file for details.

action.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ outputs:
4141
has_changes:
4242
description: 'Whether any files were created or changed'
4343
value: ${{ steps.process-docs.outputs.has_changes }}
44+
repo_url:
45+
description: 'Repository URL that was analyzed'
46+
value: ${{ steps.repo-url.outputs.repo_url }}
4447

4548
runs:
4649
using: 'composite'
@@ -49,20 +52,29 @@ runs:
4952
id: repo-url
5053
shell: bash
5154
run: |
52-
if [ "${{ inputs.repository_url }}" != "" ]; then
55+
# Use the provided repository URL if it's not empty
56+
if [ -n "${{ inputs.repository_url }}" ]; then
5357
REPO_URL="${{ inputs.repository_url }}"
5458
echo "Using provided repository URL: $REPO_URL"
59+
# Otherwise try to determine from git if we're in a git repository
60+
elif git config --get remote.origin.url > /dev/null 2>&1; then
61+
REPO_URL=$(git config --get remote.origin.url)
62+
# Convert SSH URL to HTTPS if needed
63+
if [[ $REPO_URL == git@* ]]; then
64+
REPO_URL=$(echo $REPO_URL | sed 's|[email protected]:|https://github.com/|')
65+
fi
66+
echo "Using git remote URL: $REPO_URL"
5567
else
5668
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
57-
echo "Using current repository URL: $REPO_URL"
69+
echo "Using GitHub context URL: $REPO_URL"
5870
fi
5971
echo "repo_url=$REPO_URL" >> $GITHUB_OUTPUT
6072
6173
- name: Fetch documentation files
6274
id: fetch-docs
6375
shell: bash
6476
run: |
65-
ENDPOINT_URL="https://server.codeboarding.org/github_action"
77+
ENDPOINT_URL="http://0.0.0.0:8000/github_action"
6678
REPO_URL="${{ steps.repo-url.outputs.repo_url }}"
6779
SOURCE_BRANCH="${{ inputs.source_branch }}"
6880
TARGET_BRANCH="${{ inputs.target_branch }}"

0 commit comments

Comments
 (0)