@@ -14,6 +14,16 @@ inputs:
14
14
description : >-
15
15
Set this to "true" to only run pre-commit against changed files, and not
16
16
the entire repository
17
+ s3-bucket-name :
18
+ required : false
19
+ description : S3 bucket name to cache node_modules to speed up dependency installation.
20
+ s3-bucket-region :
21
+ required : false
22
+ description : S3 bucket region to cache node_modules to speed up dependency installation.
23
+ outputs :
24
+ cache-hit :
25
+ description : Whether the cache was hit when installing dependencies
26
+ value : ${{ steps.read_cache.outputs.cache-hit }}
17
27
18
28
runs :
19
29
using : composite
@@ -72,17 +82,43 @@ runs:
72
82
PRE_COMMIT_ARGS="--files ${{ steps.changed-files.outputs.all_changed_files }}"
73
83
echo "PRE_COMMIT_ARGS=$PRE_COMMIT_ARGS" >> "$GITHUB_ENV"
74
84
fi
85
+
86
+ - name : Compute pre-commit cache key
87
+ if : inputs.s3-bucket-name != ''
88
+ id : pre_commit_cache_key
89
+ run : |
90
+ echo "key=${{ hashFiles('**/.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
91
+ shell : bash
92
+ - name : Load cached pre-commit hooks if available
93
+ if : inputs.s3-bucket-name != ''
94
+ uses : everpcpc/actions-cache@v2
95
+ id : read_cache
96
+ with :
97
+ bucket : ${{ inputs.s3-bucket-name }}
98
+ use-fallback : false
99
+ path : ${{ runner.temp }}/${{ env.cache-name }}-${{ steps.pre_commit_cache_key.outputs.key }}
100
+ key : ${{ env.cache-name }}-${{ steps.pre_commit_cache_key.outputs.key }}
101
+ restore-keys : ${{ env.cache-name }}-
102
+ env :
103
+ AWS_REGION : ${{ inputs.s3-bucket-region }}
104
+ cache-name : ${{ github.event.repository.name }}/cache-pre-commit
105
+
75
106
- name : Pre-commit (action)
76
107
# Same as above, this will install and run pre-commit for us
77
108
if : env.PRE_COMMIT_BIN == null && steps.pre-commit-config.outputs.exists != 'false'
78
109
uses : pre-commit/action@v3.0.1
79
110
with :
80
111
extra_args : ${{ env.PRE_COMMIT_ARGS }}
112
+ env :
113
+ PRE_COMMIT_HOME : ${{ runner.temp }}/${{ github.event.repository.name }}/cache-pre-commit-${{ steps.pre_commit_cache_key.outputs.key }}
81
114
- name : Pre-commit (from PATH)
82
115
# Run pre-commit directly if we found it on the PATH
83
116
if : env.PRE_COMMIT_BIN != null && steps.pre-commit-config.outputs.exists != 'false'
84
117
shell : bash
85
118
run : pre-commit run --show-diff-on-failure --color=always ${{ env.PRE_COMMIT_ARGS }}
119
+ env :
120
+ PRE_COMMIT_HOME : ${{ runner.temp }}/${{ github.event.repository.name }}/cache-pre-commit-${{ steps.pre_commit_cache_key.outputs.key }}
121
+
86
122
- name : Restore commitlint config
87
123
if : always() && hashFiles(inputs.config-file) != '' && inputs.turo-conventional-commit == 'true'
88
124
shell : bash
0 commit comments