-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
177 lines (159 loc) · 4.92 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
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
name: Build static site
description: GitHub Actions for building and testing static site projects
inputs:
project-path:
description: The path to the project to check
required: false
default: ''
is-sub-path:
description: Whether the project is a sub-path
required: false
default: 'false'
package-manager:
description: The package manager which is used to manager dependencies
required: false
default: 'pnpm'
package-manager-version:
description: The version of package manager to use
required: false
default: 'latest'
lock-file:
description: The lock file which is used to manage dependencies
required: false
default: 'pnpm-lock.yaml'
node-version:
description: The version of Node.js to use
required: false
default: 'latest'
lint-script:
description: The script name to lint code
required: false
default: lint
build-script:
description: The script name to build the project
required: false
default: build
test-script:
description: The script name to run test cases
required: false
default: test
skip-lint:
description: Skip the lint step
required: false
default: 'false'
skip-build:
description: Skip the build step
required: false
default: 'false'
skip-test:
description: Skip the test step
required: false
default: 'false'
artifact-name:
description: The name of the artifact to upload
required: false
default: 'dist'
output-dir:
description: The path to the output directory
required: false
default: 'dist/'
runs:
using: "composite"
steps:
- name: Set Node package manager
env:
NODE_PACKAGE_MANAGER: "${{ inputs.package-manager }}"
run: echo "NODE_PACKAGE_MANAGER=${NODE_PACKAGE_MANAGER}" >> "$GITHUB_ENV"
shell: bash
- name: Set working directory
if: inputs.project-path == ''
run: echo "WORKING_DIR=./" >> "$GITHUB_ENV"
shell: bash
- name: Set working directory
if: inputs.project-path != ''
env:
WORKING_DIR: "${{ inputs.project-path }}"
run: |
{
echo "WORKING_DIR=${WORKING_DIR}"
echo "PNPM_WORKING_DIR=${WORKING_DIR}"
} >> "$GITHUB_ENV"
shell: bash
- name: Checkout
if: github.repository != 'ghacts/static-site' || env.SKIP_CHECKOUT != 'true'
uses: actions/checkout@v4
- name: Setup pnpm
if: env.NODE_PACKAGE_MANAGER == 'pnpm' && env.PNPM_WORKING_DIR == ''
uses: pnpm/action-setup@v3
with:
version: "${{ inputs.package-manager-version }}"
run_install: |
- args: [--frozen-lockfile]
- name: Setup pnpm
if: env.NODE_PACKAGE_MANAGER == 'pnpm' && env.PNPM_WORKING_DIR != ''
uses: pnpm/action-setup@v3
with:
version: "${{ inputs.package-manager-version }}"
run_install: |
- args: [--frozen-lockfile]
cwd: "${{ env.WORKING_DIR }}"
- name: Set up Node
if: inputs.is-sub-path == 'false'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: ${{ env.NODE_PACKAGE_MANAGER }}
- name: Set up Node sub path
if: inputs.is-sub-path == 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: ${{ env.NODE_PACKAGE_MANAGER }}
cache-dependency-path: "${{ env.WORKING_DIR }}/${{ inputs.lock-file }}"
- name: Install dependencies
if: env.NODE_PACKAGE_MANAGER != 'pnpm'
working-directory: ${{ env.WORKING_DIR }}
run: ${NODE_PACKAGE_MANAGER} install
shell: bash
- name: Lint code
if: inputs.skip-lint == 'false'
env:
LINT_SCRIPT: "${{ inputs.lint-script }}"
working-directory: ${{ env.WORKING_DIR }}
run: ${NODE_PACKAGE_MANAGER} run ${LINT_SCRIPT}
shell: bash
- name: Skip running lint
if: inputs.skip-lint == 'true'
run: echo "Skipped running lint"
shell: bash
- name: Build
if: inputs.skip-build == 'false'
env:
BUILD_SCRIPT: "${{ inputs.build-script }}"
working-directory: ${{ env.WORKING_DIR }}
run: ${NODE_PACKAGE_MANAGER} run ${BUILD_SCRIPT}
shell: bash
- name: Upload artifact
if: inputs.skip-build == 'false' && success()
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: "${{ env.WORKING_DIR }}/${{ inputs.output-dir }}"
- name: Skip building
if: inputs.skip-build == 'true'
run: echo "Skipped building"
shell: bash
- name: Test
if: inputs.skip-test == 'false'
env:
TEST_SCRIPT: "${{ inputs.test-script }}"
working-directory: ${{ env.WORKING_DIR }}
run: ${NODE_PACKAGE_MANAGER} run ${TEST_SCRIPT}
shell: bash
- name: Skip testing
if: inputs.skip-test == 'true'
run: echo "Skipped testing"
shell: bash
branding:
icon: 'box'
color: 'green'