forked from openproblems-bio/openproblems
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (78 loc) · 2.88 KB
/
pre-commit.yml
File metadata and controls
92 lines (78 loc) · 2.88 KB
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: pre-commit
on:
push:
branches-ignore:
- 'main'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
pre-commit:
runs-on: ubuntu-18.04
container:
image: singlecellopenproblems/openproblems-github-actions:latest
options: --user root
if: >-
!endsWith(github.event.head_commit.message, '# ci skip') &&
(
startsWith(github.ref, 'refs/heads') ||
github.event.pull_request.draft == false
)
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.10.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update -qq || (sudo rm /etc/apt/sources.list.d/* && sudo apt-get update -yqq)
sudo apt-get install -y --no-install-recommends libcurl4-openssl-dev
- name: Set up environment
run: |
echo "LINUX_VERSION=$(uname -a)" >> $GITHUB_ENV
echo "R_VERSION=$(R --version | head -n 1)" >> $GITHUB_ENV
- name: Cache R packages
uses: actions/cache@v3
if: startsWith(runner.os, 'Linux')
with:
path: /usr/local/lib/R/site-library
key: precommit-${{env.LINUX_VERSION}}-${{env.R_VERSION}}-renv-${{ hashFiles('.pre-commit.r_requirements.txt') }}-
restore-keys: |
precommit-${{env.LINUX_VERSION}}-${{env.R_VERSION}}-renv-
- name: Install R packages
run: |
renv::restore()
source("./scripts/install_renv.R")
install_renv(".pre-commit.r_requirements.txt")
shell: Rscript {0}
- name: Cache pre-commit
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}-
- name: Run pre-commit
id: precommit
uses: pre-commit/action@v3.0.0
continue-on-error: true
- name: Commit files
if: steps.precommit.outcome == 'failure' && startsWith(github.ref, 'refs/heads')
run: |
if [[ `git status --porcelain --untracked-files=no` ]]; then
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout -- .github/workflows
git commit -m "pre-commit" -a
fi
shell: bash -e {0}
- name: Push changes
if: steps.precommit.outcome == 'failure' && startsWith(github.ref, 'refs/heads')
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Check pre-commit
if: steps.precommit.outcome == 'failure'
uses: pre-commit/action@v3.0.0