From 9ec7540c4b51f417d952dc76a75d42b2d0e26016 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:14:52 -0400 Subject: [PATCH] Common setup-python in github action (#15901) --- .github/actions/awx_devel_image/action.yml | 4 +--- .github/actions/setup-python/action.yml | 27 ++++++++++++++++++++++ .github/workflows/ci.yml | 15 ++++-------- .github/workflows/devel_images.yml | 6 +---- .github/workflows/docs.yml | 2 +- .github/workflows/label_issue.yml | 4 +++- .github/workflows/label_pr.yml | 2 +- .github/workflows/promote.yml | 8 +------ .github/workflows/stage.yml | 9 ++------ .github/workflows/upload_schema.yml | 8 +------ 10 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 .github/actions/setup-python/action.yml diff --git a/.github/actions/awx_devel_image/action.yml b/.github/actions/awx_devel_image/action.yml index c2c9ba8ffb..354279f2c3 100644 --- a/.github/actions/awx_devel_image/action.yml +++ b/.github/actions/awx_devel_image/action.yml @@ -11,9 +11,7 @@ inputs: runs: using: composite steps: - - name: Get python version from Makefile - shell: bash - run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV + - uses: ./.github/actions/setup-python - name: Set lower case owner name shell: bash diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 0000000000..be57da06fc --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,27 @@ +name: 'Setup Python from Makefile' +description: 'Extract and set up Python version from Makefile' +inputs: + python-version: + description: 'Override Python version (optional)' + required: false + default: '' + working-directory: + description: 'Directory containing the Makefile' + required: false + default: '.' +runs: + using: composite + steps: + - name: Get python version from Makefile + shell: bash + run: | + if [ -n "${{ inputs.python-version }}" ]; then + echo "py_version=${{ inputs.python-version }}" >> $GITHUB_ENV + else + cd ${{ inputs.working-directory }} + echo "py_version=`make PYTHON_VERSION`" >> $GITHUB_ENV + fi + - name: Install python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.py_version }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53d51b55b0..18dc0b76d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -130,7 +130,7 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v5 + - uses: ./.github/actions/setup-python with: python-version: '3.x' @@ -172,14 +172,9 @@ jobs: repository: ansible/awx-operator path: awx-operator - - name: Get python version from Makefile - working-directory: awx - run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV - - - name: Install python ${{ env.py_version }} - uses: actions/setup-python@v4 + - uses: ./awx/.github/actions/setup-python with: - python-version: ${{ env.py_version }} + working-directory: awx - name: Install playbook dependencies run: | @@ -283,7 +278,7 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v5 + - uses: ./.github/actions/setup-python with: python-version: '3.x' @@ -359,7 +354,7 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v5 + - uses: ./.github/actions/setup-python with: python-version: '3.x' diff --git a/.github/workflows/devel_images.yml b/.github/workflows/devel_images.yml index 39941e7774..069d2c8451 100644 --- a/.github/workflows/devel_images.yml +++ b/.github/workflows/devel_images.yml @@ -49,14 +49,10 @@ jobs: run: | echo "DEV_DOCKER_TAG_BASE=ghcr.io/${OWNER,,}" >> $GITHUB_ENV echo "COMPOSE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV - echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV env: OWNER: '${{ github.repository_owner }}' - - name: Install python ${{ env.py_version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.py_version }} + - uses: ./.github/actions/setup-python - name: Log in to registry run: | diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e520ffdae2..ec6c9f4a4f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -12,7 +12,7 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v5 + - uses: ./.github/actions/setup-python with: python-version: '3.x' diff --git a/.github/workflows/label_issue.yml b/.github/workflows/label_issue.yml index 9f666588c9..952685cd54 100644 --- a/.github/workflows/label_issue.yml +++ b/.github/workflows/label_issue.yml @@ -34,9 +34,11 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup-python + - name: Install python requests run: pip install requests + - name: Check if user is a member of Ansible org uses: jannekem/run-python-script-action@v1 id: check_user diff --git a/.github/workflows/label_pr.yml b/.github/workflows/label_pr.yml index a5d5aa861f..43f1e3a291 100644 --- a/.github/workflows/label_pr.yml +++ b/.github/workflows/label_pr.yml @@ -33,7 +33,7 @@ jobs: with: show-progress: false - - uses: actions/setup-python@v5 + - uses: ./.github/actions/setup-python with: python-version: '3.x' diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index d84e4ad81e..ba723c07f9 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -36,13 +36,7 @@ jobs: with: show-progress: false - - name: Get python version from Makefile - run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV - - - name: Install python ${{ env.py_version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.py_version }} + - uses: ./.github/actions/setup-python - name: Install dependencies run: | diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index 1e6f8e5fd6..2f4e066061 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -64,14 +64,9 @@ jobs: repository: ansible/awx-logos path: awx-logos - - name: Get python version from Makefile - working-directory: awx - run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV - - - name: Install python ${{ env.py_version }} - uses: actions/setup-python@v4 + - uses: ./awx/.github/actions/setup-python with: - python-version: ${{ env.py_version }} + working-directory: awx - name: Install playbook dependencies run: | diff --git a/.github/workflows/upload_schema.yml b/.github/workflows/upload_schema.yml index 09d9860c94..73eef5d646 100644 --- a/.github/workflows/upload_schema.yml +++ b/.github/workflows/upload_schema.yml @@ -23,13 +23,7 @@ jobs: with: show-progress: false - - name: Get python version from Makefile - run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV - - - name: Install python ${{ env.py_version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.py_version }} + - uses: ./.github/actions/setup-python - name: Log in to registry run: |