Skip to content

Commit 45e53de

Browse files
committed
Check for updates automatically every day
1 parent 7595819 commit 45e53de

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

.github/workflows/update.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Update
2+
3+
on:
4+
schedule:
5+
# The scheduled jobs run only on `master`. Then we checkout `ja-all-enable`.
6+
# <https://github.community/t5/GitHub-Actions/Scheduled-builds-of-non-default-branch/td-p/32270>
7+
- cron: '0 0 * * *'
8+
push:
9+
branches:
10+
- master
11+
- ja-all-enabled
12+
13+
jobs:
14+
update:
15+
name: Update
16+
runs-on: ubuntu-18.04
17+
18+
steps:
19+
- name: checkout
20+
uses: actions/checkout@v2
21+
with:
22+
ref: ja-all-enabled
23+
24+
- name: setup-python
25+
uses: actions/setup-python@v1
26+
with:
27+
python-version: 3.8.0
28+
29+
- name: rust-toolchain
30+
uses: actions-rs/toolchain@v1
31+
with:
32+
toolchain: stable-x86_64-unknown-linux-gnu
33+
default: true
34+
profile: minimal
35+
36+
- name: '`cargo install --debug --bin cargo-add cargo-edit`'
37+
uses: actions-rs/cargo@v1
38+
with:
39+
command: install
40+
args: --debug --bin cargo-add cargo-edit
41+
42+
- name: '`cargo install --debug cargo-outdated`'
43+
uses: actions-rs/cargo@v1
44+
with:
45+
command: install
46+
args: --debug cargo-outdated
47+
48+
- name: Upgrade the dependencies
49+
id: upgrade
50+
run: |
51+
import json
52+
import subprocess
53+
from collections import defaultdict
54+
55+
cargo_outdated = json.loads(subprocess.run(
56+
['cargo', 'outdated', '--format', 'json', '-d', '1'],
57+
stdout=subprocess.PIPE, check=True,
58+
).stdout.decode('utf8'))
59+
60+
crates = defaultdict(list)
61+
body = '<ul>'
62+
63+
for dependency in cargo_outdated['dependencies']:
64+
if dependency['kind'] != 'Normal':
65+
raise NotImplemented()
66+
crates[dependency['platform']].append(
67+
(dependency['name'], dependency['latest']),
68+
)
69+
body += f'<li>' \
70+
f'<a href="https://crates.io/crates/{dependency["name"]}">' \
71+
f'{dependency["name"]}' \
72+
f'</a> ' \
73+
f'v{dependency["project"]} → v{dependency["latest"]}' \
74+
f'</li>'
75+
body += '</ul>'
76+
if body == '<ul></ul>':
77+
body = 'Only dependencies of dependencies.'
78+
79+
for target, crates in crates.items():
80+
args = ['cargo', 'add']
81+
if target:
82+
args.extend(['--target', target])
83+
args.extend(f'{name}@={ver}' for name, ver in crates)
84+
subprocess.run(args, check=True)
85+
86+
print(f'::set-output name=body::{body}')
87+
shell: python3 {0}
88+
89+
- name: '`cargo update`'
90+
uses: actions-rs/cargo@v1
91+
with:
92+
command: update
93+
94+
- name: Check PRs
95+
id: check-prs
96+
run: echo "::set-output name=already-created=$(curl https://api.github.com/repos/rust-lang-ja/atcoder-rust-base/pulls | jq -C 'map(.title) | any(contains("[bot] Update the crates"))')"
97+
98+
- name: Create Pull Request
99+
uses: peter-evans/create-pull-request@v2
100+
with:
101+
token: ${{ secrets.GITHUB_TOKEN }}
102+
commit-message: '[bot] Update the crates'
103+
title: '[bot] Update the crates'
104+
body: ${{ steps.upgrade.outputs.body }}
105+
branch: ja-all-enabled-update-the-crates
106+
base: ja-all-enabled
107+
branch-suffix: timestamp
108+
if: steps.check-prs.outputs.already-created == 'false'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy