-
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
fdf9333
67e8357
e764019
c9c53e6
c05e242
cea77fd
9844688
454f20e
49145b9
bf38243
b59c5b5
85c89d2
a882d41
eec5503
4bb47a9
a4c95e3
8ec9d68
7ee7359
9e18007
ee5f3ab
6f64290
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,115 @@ | ||
| name: Dependency Update | ||
|
Rimsha2535 marked this conversation as resolved.
ArBridgeman marked this conversation as resolved.
|
||
|
|
||
| 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 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Fail if not running on the default branch | ||
|
ckunki marked this conversation as resolved.
|
||
| id: check-branch | ||
| if: github.ref != format('refs/heads/{0}', github.event.repository.default_branch) | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| core.setFailed('Not running on the default branch. github.ref is ${{ github.ref }}') | ||
|
|
||
| - 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 | ||
|
ckunki marked this conversation as resolved.
|
||
| id: audit-dependencies | ||
| run: | | ||
| poetry run -- nox -s dependency:audit | tee vulnerabilities.json | ||
|
ArBridgeman marked this conversation as resolved.
|
||
| LENGTH=$(jq 'length' vulnerabilities.json) | ||
| echo "count=$LENGTH" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Update Dependencies | ||
| id: update-dependencies | ||
| if: steps.audit-dependencies.outputs.count > 0 | ||
|
ArBridgeman marked this conversation as resolved.
|
||
| run: poetry update | ||
|
|
||
| - name: Check for poetry.lock Changes | ||
| id: check-for-poetry-lock-changes | ||
| if: steps.audit-dependencies.outputs.count > 0 | ||
| run: | | ||
| if git diff --quiet -- poetry.lock; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Configure git | ||
| id: configure-git | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| run: | | ||
| git config --global user.email "opensource@exasol.com" | ||
| git config --global user.name "Automatic Dependency Updater" | ||
|
|
||
| - name: Create branch | ||
| id: create-branch | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| run: | | ||
| branch_name="dependency-update/$(date "+%Y-%m-%d_%H:%M:%S")" | ||
| echo "Creating branch $branch_name" | ||
| git switch -C "$branch_name" | ||
|
|
||
| - name: Commit Changes & Push | ||
| id: publish-branch | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| run: | | ||
| branch_name=$(git rev-parse --abbrev-ref HEAD) | ||
| git add poetry.lock | ||
| git commit --message "Updated poetry.lock" | ||
| git push --set-upstream origin "$branch_name" | ||
|
|
||
| - name: Create Pull Request | ||
| id: create-pr | ||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| BASE_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name) | ||
|
|
||
| PR_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\`" | ||
|
ArBridgeman marked this conversation as resolved.
|
||
|
|
||
| PR_URL=$(gh pr create \ | ||
| --base "$BASE_BRANCH" \ | ||
| --title "Update dependencies to fix vulnerabilities ($(date '+%Y-%m-%d'))" \ | ||
| --body "$PR_BODY") | ||
|
|
||
| echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Report New Pull Request to Slack Channel | ||
| id: report-pr-slack | ||
| if: ${{ steps.create-pr.outputs.pr_url }} | ||
| uses: ravsamhq/notify-slack-action@v2 | ||
| with: | ||
| status: '${{ job.status }}' | ||
| token: '${{ secrets.GITHUB_TOKEN }}' | ||
| notification_title: 'Dependency update for {repo} created a Pull Request' | ||
| message_format: '{workflow} created Pull Request ${{ steps.create-pr.outputs.pr_url }}' | ||
| env: | ||
| SLACK_WEBHOOK_URL: '${{ secrets.INTEGRATION_TEAM_SECURITY_UPDATES_WEBHOOK }}' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,14 +48,6 @@ jobs: | |
| permissions: | ||
| contents: read | ||
|
|
||
| test-python-environment: | ||
|
Contributor
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. Why has this been removed, now?
Author
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. @ckunki Sorry, there was a merge conflict in that file and I think this line was accidentally removed while resolving it.
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. Thanks, this shouldn't be removed. It's related to the PTB not fully supporting GitHub workflow changes. |
||
| name: Test python-environment Action | ||
| needs: | ||
| - approve-run-slow-tests | ||
| uses: ./.github/workflows/test-python-environment.yml | ||
| permissions: | ||
| contents: read | ||
|
|
||
| # This job ensures inputs have been executed successfully. | ||
| allow-merge: | ||
| name: Allow Merge | ||
|
|
@@ -70,6 +62,7 @@ jobs: | |
| - test-python-environment | ||
| # To prevent accidentally merges, this step is required. For more details | ||
| # see: https://github.com/exasol/python-toolbox/issues/563 | ||
| # Each job requires a step, so we added this dummy step. | ||
| steps: | ||
| - name: Branch Protection - failure if any ancestor failed or was cancelled | ||
| if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||
| name: Dependency Update | ||||
|
|
||||
| on: | ||||
| schedule: | ||||
| # Every Monday at 03:00 UTC | ||||
| - cron: "0 3 * * 1" | ||||
| workflow_dispatch: | ||||
|
ArBridgeman marked this conversation as resolved.
|
||||
|
|
||||
| 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 | ||||
| with: | ||||
| fetch-depth: 0 | ||||
|
|
||||
| - name: Fail if not running on the default branch | ||||
| id: check-branch | ||||
| if: github.ref != format('refs/heads/{0}', github.event.repository.default_branch) | ||||
| uses: actions/github-script@v8 | ||||
| with: | ||||
| script: | | ||||
| core.setFailed('Not running on the default branch. github.ref is ${{ github.ref }}') | ||||
|
|
||||
| - 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 | tee vulnerabilities.json | ||||
| LENGTH=$(jq 'length' vulnerabilities.json) | ||||
| echo "count=$LENGTH" >> "$GITHUB_OUTPUT" | ||||
|
|
||||
| - name: Update Dependencies | ||||
| id: update-dependencies | ||||
| if: steps.audit-dependencies.outputs.count > 0 | ||||
| run: poetry update | ||||
|
|
||||
| - name: Check for poetry.lock Changes | ||||
| id: check-for-poetry-lock-changes | ||||
| if: steps.audit-dependencies.outputs.count > 0 | ||||
| run: | | ||||
| if git diff --quiet -- poetry.lock; then | ||||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||||
| else | ||||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||||
| fi | ||||
|
|
||||
| - name: Configure git | ||||
| id: configure-git | ||||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||||
| run: | | ||||
| git config --global user.email "opensource@exasol.com" | ||||
| git config --global user.name "Automatic Dependency Updater" | ||||
|
|
||||
| - name: Create branch | ||||
| id: create-branch | ||||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||||
| run: | | ||||
| branch_name="dependency-update/$(date "+%Y-%m-%d_%H:%M:%S")" | ||||
| echo "Creating branch $branch_name" | ||||
| git switch -C "$branch_name" | ||||
|
|
||||
| - name: Commit Changes & Push | ||||
| id: publish-branch | ||||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||||
| run: | | ||||
| branch_name=$(git rev-parse --abbrev-ref HEAD) | ||||
| git add poetry.lock | ||||
| git commit --message "Updated poetry.lock" | ||||
| git push --set-upstream origin "$branch_name" | ||||
|
|
||||
| - name: Create Pull Request | ||||
| id: create-pr | ||||
| if: steps.check-for-poetry-lock-changes.outputs.changed == 'true' | ||||
| env: | ||||
| GH_TOKEN: ${{ github.token }} | ||||
| run: | | ||||
| BASE_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name) | ||||
|
|
||||
| PR_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\`" | ||||
|
|
||||
| PR_URL=$(gh pr create \ | ||||
| --base "$BASE_BRANCH" \ | ||||
| --title "Update dependencies to fix vulnerabilities ($(date '+%Y-%m-%d'))" \ | ||||
| --body "$PR_BODY") | ||||
|
|
||||
| echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT" | ||||
|
|
||||
| pr_url=$(gh pr create \ | ||||
|
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. not needed
Suggested change
|
||||
| --base "$BASE_BRANCH" \ | ||||
|
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. not needed
Suggested change
|
||||
| --title "Update dependencies to fix vulnerabilities ($(date '+%Y-%m-%d'))" \ | ||||
|
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. not needed
Suggested change
|
||||
| --body "Automated dependency update for \`poetry.lock\`.) | ||||
|
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. not needed
Suggested change
|
||||
| echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT" | ||||
|
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. not needed
Suggested change
|
||||
| This PR was created by the dependency update workflow after running: | ||||
|
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. not needed
Suggested change
|
||||
| - \`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. not needed
Suggested change
|
||||
| - \`poetry update\`" | ||||
|
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. not needed
Suggested change
|
||||
| - name: Report New Pull Request to Slack Channel | ||||
| id: report-pr-slack | ||||
| if: ${{ steps.create-pr.outputs.pr_url }} | ||||
| uses: ravsamhq/notify-slack-action@v2 | ||||
| with: | ||||
| status: '${{ job.status }}' | ||||
| token: '${{ secrets.GITHUB_TOKEN }}' | ||||
| notification_title: 'Dependency update for {repo} created a Pull Request' | ||||
| status: '${{ job.status }}', | ||||
|
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. duplicate field
Suggested change
|
||||
| token: '${{ secrets.GITHUB_TOKEN }}', | ||||
|
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. duplicate field
Suggested change
|
||||
| notification_title: 'Dependency update for {repo} created a Pull Request', | ||||
|
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. duplicate field
Suggested change
|
||||
| message_format: '{workflow} created Pull Request ${{ steps.create-pr.outputs.pr_url }}' | ||||
| env: | ||||
| SLACK_WEBHOOK_URL: '${{ secrets.INTEGRATION_TEAM_SECURITY_UPDATES_WEBHOOK }}' | ||||
Uh oh!
There was an error while loading. Please reload this page.