-
Notifications
You must be signed in to change notification settings - Fork 101
86 lines (84 loc) · 3.07 KB
/
compile-requirements.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
commit_and_push:
type: string
default: 'false'
jobs:
compile-requirements:
if: ${{ inputs.commit_and_push != 'true' }}
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@v4
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
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@v4
with:
name: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}-requirements
path: requirements/requirements-${{ matrix.python-version }}-${{ runner.os }}.txt
commit-and-push:
if: ${{ inputs.commit_and_push == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/download-artifact@v4
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 [email protected]
- 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