-
Notifications
You must be signed in to change notification settings - Fork 2
add dependency-update workflow template (fixes #683) #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Dependency Update | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every Monday at 03:00 UTC | ||
| - cron: "0 3 * * 1" | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| dependency-update: | ||
| name: Dependency Update | ||
| runs-on: "ubuntu-24.04" | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Check out Repository | ||
| id: check-out-repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Python & Poetry Environment | ||
| id: set-up-python-and-poetry-environment | ||
| uses: exasol/python-toolbox/.github/actions/python-environment@v6 | ||
| with: | ||
| python-version: "3.10" | ||
| poetry-version: "2.3.0" | ||
|
|
||
| - name: Audit Dependencies | ||
| id: audit-dependencies | ||
| run: poetry run -- nox -s dependency:audit | ||
|
|
||
| - name: Update Dependencies | ||
| id: update-dependencies | ||
| run: poetry update | ||
|
|
||
| - name: Check for poetry.lock Changes | ||
| id: check-for-poetry-lock-changes | ||
| run: | | ||
| if git diff --quiet -- poetry.lock; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| id: create-pull-request | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| commit-message: "Update poetry.lock" | ||
| branch: dependency-update/poetry-lock | ||
| delete-branch: true | ||
| title: "Update poetry.lock" | ||
| body: |- | ||
| Automated dependency update for `poetry.lock`. | ||
|
|
||
| This PR was created by the dependency update workflow after running: | ||
| - `poetry run -- nox -s dependency:audit` | ||
| - `poetry update` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| dependency-update | ||
| ================= | ||
|
|
||
| This workflow updates the project dependencies using Poetry. | ||
|
|
||
| It first runs a dependency audit via ``nox -s dependency:audit`` and then updates the dependencies using ``poetry update``. | ||
| If the ``poetry.lock`` file changes, a pull request is created automatically. | ||
|
|
||
| Example Usage | ||
| ------------- | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tbx workflow install dependency-update |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ | |
|
|
||
| python_environment | ||
| security_issues | ||
| dependency_update | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Dependency Update | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every Monday at 03:00 UTC | ||
| - cron: "0 3 * * 1" | ||
| workflow_dispatch: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Was there an approach you and @kratz00 had discussed? One idea is that we could use |
||
|
|
||
| jobs: | ||
| dependency-update: | ||
| name: Dependency Update | ||
| runs-on: "(( os_version ))" | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Check out Repository | ||
| id: check-out-repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Python & Poetry Environment | ||
| id: set-up-python-and-poetry-environment | ||
| uses: exasol/python-toolbox/.github/actions/python-environment@v6 | ||
| with: | ||
| python-version: "(( minimum_python_version ))" | ||
| poetry-version: "(( dependency_manager_version ))" | ||
|
|
||
| - name: Audit Dependencies | ||
| id: audit-dependencies | ||
| run: poetry run -- nox -s dependency:audit | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can ask the users of the python-toolbox what they'd prefer. When I'd written that we perform a check by running One way to do this would be to check the length of the produced JSON; # this will both print the results & output them to a json file
poetry run -- nox -s dependency:audit | tee vulnerabilities.json
LENGTH=$(jq 'length' vulnerabilities.json)
echo "count=$LENGTH" >> $GITHUB_OUTPUTIn the next step, where we run if: steps.audit-dependencies.outputs.count > 0 |
||
|
|
||
| - name: Update Dependencies | ||
| id: update-dependencies | ||
| run: poetry update | ||
|
|
||
| - name: Check for poetry.lock Changes | ||
| id: check-for-poetry-lock-changes | ||
| run: | | ||
| if git diff --quiet -- poetry.lock; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| id: create-pull-request | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| uses: peter-evans/create-pull-request@v7 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we try not to use third-party GitHub actions. This is because they can pose a security risk. Currently, we still use the a few third-party actions, like ravsamhq/notify-slack-action, as there isn't a GitHub equivalent. So for the "Create Pull Request", we'd prefer to use the GitHub provided commands, so this should look mostly the same as: Though, we do not need to have as many initial checks as is provided in: |
||
| with: | ||
| commit-message: "Update poetry.lock" | ||
| branch: dependency-update/poetry-lock | ||
| delete-branch: true | ||
| title: "Update poetry.lock" | ||
| body: | | ||
| Automated dependency update for `poetry.lock`. | ||
|
|
||
| This PR was created by the dependency update workflow after running: | ||
| - `poetry run -- nox -s dependency:audit` | ||
| - `poetry update` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to change it this time, but by convention, we normally name the branch
feature/683-dependency-update-workflow.By having the issue number in the branch name, we can better ensure that the branch name is unique. This can be helpful for locally checking out the branch as it makes it easily more identifiable.