-
Notifications
You must be signed in to change notification settings - Fork 96
94 lines (82 loc) · 2.95 KB
/
pre-commit.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
93
94
name: pre-commit
on:
push:
branches-ignore:
- 'master'
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up environment
run: |
echo "UBUNTU_VERSION=`grep DISTRIB_RELEASE /etc/lsb-release | sed 's/.*=//g'`" >> $GITHUB_ENV
mkdir -p .local/R/site-packages
echo "R_LIBS_USER=`pwd`/.local/R/site-packages" >> $GITHUB_ENV
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update -qq
sudo apt-get install -y libcurl4-openssl-dev
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
architecture: "x64"
- name: Cache pre-commit
uses: actions/cache@v2
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}-
- name: Run pre-commit
uses: pre-commit/action@v2.0.0
- name: Cache R packages
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
with:
path: ${{env.R_LIBS_USER}}
key: precommit-${{env.UBUNTU_VERSION}}-renv-${{ hashFiles('Rmagic/.pre-commit.r_requirements.txt') }}-${{ hashFiles('Rmagic/DESCRIPTION') }}-
restore-keys: |
precommit-${{env.UBUNTU_VERSION}}-renv-${{ hashFiles('Rmagic/.pre-commit.r_requirements.txt') }}-
precommit-${{env.UBUNTU_VERSION}}-renv-
- name: Install R packages
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
con = file("Rmagic/.pre-commit.r_requirements.txt", "r")
while ( length(pkg <- readLines(con, n = 1)) > 0 ) {
renv::install(pkg)
}
close(con)
if (!require("devtools")) install.packages("devtools", repos="http://cloud.r-project.org")
devtools::install_dev_deps("./Rmagic", upgrade=TRUE)
devtools::install("./Rmagic")
shell: Rscript {0}
- name: Run pre-commit for R
run: |
cd Rmagic
git init
git add *
pre-commit run --all-files
rm -rf .git
cd ..
- name: Commit files
if: failure()
run: |
git checkout -- .github/workflows
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 commit -m "pre-commit" -a
fi
- name: Push changes
if: failure()
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}