Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Argument to Specify YAML File Path #813

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -49,15 +52,17 @@ 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
rm version_file
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
Expand All @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions updatesnap/updatesnapyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
rudra-iitm marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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:])
Expand All @@ -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)
Expand Down