-
-
Notifications
You must be signed in to change notification settings - Fork 3
92 lines (75 loc) · 2.85 KB
/
cargo_update.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
87
88
89
90
91
92
name: cargo update
on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
permissions:
contents: write
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."