From 9610f24329de557be314de2363d838cf9bf6002d Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Wed, 27 Nov 2024 02:57:12 +0530 Subject: [PATCH 1/6] [Add] argument to pass yaml file path --- updatesnap/updatesnapyaml.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/updatesnap/updatesnapyaml.py b/updatesnap/updatesnapyaml.py index 6f6c8b4..eef4dd3 100755 --- a/updatesnap/updatesnapyaml.py +++ b/updatesnap/updatesnapyaml.py @@ -40,7 +40,7 @@ def get_working_branch(self, project_url): break return working_branch - def get_yaml_file(self, project_url): + def get_yaml_file(self, project_url, file_path): """ Searches in a project for the 'snapcraft.yaml' file and returns its contents """ yaml_path = 'snapcraft.yaml' @@ -55,7 +55,7 @@ def get_yaml_file(self, project_url): except (ValueError, ConnectionError): data = None if not data: - yaml_path = 'rockcraft.yaml' + yaml_path = f'{file_path}' try: data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): @@ -76,6 +76,8 @@ def main(): help='Version schema of snapping repository') parser.add_argument('--rock-version-schema', action='store', default='None', help='Version schema of rock repository') + parser.add_argument('--file-path', action='store', default='rockcraft.yaml', + help='Path to the yaml file') parser.add_argument('--verbose', action='store_true', default=False) parser.add_argument('project', default='.', help='The project URI') arguments = parser.parse_args(sys.argv[1:]) @@ -88,7 +90,7 @@ def main(): # get the most-updated SNAPCRAFT.YAML file - data = manager.get_yaml_file(arguments.project) + data = manager.get_yaml_file(arguments.project, arguments.file_path) if not data: print('Failed to get the snapcraft.yaml file.', file=sys.stderr) sys.exit(-1) From fa8d300da0c55392d468f7ad2739305b46bba1bc Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Wed, 27 Nov 2024 03:14:03 +0530 Subject: [PATCH 2/6] Add argument to specify yaml file path --- updatesnap/updatesnapyaml.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/updatesnap/updatesnapyaml.py b/updatesnap/updatesnapyaml.py index eef4dd3..c397bde 100755 --- a/updatesnap/updatesnapyaml.py +++ b/updatesnap/updatesnapyaml.py @@ -40,10 +40,9 @@ def get_working_branch(self, project_url): break return working_branch - def get_yaml_file(self, project_url, file_path): + def get_yaml_file(self, project_url, yaml_path): """ Searches in a project for the 'snapcraft.yaml' file and returns its contents """ - yaml_path = 'snapcraft.yaml' try: data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): @@ -54,12 +53,6 @@ def get_yaml_file(self, project_url, file_path): data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): data = None - if not data: - yaml_path = f'{file_path}' - try: - data = self._github.get_file(project_url, yaml_path) - except (ValueError, ConnectionError): - data = None return data @@ -76,7 +69,7 @@ def main(): help='Version schema of snapping repository') parser.add_argument('--rock-version-schema', action='store', default='None', help='Version schema of rock repository') - parser.add_argument('--file-path', action='store', default='rockcraft.yaml', + parser.add_argument('--yaml-path', action='store', default='snapcraft.yaml', help='Path to the yaml file') parser.add_argument('--verbose', action='store_true', default=False) parser.add_argument('project', default='.', help='The project URI') @@ -90,7 +83,7 @@ def main(): # get the most-updated SNAPCRAFT.YAML file - data = manager.get_yaml_file(arguments.project, arguments.file_path) + data = manager.get_yaml_file(arguments.project, arguments.yaml_path) if not data: print('Failed to get the snapcraft.yaml file.', file=sys.stderr) sys.exit(-1) From d3f805aa1905c9a21fe67b95039386b11c688743 Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Wed, 27 Nov 2024 17:15:41 +0530 Subject: [PATCH 3/6] Added `yaml-path` input to action.yaml for specifying the path to yaml. --- action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b065824..d25b8bd 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: description: 'Version schema of rock repository' required: false default: 'None' + yaml-path: + description: 'Path to the YAML file' + required: false + default: 'snapcraft.yaml' # Outputs generated by running this action. outputs: @@ -49,7 +53,7 @@ runs: - name: run updatesnapyaml id: updatesnapyaml run: | - ./desktop-snaps/updatesnap/updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN --version-schema $VERSION_SCHEMA --rock-version-schema $ROCK_VERSION_SCHEMA https://github.com/${{ github.repository }} + ./desktop-snaps/updatesnap/updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN --version-schema $VERSION_SCHEMA --rock-version-schema $ROCK_VERSION_SCHEMA --yaml-path $YAML_PATH https://github.com/${{ github.repository }} # Make sure to put the updated snapcraft.yaml file in the right location if it lives in a snap directory if [ -f version_file ]; then echo "IS_VERSION_CHANGE=true" >> $GITHUB_ENV @@ -70,6 +74,7 @@ runs: GITHUB_TOKEN: ${{ inputs.token }} VERSION_SCHEMA: ${{ inputs.version-schema }} ROCK_VERSION_SCHEMA: ${{ inputs.rock-version-schema }} + YAML_PATH: ${{ inputs.yaml-path }} shell: bash # Step to remove the desktop-snaps folder so that when we commit changes in another repo, the desktop-snaps folder is not committed there. From 2046d91fc26e29edcaf571912ad4248b1ff52d3e Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Thu, 28 Nov 2024 16:59:45 +0530 Subject: [PATCH 4/6] Fallback to old code in updatesnapyaml.py when yaml-path is not provided --- action.yml | 2 +- updatesnap/updatesnapyaml.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d25b8bd..a7d7147 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: yaml-path: description: 'Path to the YAML file' required: false - default: 'snapcraft.yaml' + default: 'None' # Outputs generated by running this action. outputs: diff --git a/updatesnap/updatesnapyaml.py b/updatesnap/updatesnapyaml.py index c397bde..6ccde7c 100755 --- a/updatesnap/updatesnapyaml.py +++ b/updatesnap/updatesnapyaml.py @@ -43,6 +43,14 @@ def get_working_branch(self, project_url): def get_yaml_file(self, project_url, yaml_path): """ Searches in a project for the 'snapcraft.yaml' file and returns its contents """ + if yaml_path != 'None': + try: + data = self._github.get_file(project_url, yaml_path) + except (ValueError, ConnectionError): + data = None + return data + + yaml_path = 'snapcraft.yaml' try: data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): @@ -53,6 +61,12 @@ def get_yaml_file(self, project_url, yaml_path): data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): data = None + if not data: + yaml_path = 'rockcraft.yaml' + try: + data = self._github.get_file(project_url, yaml_path) + except (ValueError, ConnectionError): + data = None return data @@ -69,7 +83,7 @@ def main(): help='Version schema of snapping repository') parser.add_argument('--rock-version-schema', action='store', default='None', help='Version schema of rock repository') - parser.add_argument('--yaml-path', action='store', default='snapcraft.yaml', + parser.add_argument('--yaml-path', action='store', default='None', help='Path to the yaml file') parser.add_argument('--verbose', action='store_true', default=False) parser.add_argument('project', default='.', help='The project URI') From 1411435a8d78c776ea8fd70100bebb88afb383e5 Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Thu, 28 Nov 2024 23:49:34 +0530 Subject: [PATCH 5/6] - Use None instead of the string None for the yaml-path argument. - Add logic to move the YAML file to the specified path in `action.yml` --- action.yml | 4 +++- updatesnap/updatesnapyaml.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index a7d7147..101c933 100644 --- a/action.yml +++ b/action.yml @@ -61,7 +61,9 @@ runs: fi if [ -f output_file ]; then echo "IS_CHANGE=true" >> $GITHUB_ENV - if [ -f rockcraft.yaml ]; then + if [ "$YAML_PATH" != 'None' ]; then + mv output_file $YAML_PATH + elif [ -f rockcraft.yaml ]; then mv output_file rockcraft.yaml elif [ -d snap ]; then mv output_file snap/snapcraft.yaml diff --git a/updatesnap/updatesnapyaml.py b/updatesnap/updatesnapyaml.py index 6ccde7c..fac3507 100755 --- a/updatesnap/updatesnapyaml.py +++ b/updatesnap/updatesnapyaml.py @@ -43,7 +43,7 @@ def get_working_branch(self, project_url): def get_yaml_file(self, project_url, yaml_path): """ Searches in a project for the 'snapcraft.yaml' file and returns its contents """ - if yaml_path != 'None': + if yaml_path is not None: try: data = self._github.get_file(project_url, yaml_path) except (ValueError, ConnectionError): @@ -83,7 +83,7 @@ def main(): help='Version schema of snapping repository') parser.add_argument('--rock-version-schema', action='store', default='None', help='Version schema of rock repository') - parser.add_argument('--yaml-path', action='store', default='None', + parser.add_argument('--yaml-path', action='store', default=None, help='Path to the yaml file') parser.add_argument('--verbose', action='store_true', default=False) parser.add_argument('project', default='.', help='The project URI') From b14f7149db7b541e4189a31a2166197d14e1666f Mon Sep 17 00:00:00 2001 From: Rudra-IITM Date: Mon, 2 Dec 2024 15:55:45 +0530 Subject: [PATCH 6/6] Update `action.yml` to handle undefined `yaml-path` arg --- action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 101c933..7a926a7 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,6 @@ inputs: yaml-path: description: 'Path to the YAML file' required: false - default: 'None' # Outputs generated by running this action. outputs: @@ -53,7 +52,7 @@ runs: - name: run updatesnapyaml id: updatesnapyaml run: | - ./desktop-snaps/updatesnap/updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN --version-schema $VERSION_SCHEMA --rock-version-schema $ROCK_VERSION_SCHEMA --yaml-path $YAML_PATH https://github.com/${{ github.repository }} + ./desktop-snaps/updatesnap/updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN --version-schema $VERSION_SCHEMA --rock-version-schema $ROCK_VERSION_SCHEMA ${YAML_PATH:+--yaml-path $YAML_PATH} https://github.com/${{ github.repository }} # Make sure to put the updated snapcraft.yaml file in the right location if it lives in a snap directory if [ -f version_file ]; then echo "IS_VERSION_CHANGE=true" >> $GITHUB_ENV @@ -61,7 +60,7 @@ runs: fi if [ -f output_file ]; then echo "IS_CHANGE=true" >> $GITHUB_ENV - if [ "$YAML_PATH" != 'None' ]; then + if [ -n "$YAML_PATH" ]; then mv output_file $YAML_PATH elif [ -f rockcraft.yaml ]; then mv output_file rockcraft.yaml