-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yaml
More file actions
195 lines (190 loc) · 7.76 KB
/
action.yaml
File metadata and controls
195 lines (190 loc) · 7.76 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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 | ruby)
echo "$tool=$version" >>"$GITHUB_OUTPUT"
echo "${tool}-string=${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 the version specified in .tool-versions.
if: steps.tool-versions.outputs.dotnet-core != ''
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
dotnet-version: ${{ steps.tool-versions.outputs.dotnet-core }}
- name: Set up Node.js at the version specified in .tool-versions.
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: ${{ steps.tool-versions.outputs.nodejs }}
- name: Set up Python at the version specified in .tool-versions.
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ steps.tool-versions.outputs.python }}
- name: Set up Ruby at the version specified in .tool-versions.
if: steps.tool-versions.outputs.ruby != ''
uses: ruby/setup-ruby@af848b40be8bb463a751551a1180d74782ba8a72 # v1.162.0
with:
ruby-version: ${{ steps.tool-versions.outputs.ruby }}
- name: Install asdf.
uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 # v3.0.2
with:
asdf_branch: v0.13.1
- name: Cache asdf and asdf-managed tools.
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: asdf-cache
with:
path: ${{ env.ASDF_DIR }}
key: >
asdf-v0.13.1-${{ 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@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 # v3.0.2
- 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@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
${{ steps.poetry-cache.outputs.PATH }}
.venv
key: >
poetry-${{ steps.os.outputs.IMAGE }}-${{
steps.tool-versions.outputs.python-string
}}${{
hashFiles('poetry.toml', '**/poetry.lock')
}}
restore-keys: |
poetry-${{ steps.os.outputs.IMAGE }}-${{ steps.tool-versions.outputs.python-string }}
- name: Configure Poetry to use Python version specified in .tool-versions.
run: poetry env use "${{ steps.tool-versions.outputs.python }}"
shell: bash
- 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@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
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@6bd157a512c2fafa4e0243a8aa87d964eb890886 # 0.2.2
- name: Determine name of MegaLinter Docker image from pre-commit config.
id: megalinter
run: |
from os import environ
from re import compile
_MEGALINTER_ARGS_PATTERN = compile(
"args:\\s*&megalinter-args\\s*\\[--flavor,\\s*(?P<flavor>\\w+),"
"\\s*--release,\\s*(?P<release>v(\\d+\\.){2}\\d+)"
)
with open(".pre-commit-config.yaml", encoding="utf-8") as input_stream:
for line in input_stream:
if match := _MEGALINTER_ARGS_PATTERN.search(line):
break
flavor = match.group("flavor")
release = match.group("release")
docker_image = f"megalinter-{flavor}:{release}"
output_file = environ["GITHUB_OUTPUT"]
with open(output_file, "a", encoding="utf-8") as output_stream:
output_stream.write(f"DOCKER_IMAGE={docker_image}\n")
shell: python
- name: Cache Docker images.
uses: ScribeMD/docker-cache@e53d303afe42d4c1ebeeb8ab0b4c47eba1bbf3e0 # 0.3.6
with:
key: ${{ steps.megalinter.outputs.DOCKER_IMAGE }}
- name: Cache pre-commit hooks.
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cache/pre-commit
key: >
pre-commit-${{ steps.os.outputs.IMAGE }}-${{
steps.tool-versions.outputs.ruby-string || ''
}}${{ hashFiles(
'**/.tool-versions',
'**/poetry.lock',
'.pre-commit-config.yaml'
) }}
restore-keys: |
pre-commit-${{ steps.os.outputs.IMAGE }}-${{ steps.tool-versions.outputs.ruby-string || '' }}
- 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 gc # Avoid partial cache restoration snowballing.
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@bc2616fec6b3effc9ad20380f19550a8b18cdbdf # 0.20.0
with:
git_name: commitizen-github-action[bot]
git_email: commitizen-github-action[bot]@users.noreply.github.com
github_token: ${{ github.token }}
commitizen_version: 3.18.4 # Keep in sync with .pre-commit-config.yaml and pyproject.toml.
check_consistency: true