-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathaction.yml
More file actions
179 lines (168 loc) · 7.21 KB
/
Copy pathaction.yml
File metadata and controls
179 lines (168 loc) · 7.21 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
name: "Astro Deploy"
description: "A composite action that prepares your Astro site to be deployed to GitHub Pages"
branding:
icon: "arrow-up-right"
color: "purple"
inputs:
node-version:
description: "The node version to use"
required: false
default: "24"
package-manager:
description: "You may specify your preferred package manager (one of `npm | yarn | pnpm | bun | deno` and an optional `@<version>` tag). Otherwise, the package manager will be automatically detected."
required: false
default: ""
path:
description: "Path of the directory containing your site"
required: false
default: "."
build-cmd:
description: "The command used to build your site"
required: false
default:
cache:
description: "Enable Astro cache to speed up subsequent builds (caches optimized images and other assets)"
required: false
default: "true"
cache-dir:
description: "Path to the Astro cache directory (relative to 'path' input). Defaults to 'node_modules/.astro'"
required: false
default: "node_modules/.astro"
out-dir:
description: "Path to the output build directory (relative to 'path' input). Defaults to 'dist'"
required: false
default: "dist"
runs:
using: composite
steps:
- name: Check lockfiles
shell: "bash"
working-directory: ${{ inputs.path }}
env:
INPUT_PM: ${{ inputs.package-manager }}
run: |
len=`echo $INPUT_PM | wc -c`
if [ $len -gt 1 ]; then
PACKAGE_MANAGER=$(echo "$INPUT_PM" | grep -o '^[^@]*')
VERSION=$(echo "$INPUT_PM" | { grep -o '@.*' || true; } | sed 's/^@//')
# Set default VERSION if not provided
if [ -z "$VERSION" ]; then
if [ "$PACKAGE_MANAGER" = "deno" ]; then
# The denoland/setup-deno action equivalent of "latest"
VERSION="vx.x.x"
else
VERSION="latest"
fi
fi
echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV
elif [ $(find "." -maxdepth 1 -name "pnpm-lock.yaml") ]; then
echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_ENV
echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV
# If packageManager field is not present, use latest version.
if ! jq -e '.packageManager' package.json > /dev/null 2>&1; then
VERSION="latest"
# Annotate this action run to let users know we’re using the default.
echo "::warning title=Could not detect PNPM version::No \`packageManager\` field found in \`package.json\`. Using latest PNPM version instead. We recommend specifying \`pnpm@VERSION\` explicitly using the \`packageManager\` field in your \`package.json\`."
fi
elif [ $(find "." -maxdepth 1 -name "yarn.lock") ]; then
echo "PACKAGE_MANAGER=yarn" >> $GITHUB_ENV
echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV
elif [ $(find "." -maxdepth 1 -name "package-lock.json") ]; then
VERSION="latest"
echo "PACKAGE_MANAGER=npm" >> $GITHUB_ENV
echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV
elif [ $(find "." -maxdepth 1 -name "bun.lock") ]; then
VERSION="latest"
echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV
echo "LOCKFILE=bun.lock" >> $GITHUB_ENV
elif [ $(find "." -maxdepth 1 -name "bun.lockb") ]; then
VERSION="latest"
echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV
echo "LOCKFILE=bun.lockb" >> $GITHUB_ENV
elif [ -f "deno.json" ] || [ -f "deno.jsonc" ] || [ -f "deno.lock" ]; then
VERSION="vx.x.x"
echo "PACKAGE_MANAGER=deno" >> $GITHUB_ENV
echo "LOCKFILE=deno.lock" >> $GITHUB_ENV
else
echo "No lockfile found.
Please specify your preferred \"package-manager\" in the action configuration."
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Setup PNPM
if: ${{ env.PACKAGE_MANAGER == 'pnpm' }}
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: ${{ env.VERSION }}
package_json_file: "${{ inputs.path }}/package.json"
- name: Setup Bun
if: ${{ env.PACKAGE_MANAGER == 'bun' }}
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: ${{ env.VERSION }}
- name: Setup Deno
if: ${{ env.PACKAGE_MANAGER == 'deno' }}
uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
with:
deno-version: ${{ env.VERSION }}
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ env.PACKAGE_MANAGER != 'bun' && env.PACKAGE_MANAGER != 'deno' }}
with:
node-version: ${{ inputs.node-version }}
cache: ${{ env.PACKAGE_MANAGER }}
cache-dependency-path: "${{ inputs.path }}/${{ env.LOCKFILE }}"
- name: Setup Node (Bun)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ env.PACKAGE_MANAGER == 'bun' }}
with:
node-version: ${{ inputs.node-version }}
- name: Install
shell: bash
working-directory: ${{ inputs.path }}
run: |
if [ "$PACKAGE_MANAGER" = "deno" ]; then
# For Deno projects with deno.json, cache dependencies
if [ -f "deno.json" ] || [ -f "deno.jsonc" ]; then
echo "Caching Deno dependencies..."
deno cache --lock=deno.lock --lock-write **/*.ts **/*.tsx 2>/dev/null || true
fi
# For hybrid projects with package.json, install npm dependencies
if [ -f "package.json" ]; then
echo "Installing npm dependencies with Deno..."
deno install --allow-scripts
fi
else
# Standard package manager install
$PACKAGE_MANAGER install
fi
- name: Restore Astro cache
if: ${{ inputs.cache == 'true' }}
id: astro-cache-restore
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ inputs.path }}/${{ inputs.cache-dir }}
key: astro-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
astro-cache-${{ runner.os }}-
- name: Build (npm/yarn/pnpm/bun)
if: ${{ env.PACKAGE_MANAGER != 'deno' }}
shell: bash
working-directory: ${{ inputs.path }}
run: ${{ inputs.build-cmd || '$PACKAGE_MANAGER run build' }}
- name: Build (Deno)
if: ${{ env.PACKAGE_MANAGER == 'deno' }}
shell: bash
working-directory: ${{ inputs.path }}
run: ${{ inputs.build-cmd || 'deno task build' }}
- name: Save Astro cache
if: ${{ inputs.cache == 'true' && steps.astro-cache-restore.outputs.cache-hit != 'true' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ inputs.path }}/${{ inputs.cache-dir }}
key: ${{ steps.astro-cache-restore.outputs.cache-primary-key }}
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
with:
path: "${{ inputs.path }}/${{ inputs.out-dir }}/"
include-hidden-files: true