From 0abc8f9b5e27c72f3bcab54b7d8ea78587074730 Mon Sep 17 00:00:00 2001 From: Christopher Viel Date: Wed, 7 Aug 2024 15:40:06 -0400 Subject: [PATCH] Make sure gradle properties are on the same line (#10) Previously we needed arguments on multiple lines but now we call gradlew from bash. --- action.yml | 60 +++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/action.yml b/action.yml index c335130..3c8f4c3 100644 --- a/action.yml +++ b/action.yml @@ -43,48 +43,39 @@ inputs: runs: using: "composite" steps: - - name: Lookup properties + - name: Process gradle properties id: properties - shell: bash + shell: python + env: + INPUT_GENERATOR_NAME: ${{ inputs.generator-name }} + INPUT_GRADLE_PROPERTIES: ${{ inputs.gradle-properties }} + INPUT_IS_RELEASE: ${{ inputs.is-release }} + INPUT_OPENAPI_SPEC_FILE: ${{ inputs.openapi-spec-file }} + INPUT_PUBLISH: ${{ inputs.publish }} + INPUT_PUBLISH_PAT: ${{ inputs.publish-pat }} run: | - PROPERTIES=( - is-release=${{ inputs.is-release }} - ) - TASK=build - - GENERATOR=${{ inputs.generator-name }} - GENERATOR=${GENERATOR,,} - GENERATOR=${GENERATOR^} - - if [[ "${{ inputs.publish }}" == "true" ]]; then - TASK=publish - PROPERTIES+=(gpr.write.key=${{ inputs.publish-pat }}); + import os + import subprocess - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" - fi + task = 'build' + generator = os.environ.get('INPUT_GENERATOR_NAME').title() + properties = [ '-Pis-release=' + os.environ.get('INPUT_IS_RELEASE') ] - if [[ "${{ inputs.openapi-spec-file }}" != "" ]]; then - PROPERTIES+=(openApiSpec=${{ inputs.openapi-spec-file }}); - fi + if os.environ.get('INPUT_PUBLISH') == 'true': + task = 'publish' + properties.append('-Pgpr.write.key=' + os.environ.get('INPUT_PUBLISH_PAT')) - echo "task-name=${TASK}${GENERATOR}Sdk" >> $GITHUB_OUTPUT - echo "PROPERTIES<> $GITHUB_ENV - printf -- "-P%s\n" "${PROPERTIES[@]}" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV + subprocess.run(['git', 'config', '--global', 'user.email', '41898282+github-actions[bot]@users.noreply.github.com']) + subprocess.run(['git', 'config', '--global', 'user.name', 'github-actions[bot]']) - - name: Process gradle properties - id: gradle-properties - shell: python - env: - GRADLE_PROPERTIES: ${{ inputs.gradle-properties }} - run: | - import os + if os.environ.get('INPUT_OPENAPI_SPEC_FILE'): + properties.append('-PopenApiSpec=' + os.environ.get('INPUT_OPENAPI_SPEC_FILE')) - properties_list: list[str] = [line for line in (line.strip() for line in os.environ.get('GRADLE_PROPERTIES').splitlines()) if line] - properties = list(map(lambda x: f'-P{x}' if not x.startswith('-P') else x, properties_list)) + properties_input: list[str] = [line for line in (line.strip() for line in os.environ.get('INPUT_GRADLE_PROPERTIES').splitlines()) if line] + properties.extend(map(lambda x: f'-P{x}' if not x.startswith('-P') else x, properties_input)) with open(os.environ.get('GITHUB_OUTPUT'), 'a') as output_file: + output_file.write(f'task-name={task}{generator}Sdk\n') output_file.write('gradle-properties=') output_file.write(' '.join(properties)) output_file.write('\n') @@ -101,5 +92,4 @@ runs: ./gradlew \ -p ${{ inputs.gradle-project-path }} \ ${{ steps.properties.outputs.task-name }} \ - ${{ env.PROPERTIES }} \ - ${{ steps.gradle-properties.outputs.gradle-properties }} + ${{ steps.properties.outputs.gradle-properties }}