From d9c1e332c5bfb37e8cb02d37fd0a9edc16758065 Mon Sep 17 00:00:00 2001 From: Kevin Guillaumond Date: Fri, 6 May 2022 16:16:47 -0700 Subject: [PATCH] fix: pass modified files to the Action (#6) 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. --- README.rst | 8 ++++++-- action.yml | 3 +++ main.py | 9 +++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 64a221e..afa8271 100644 --- a/README.rst +++ b/README.rst @@ -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: user@domain.tld token: ${{ secrets.TOKEN }} + modified-files: ${{ env.MODIFIED_FILES }} space-name: CoolSpace root-page-title: Root page @@ -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/' [...] diff --git a/action.yml b/action.yml index 8799ab7..2dd8c1c 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/main.py b/main.py index 3fde7f3..de556e0 100644 --- a/main.py +++ b/main.py @@ -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: @@ -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)