-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (72 loc) · 2.64 KB
/
ci.yaml
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
name: CI
on:
pull_request: # Start the job on all PRs
branches: [master, main]
types: [synchronize, opened, reopened, ready_for_review]
push: # Start the job on all main branch push
branches: [master, main]
jobs:
precommit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Set shfmt version environment variable
run: echo "SHFMT_VERSION=v3.7.0" >> $GITHUB_ENV
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-
restore-keys: |
${{ runner.os }}-pip-
- name: Cache shfmt binary
uses: actions/cache@v3
with:
path: /usr/local/bin/shfmt
key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
restore-keys: |
${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
${{ runner.os }}-shfmt-
- name: Cache Pre-Commit environments
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pc-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pc-${{ hashFiles('.pre-commit-config.yaml') }}
${{ runner.os }}-pc-
- name: Install dependencies
run: |
python -m pip install pre-commit
pre-commit install
- name: Install shfmt
run: |
SHFMT_VERSION=${{ env.SHFMT_VERSION }}
SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64"
if [[ ! -f /usr/local/bin/shfmt ]]; then
wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}"
chmod +x shfmt
sudo mv shfmt /usr/local/bin/
fi
sudo apt-get install shellcheck
- name: Run pre-commits
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///')
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_REPOSITORY" | jq -r '.default_branch')
git fetch
CUR_SHA=$(git log --pretty=tformat:"%H" -n1 . | tail -n1)
echo "Default branch is $DEFAULT_BRANCH"
echo "Current SHA is $CUR_SHA"
if [[ $GITHUB_REF == "refs/heads/$DEFAULT_BRANCH" ]]; then
pre-commit run --all
else
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref $CUR_SHA
fi