-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
81 lines (75 loc) · 2.55 KB
/
action.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
name: GitHub README stats generator
description: Dynamically generated stats for your GitHub README
inputs:
card:
description: 'Type of card: one of stats (default), repo, langs, wakatime, gist.'
required: false
default: stats
options:
description: Options for the card
required: false
default: username=${{ github.repository_owner }}
path:
description: Output path for SVG file (relative path; include filename with .svg)
required: false
default: grs/out.svg
token:
description: GitHub token; normally no need to set it
required: false
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
branding:
color: green
icon: bar-chart
runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get cache key and path
id: lock
run: |
cd $GITHUB_ACTION_PATH
node <<'JAVASCRIPT'
const fs = require('fs');
const os = require('os');
const sha256 = require('crypto').createHash('sha256');
const hash = sha256.update(fs.readFileSync('package-lock.json')).digest('hex');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `key=${os.platform()}-${os.arch()}-grs-modules-${hash}\n`);
JAVASCRIPT
modules=$(pwd)/node_modules
command -v cygpath &> /dev/null && modules=$(cygpath -w $modules)
echo "modules=$modules" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
cd $GITHUB_WORKSPACE
shell: bash
# This step is needed because ${{ github.action_path }} has relative pathing (it ends with /./).
# On macOS and Ubuntu runner, sha256sum command isn't available, so I use Node.js to calculate the hash.
- name: Restore cache
uses: actions/cache/restore@v4
id: cache-restore
with:
path: ${{ steps.lock.outputs.modules }}
key: ${{ steps.lock.outputs.key }}
- name: CI
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
cd $GITHUB_ACTION_PATH
npm ci
cd $GITHUB_WORKSPACE
shell: bash
- name: Save cache
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ steps.lock.outputs.modules }}
key: ${{ steps.lock.outputs.key }}
- name: Run
run: node $GITHUB_ACTION_PATH/index.js
env:
GRS_CARD: ${{ inputs.card }}
GRS_OPTIONS: ${{ inputs.options }}
GRS_PATH: ${{ inputs.path }}
PAT_1: ${{ inputs.token }}
shell: bash