From b08a2050df841ae3800d7e5f4d969b0714e74b30 Mon Sep 17 00:00:00 2001 From: Zeid Zabaneh Date: Thu, 27 Oct 2022 10:40:33 -0400 Subject: [PATCH] workflows: add compile requirements GitHub Action (bug 1797761) --- .github/workflows/compile-requirements.yml | 82 +++++++++++++++++++ .../workflows/run-compile-requirements.yml | 32 ++++++++ 2 files changed, 114 insertions(+) create mode 100644 .github/workflows/compile-requirements.yml create mode 100644 .github/workflows/run-compile-requirements.yml diff --git a/.github/workflows/compile-requirements.yml b/.github/workflows/compile-requirements.yml new file mode 100644 index 0000000..80b987d --- /dev/null +++ b/.github/workflows/compile-requirements.yml @@ -0,0 +1,82 @@ +name: Generate requirement files + +on: + workflow_call: + inputs: + os: + default: '["ubuntu-latest"]' + description: A string representation of a list of operating systems. + required: false + type: string + python: + default: '["3.10"]' + description: A string representation of a list of Python versions. + required: false + type: string + requirements_directory: + default: requirements + description: The directory where requirements.in is located. + required: false + type: string + requirements_files: + default: '["requirements.in"]' + description: A string representation of a list of requirement files. + required: false + type: string + +jobs: + compile-requirements: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ${{ fromJSON(inputs.os) }} + python-version: ${{ fromJSON(inputs.python) }} + requirements_file: ${{ fromJSON(inputs.requirements_files) }} + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade pip-tools + - name: Generate + # Generate filename based on Python version and OS. + run: | + cd ${{ inputs.requirements_directory }} + python -m piptools compile --verbose ${{ matrix.requirements_file }} --generate-hashes --allow-unsafe --output-file requirements-${{ matrix.python-version }}-${{ runner.os }}.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/upload-artifact@v2 + with: + name: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}-requirements + path: requirements/requirements-${{ matrix.python-version }}-${{ runner.os }}.txt + commit-and-push: + needs: compile-requirements + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - uses: actions/download-artifact@v3 + with: + name: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}-requirements + path: temp-requirements + - name: Configure git + run: | + git config user.name pip-tools compile + git config user.email nomail@example.org + - name: Commit and push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git status + git pull --rebase + find temp-requirements -name "requirements-*" -type f -exec mv -f -t requirements {} + + git add -A + git commit -m "Automatically generated requirements" + git push -f https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git diff --git a/.github/workflows/run-compile-requirements.yml b/.github/workflows/run-compile-requirements.yml new file mode 100644 index 0000000..cbed426 --- /dev/null +++ b/.github/workflows/run-compile-requirements.yml @@ -0,0 +1,32 @@ +name: Generate requirement files + +on: + push: + branches: [requirements] + + pull_request: + branches: [requirements] + +jobs: + call-compile-requirements-linux: + uses: ./.github/workflows/compile-requirements.yml + with: + requirements_files: '["base.in"]' + os: '["ubuntu-latest"]' + python: '["3.7", "3.8", "3.9", "3.10"]' + + call-compile-requirements-windows: + needs: call-compile-requirements-linux + uses: ./.github/workflows/compile-requirements.yml + with: + requirements_files: '["base.in"]' + os: '["windows-latest"]' + python: '["3.7", "3.8", "3.9", "3.10"]' + + call-compile-requirements-macos: + needs: call-compile-requirements-windows + uses: ./.github/workflows/compile-requirements.yml + with: + requirements_files: '["base.in"]' + os: '["macos-latest"]' + python: '["3.7", "3.8", "3.9", "3.10"]'