|
| 1 | +name: Update requirements.txt |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 3 1 * *' # Runs every first day of the month @ 3 AM. |
| 6 | + workflow_dispatch: # Allow manual runs |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-requirements: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Setup global variables |
| 14 | + id: global_vars |
| 15 | + run: | |
| 16 | + echo "TODAYS_DAY=$(date '+%d')" >> $GITHUB_ENV # Ex.: 27 |
| 17 | + echo "TODAYS_MONTH=$(date '+%m')" >> $GITHUB_ENV # Ex.: 07 |
| 18 | + echo "TODAYS_YEAR=$(date '+%Y')" >> $GITHUB_ENV # Ex.: 2023 |
| 19 | + |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v4 |
| 25 | + with: |
| 26 | + python-version: 3.11 # Adjust to your required Python version |
| 27 | + |
| 28 | + - name: Load secrets from 1Password |
| 29 | + id: onepw_secrets |
| 30 | + |
| 31 | + with: |
| 32 | + export-env: true # Export loaded secrets as environment variables |
| 33 | + env: |
| 34 | + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} |
| 35 | + GITHUB_TOKEN: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GitHub generic action token for all repos/credential" |
| 36 | + |
| 37 | + - name: Install pur and update requirements file |
| 38 | + run: | |
| 39 | + pip install --upgrade pur |
| 40 | + pur -r requirements.txt |
| 41 | +
|
| 42 | + - name: Remove venv from git tracking |
| 43 | + run: | |
| 44 | + git clean -fdX venv |
| 45 | +
|
| 46 | + - name: Check for changes |
| 47 | + id: check_changes |
| 48 | + run: | |
| 49 | + if git diff --exit-code requirements.txt; then |
| 50 | + echo "changes=false" >> $GITHUB_ENV |
| 51 | + else |
| 52 | + echo "changes=true" >> $GITHUB_ENV |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Create branch name |
| 56 | + id: create_branch_name |
| 57 | + run: | |
| 58 | + echo "BRANCH=update-requirements-${{ env.TODAYS_YEAR }}-${{ env.TODAYS_MONTH }}-${{ env.TODAYS_DAY }}" >> $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + - name: Create Pull Request |
| 61 | + id: createpr |
| 62 | + if: env.changes == 'true' |
| 63 | + uses: peter-evans/[email protected] |
| 64 | + with: |
| 65 | + token: ${{ env.GITHUB_TOKEN }} |
| 66 | + sign-commits: true |
| 67 | + assignees: "fredericsimard" |
| 68 | + branch: ${{ steps.create_branch_name.outputs.BRANCH }} |
| 69 | + commit-message: 'This PR updates the `requirements.txt` file with the latest versions of dependencies.' |
| 70 | + title: 'Monthly `requirements.txt` update' |
| 71 | + body: 'This PR updates the `requirements.txt` file with the latest versions of dependencies.' |
0 commit comments