Skip to content

Commit 8efd394

Browse files
authored
autoformat bot in CI (#437)
* draft autoformat bot * stop CI on outdatted commits * simplify the cache action * misformat on purpose * a PR template explaining the presence of a bot * mention resetting the test runner in the PR template * linter bot commit -- feel free to overwrite --------- Co-authored-by: Krastanov <[email protected]>
1 parent 9689498 commit 8efd394

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

.github/pull_request_template.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Please make sure to leave this PR editable by maintainers of this repo.
2+
3+
Please make sure you have consulted [CONTRIBUTING](https://github.com/JuliaGraphs/Graphs.jl/blob/master/CONTRIBUTING.md)
4+
5+
The linter bot might add new commits to your PR (e.g. to take care of formatting issues). Feel free to overwrite these commits.
6+
7+
If the linter bot is the last one to put in a commit, **THE TESTS WILL NOT RUN**. Either lint/format your contributions yourself as described in CONTRIBUTING.md or close&reopen the PR to reset the test runner.

.github/workflows/ci.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI
22
env:
33
JULIA_NUM_THREADS: 2
4+
concurrency:
5+
# group by workflow and ref; the last slightly strange component ensures that for pull
6+
# requests, we limit to 1 concurrent job, but for the master branch we don't
7+
group: ${{ github.workflow }}-${{ github.ref }}-${{ (github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main') || github.run_number }}
8+
# Cancel intermediate builds, but only if it is a pull request build.
9+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
410
on:
511
pull_request:
612
branches:
@@ -32,16 +38,7 @@ jobs:
3238
with:
3339
version: ${{ matrix.version }}
3440
arch: ${{ matrix.arch }}
35-
- uses: actions/cache@v4
36-
env:
37-
cache-name: cache-artifacts
38-
with:
39-
path: ~/.julia/artifacts
40-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
41-
restore-keys: |
42-
${{ runner.os }}-test-${{ env.cache-name }}-
43-
${{ runner.os }}-test-
44-
${{ runner.os }}-
41+
- uses: julia-actions/cache@v2
4542
- uses: julia-actions/julia-buildpkg@v1
4643
- uses: julia-actions/julia-runtest@v1
4744
- uses: julia-actions/julia-processcoverage@v1

.github/workflows/prprecommit.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: PR Pre-Commit Bot
2+
env:
3+
JULIA_NUM_THREADS: 2
4+
concurrency:
5+
# group by workflow and ref; the last slightly strange component ensures that for pull
6+
# requests, we limit to 1 concurrent job, but for the master branch we don't
7+
group: ${{ github.workflow }}-${{ github.ref }}-${{ (github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main') || github.run_number }}
8+
# Cancel intermediate builds, but only if it is a pull request build.
9+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
10+
on:
11+
pull_request:
12+
branches: ["master", "main"]
13+
jobs:
14+
pre-commit:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.head_ref }}
21+
- name: Setup Julia
22+
uses: julia-actions/setup-julia@v2
23+
with:
24+
version: '1'
25+
- uses: julia-actions/cache@v2
26+
- name: Setup JuliaFormatter
27+
run: |
28+
julia -e '
29+
using Pkg
30+
Pkg.add(name="JuliaFormatter", version="1.0.62")'
31+
- name: Setup Python
32+
uses: actions/setup-python@v3
33+
- name: Run pre-commit
34+
uses: pre-commit/[email protected]
35+
continue-on-error: true
36+
- name: Potentially commit changes
37+
uses: stefanzweifel/git-auto-commit-action@v5
38+
with:
39+
commit_message: linter bot commit -- feel free to overwrite

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: "https://github.com/domluna/JuliaFormatter.jl"
3+
rev: "v1.0.62"
4+
hooks:
5+
- id: "julia-formatter"

src/core.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ add_vertices!(g::AbstractGraph, n::Integer) = sum([add_vertex!(g) for i in 1:n])
4848
indegree(g[, v])
4949
5050
Return a vector containing the indegrees of every vertex of the graph `g`, where
51-
the indegree of a vertex is defined as the number of edges which end at that
51+
the indegree of a vertex is defined as the number of edges which end at that
5252
vertex. If `v` is specified and is a single vertex, only return the indegree of
5353
`v`. If `v` is specified and is a vector of vertices, only return the indegrees
5454
of the vertices in `v`.
@@ -85,7 +85,7 @@ indegree(g::AbstractGraph, vs=vertices(g)) = [indegree(g, x) for x in vs]
8585
outdegree(g[, v])
8686
8787
Return a vector containing the outdegrees of every vertex of the graph `g`, where
88-
the outdegree of a vertex is defined as the number of edges which start at that
88+
the outdegree of a vertex is defined as the number of edges which start at that
8989
vertex. If `v` is specified and is a single vertex, only return the outdegree of
9090
`v`. If `v` is specified and is a vector of vertices, only return the outdegrees
9191
of the vertices in `v`.
@@ -124,7 +124,7 @@ outdegree(g::AbstractGraph, vs=vertices(g)) = [outdegree(g, x) for x in vs]
124124
Return a vector containing the degrees of every vertex of the graph `g`, where
125125
the degree of a vertex is defined as the number of edges which start or end at
126126
that vertex. For directed graphs, the degree of a vertex is equal to the sum of
127-
its indegree and outdegree. If `v` is specified and is a single vertex, only
127+
its indegree and outdegree. If `v` is specified and is a single vertex, only
128128
return the degree of `v`. If `v` is specified and is a vector of vertices, only
129129
return the degrees of the vertices in `v`.
130130

0 commit comments

Comments
 (0)