-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
18 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: cargo update | |
|
||
on: | ||
schedule: | ||
- cron: '0 8 * * *' | ||
- cron: "0 8 * * *" | ||
workflow_dispatch: | ||
|
||
permissions: | ||
|
@@ -12,81 +12,6 @@ env: | |
TZ: Europe/Stockholm | ||
|
||
jobs: | ||
update-dependencies: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.DELTA_BOT_GH_TOKEN }} | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Set up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
|
||
- name: Cache Cargo Dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo | ||
target | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-cargo- | ||
- name: Install Protobuf | ||
run: sudo apt-get install -y protobuf-compiler | ||
|
||
- name: Install cargo-edit and cargo-outdated | ||
run: | | ||
cargo install cargo-edit | ||
cargo install cargo-outdated | ||
- name: Get Outdated Dependencies | ||
id: outdated_before | ||
run: cargo outdated > outdated_before.txt | ||
|
||
- name: Update Dependencies | ||
id: update_step | ||
run: | | ||
BRANCH_NAME="update-dependencies-$(date +%Y%m%d%H%M%S)" | ||
git checkout -b "$BRANCH_NAME" | ||
echo "Branch created: $BRANCH_NAME" | ||
# Update all dependencies | ||
cargo update | ||
- name: Get Updated Dependencies | ||
id: outdated_after | ||
run: cargo outdated > outdated_after.txt | ||
|
||
- name: Commit and Push Changes | ||
if: steps.update_step.outputs.changes_detected == 'true' | ||
run: | | ||
git config --global user.name "dmlops" | ||
git config --global user.email "[email protected]" | ||
git add . | ||
UPDATED_DEPS=$(diff -u outdated_before.txt outdated_after.txt | grep '^+[^+]' | sed 's/^+//') | ||
COMMIT_MSG="Bump dependencies\n\n$UPDATED_DEPS" | ||
git commit -m "$COMMIT_MSG" | ||
git push https://x-access-token:${{ secrets.DELTA_BOT_GH_TOKEN }}@github.com/${{ github.repository }} $BRANCH_NAME | ||
echo "Changes committed and pushed to $BRANCH_NAME" | ||
- name: Create Pull Request | ||
if: steps.update_step.outputs.changes_detected == 'true' | ||
run: | | ||
# Compare outdated dependencies before and after update | ||
UPDATED_DEPS=$(diff -u outdated_before.txt outdated_after.txt | grep '^+[^+]' | sed 's/^+//') | ||
PR_BODY="Bump dependencies\n\n$UPDATED_DEPS" | ||
# Create a pull request | ||
PR_URL=$(gh pr create --base master --head $BRANCH_NAME --title "Update dependencies" --body "$PR_BODY" --draft=false --label "dependencies") | ||
echo "Pull request created: $PR_URL" | ||
# Automatically merge the pull request after it meets the requirements | ||
gh pr merge "$PR_URL" --merge --delete-branch | ||
echo "Pull request merged and branch deleted." | ||
build: | ||
uses: blackportal-ai/infra/.github/workflows/cargo-update.yml@master | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,64 +13,5 @@ env: | |
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.DELTA_BOT_GH_TOKEN }} | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Set up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
|
||
- name: Cache Cargo Dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo | ||
target | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-cargo- | ||
- name: Install Protobuf | ||
run: sudo apt-get install -y protobuf-compiler | ||
|
||
- name: Install cargo-machete | ||
run: cargo install cargo-machete | ||
|
||
- name: Create Branch and Fix Unused Dependencies | ||
id: cleanup_step | ||
run: | | ||
BRANCH_NAME="cleanup-$(date +%Y%m%d%H%M%S)" | ||
git checkout -b "$BRANCH_NAME" | ||
echo "Branch created: $BRANCH_NAME" | ||
# Run cargo machete --fix and capture its exit code | ||
cargo machete --fix || true | ||
# Check if there are changes after fixing | ||
if [[ -n "$(git status --porcelain)" ]]; then | ||
git config --global user.name "dmlops" | ||
git config --global user.email "[email protected]" | ||
git add . | ||
git commit -m "Fixing unused dependencies" | ||
git push https://x-access-token:${{ secrets.DELTA_BOT_GH_TOKEN }}@github.com/${{ github.repository }} $BRANCH_NAME | ||
echo "Changes committed and pushed to $BRANCH_NAME" | ||
echo "Attempting to create a pull request..." | ||
# Create a pull request | ||
PR_URL=$(gh pr create --base master --head $BRANCH_NAME --title "Fix unused dependencies" --body "This PR fixes unused dependencies found by cargo machete." --draft=false --label "dependencies") | ||
echo "Pull request created: $PR_URL" | ||
# Automatically merge the pull request after it meets the requirements | ||
gh pr merge "$PR_URL" --squash --delete-branch | ||
echo "Pull request merged and branch deleted." | ||
else | ||
echo "No changes detected. No commit or push." | ||
fi | ||
uses: blackportal-ai/infra/.github/workflows/core.yml@master | ||
secrets: inherit |