-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
148 lines (128 loc) · 5.04 KB
/
action.yml
File metadata and controls
148 lines (128 loc) · 5.04 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
name: "Deploy - GitHub Pages"
description: "Action to deploy a static site to GitHub Pages."
author: hoverkraft
branding:
icon: upload-cloud
color: blue
inputs:
build-path:
description: |
The path to the assets to deploy.
Can be absolute or relative $GITHUB_WORKSPACE.
required: false
build-artifact-id:
description: |
The ID of the "build" artifact to download.
If not set, the action will use the local workspace files.
required: false
default: ""
budget-path:
description: "The path to the performance budget file. See action [Check - URL - Lighthouse](../../check/url-lighthouse/README.md)."
required: false
default: "./budget.json"
static-site-generator:
description: |
The static site generator used to build the site. See https://github.com/actions/configure-pages.
required: false
checks:
description: |
Whether to run URL checks after deployment.
required: false
default: "true"
github-token:
description: |
GitHub Token for deploying to GitHub Pages.
Permissions:
- pages: write
- id-token: write
See https://github.com/actions/deploy-pages.
required: false
default: ${{ github.token }}
outputs:
url:
description: "The URL of the deployed site."
value: ${{ steps.deployment.outputs.page_url }}
runs:
using: "composite"
steps:
- id: download-artifact
if: ${{ inputs.build-artifact-id != '' }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ inputs.build-artifact-id }}
path: "/"
- id: prepare-variables
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const { isAbsolute, join } = require("path");
const { lstatSync } = require("fs");
const { randomUUID } = require('crypto');
let downloadPath = ${{ toJSON(steps.download-artifact.outputs.download-path) }};
if (!downloadPath || downloadPath === "/") {
downloadPath = ${{ toJSON(github.workspace) }};
}
let buildPath = ${{ toJSON(inputs.build-path) }};
if (!buildPath || !isAbsolute(buildPath)) {
buildPath = join(downloadPath.trim(), buildPath.trim());
}
// Check if the build path exists and is a directory
if (!lstatSync(buildPath).isDirectory()) {
return core.setFailed(`Build path does not exist or is not a directory: ${buildPath}`);
}
core.setOutput("build-path", buildPath);
// Define a unique artifact name
const uniquid = randomUUID();
const timestamp = Date.now();
const artifactName = `${{ github.run_id }}-${{ github.run_number }}-github-pages-${timestamp}-${uniquid}`;
core.setOutput("artifact-name", artifactName);
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: mkdir -p ./self-github-pages-actions/ && cp -r $GITHUB_ACTION_PATH/../../* ./self-github-pages-actions/
- uses: ./self-github-pages-actions/deploy/jampack
with:
path: ${{ steps.prepare-variables.outputs.build-path }}
- name: ⚙️ Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
with:
static_site_generator: ${{ inputs.static-site-generator }}
token: ${{ inputs.github-token }}
enablement: true
- name: 📦 Upload website build artifact
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
path: ${{ steps.prepare-variables.outputs.build-path }}
name: ${{ steps.prepare-variables.outputs.artifact-name }}
- name: 🚀 Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0
with:
artifact_name: ${{ steps.prepare-variables.outputs.artifact-name }}
# jscpd:ignore-start
# Url checks
- uses: ./self-github-pages-actions/check/url-ping
if: ${{ inputs.checks == 'true' }}
with:
url: ${{ steps.deployment.outputs.page_url }}
- uses: ./self-github-pages-actions/check/url-lighthouse
if: ${{ inputs.checks == 'true' }}
with:
url: ${{ steps.deployment.outputs.page_url }}
budget-path: ${{ inputs.budget-path }}
# jscpd:ignore-end
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: |
rm -fr ./self-github-pages-actions
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PAGE_URL: ${{ steps.deployment.outputs.page_url }}
with:
script: |
const url = process.env.PAGE_URL;
await core.summary
.addHeading("Github Page has been deployed 🚀", 3)
.addRaw(`Here it is: <a href="${url}">${url}</a>`)
.addBreak().addBreak()
.addCodeBlock(url)
.write();