diff --git a/action.yml b/action.yml index b065824..7a926a7 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,9 @@ inputs: description: 'Version schema of rock repository' required: false default: 'None' + yaml-path: + description: 'Path to the YAML file' + required: false # Outputs generated by running this action. outputs: @@ -49,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 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 @@ -57,7 +60,9 @@ runs: fi if [ -f output_file ]; then echo "IS_CHANGE=true" >> $GITHUB_ENV - if [ -f rockcraft.yaml ]; then + if [ -n "$YAML_PATH" ]; 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 @@ -70,6 +75,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. diff --git a/updatesnap/updatesnapyaml.py b/updatesnap/updatesnapyaml.py index 6f6c8b4..fac3507 100755 --- a/updatesnap/updatesnapyaml.py +++ b/updatesnap/updatesnapyaml.py @@ -40,9 +40,16 @@ 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, yaml_path): """ Searches in a project for the 'snapcraft.yaml' file and returns its contents """ + if yaml_path is not 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) @@ -76,6 +83,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('--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') arguments = parser.parse_args(sys.argv[1:]) @@ -88,7 +97,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.yaml_path) if not data: print('Failed to get the snapcraft.yaml file.', file=sys.stderr) sys.exit(-1)