forked from ScribeMD/pre-commit-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
159 lines (156 loc) · 5.46 KB
/
action.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Pre-commit Optimized for ScribeMD/pre-commit-hooks
author: Kurt von Laven
description: >
Install pre-commit via asdf and Poetry; then run pre-commit hooks with extra
optimizations for ScribeMD/pre-commit-hooks.
branding:
icon: wind
color: orange
inputs:
bump:
description: >
If "true," run the Commitizen action on push to main to commit a version
bump and tag a release if there are any release-worthy changes. Commitizen
relies on tags in order to perform an incremental release, so you must pass
fetch-depth: 0 to the official GitHub checkout action unless bump is
"false."
required: false
default: "true"
runs:
using: composite
steps:
- name: Get operating system name and version.
id: os
run: echo "IMAGE=$ImageOS" >>"$GITHUB_OUTPUT"
shell: bash
- name: Get asdf versions of tools with first-class GitHub Actions support.
id: tool-versions
run: |
file=()
while IFS= read -r line; do
array=($line)
tool="${array[0]}"
version="${array[1]}"
case $tool in
dotnet-core | nodejs | python)
echo "$tool=$version" >>"$GITHUB_OUTPUT"
;;
*)
file+=("$line")
;;
esac
done <.tool-versions
# Remove tools to be installed via actions/setup-* from .tool-versions.
printf "%s\n" "${file[@]}" >.tool-versions
shell: bash
- name: Set up .NET SDK at version specified in .tool-versions.
if: steps.tool-versions.outputs.dotnet-core != ''
uses: actions/setup-dotnet@v3.0.2
with:
dotnet-version: ${{ steps.tool-versions.outputs.dotnet-core }}
- name: Set up Node.js at version specified in .tool-versions.
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ steps.tool-versions.outputs.nodejs }}
- name: Set up Python at version specified in .tool-versions.
uses: actions/setup-python@v4.3.0
with:
python-version: ${{ steps.tool-versions.outputs.python }}
- name: Install asdf.
uses: asdf-vm/actions/setup@v1.1.0
with:
asdf_branch: v0.10.2
- name: Cache asdf and asdf-managed tools.
uses: actions/cache@v3.0.11
id: asdf-cache
with:
path: ${{ env.ASDF_DIR }}
key: >
asdf-v0.10.2-${{ steps.os.outputs.IMAGE }}-${{
hashFiles('**/.tool-versions')
}}
- name: Install asdf-managed tools based on .tool-versions.
if: steps.asdf-cache.outputs.cache-hit != 'true'
uses: asdf-vm/actions/install@v1.1.0
- name: Restore .tool-versions.
run: git restore .tool-versions
shell: bash
- name: Get Poetry cache directory.
id: poetry-cache
run: |
poetry_cache="$(poetry config -- cache-dir)"
echo "PATH=$poetry_cache" >>"$GITHUB_OUTPUT"
shell: bash
- name: Cache Poetry dependencies.
uses: actions/cache@v3.0.11
with:
path: |
${{ steps.poetry-cache.outputs.PATH }}
.venv
key: >
poetry-${{ steps.os.outputs.IMAGE }}-${{ hashFiles(
'poetry.toml',
'**/poetry.lock'
) }}
- name: Install Poetry dependencies.
run: poetry install --sync
shell: bash
- name: Get npm cache directory.
id: npm-cache
run: |
npm_cache="$(npm config get cache)"
echo "PATH=$npm_cache" >>"$GITHUB_OUTPUT"
shell: bash
- name: Cache npm dependencies.
uses: actions/cache@v3.0.11
with:
path: ${{ steps.npm-cache.outputs.PATH }}
key: >
node-${{ steps.os.outputs.IMAGE }}-${{ hashFiles(
'.mega-linter.yaml',
'.pre-commit-config.yaml',
'.pre-commit-hooks.yaml'
) }}
- name: Use Docker in rootless mode.
uses: ScribeMD/rootless-docker@0.2.1
- name: Cache Docker images.
uses: ScribeMD/docker-cache@0.2.4
with:
key: >
docker-${{ steps.os.outputs.IMAGE }}-${{
hashFiles('.pre-commit-config.yaml')
}}
- name: Cache pre-commit hooks.
uses: actions/cache@v3.0.11
with:
path: ~/.cache/pre-commit
key: >
pre-commit-${{ steps.os.outputs.IMAGE }}-${{ hashFiles(
'**/.tool-versions',
'**/poetry.lock',
'.pre-commit-config.yaml'
) }}
- name: Run pre-push hooks.
run: |
git remote set-head origin --auto # for commitizen-branch hook
if [[ $GITHUB_REF_NAME == 'main' ]]; then
export SKIP=asdf-install,commitizen-branch,no-commit-to-branch
else
export SKIP=asdf-install
fi
poetry run pre-commit run \
--all-files --hook-stage push --show-diff-on-failure --color always
poetry run pre-commit uninstall # Don't break subsequent Git commands.
shell: bash
- name: Push a commit to main to bump version and update changelog.
if: >
inputs.bump == 'true'
&& github.event_name == 'push' && github.ref == 'refs/heads/main'
&& !startsWith(github.event.head_commit.message, 'bump:')
uses: commitizen-tools/commitizen-action@0.15.0
with:
git_name: commitizen-github-action[bot]
git_email: commitizen-github-action[bot]@users.noreply.github.com
github_token: ${{ github.token }}
commitizen_version: 2.35.0 # Keep in sync with .pre-commit-config.yaml and pyproject.toml.
check_consistency: true