Skip to content

Commit

Permalink
fix: pass modified files to the Action (#6)
Browse files Browse the repository at this point in the history
The Python script now reads the list of modified files as a parameter, instead of calling git diff itself. This fixes the problem where the Docker container is built before the repository is cloned.
  • Loading branch information
KevinGDialpad authored May 6, 2022
1 parent ffb6467 commit d9c1e33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ two commits and get a list of modified files.
with:
fetch-depth: 2
- name: Get modified files
run: echo "MODIFIED_FILES=`git diff HEAD^ --name-only | xargs`" >> $GITHUB_ENV
- name: Wiki Sync
uses: talkiq/confluence-docs-sync@v1
uses: talkiq/confluence-wiki-sync@v1
with:
wiki-base-url: https://example.org
user: [email protected]
token: ${{ secrets.TOKEN }}
modified-files: ${{ env.MODIFIED_FILES }}
space-name: CoolSpace
root-page-title: Root page
Expand All @@ -57,7 +61,7 @@ space-separated list:
.. code-block:: yaml
- name: Wiki Sync
uses: talkiq/confluence-docs-sync@v1
uses: talkiq/confluence-wiki-sync@v1
with:
ignored_folders: 'foo/ bar/baz/'
[...]
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
description: Space-delimited list of folders to ignore when considering which files to upload
required: false
default: ''
modified-files:
description: Space-delimited list of files that have been modified (or added or deleted)
required: true
root-page-title:
description: Title of the Confluence page files will be uploaded under
required: true
Expand Down
9 changes: 3 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
import pypandoc


def get_files_to_sync() -> List[str]:
with subprocess.Popen(['git', 'diff', 'HEAD^', '--name-only'],
stdout=subprocess.PIPE) as proc:
changed_files = proc.communicate()[0].rstrip().decode('utf-8')
return [f for f in changed_files.split('\n') if should_sync_file(f)]
def get_files_to_sync(changed_files: str) -> List[str]:
return [f for f in changed_files.split() if should_sync_file(f)]


def should_sync_file(file_name: str) -> bool:
Expand Down Expand Up @@ -156,7 +153,7 @@ def create_or_update_pages_for_file(wiki_client: atlassian.Confluence,
logging.basicConfig(level=logging.INFO)

try:
files_to_sync = get_files_to_sync()
files_to_sync = get_files_to_sync(os.environ['INPUT_MODIFIED-FILES'])
logging.info('Files to be synced: %s', files_to_sync)

had_sync_errors = sync_files(files_to_sync)
Expand Down

0 comments on commit d9c1e33

Please sign in to comment.