-
Notifications
You must be signed in to change notification settings - Fork 24
163 lines (163 loc) · 6.45 KB
/
workflow-generate-website.yml
File metadata and controls
163 lines (163 loc) · 6.45 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
name: Generate Website
on:
workflow_call:
inputs:
commit_resources:
description: 'commit the resources after generating them. Requires the access_token to be passed'
required: false
default: false
type: boolean
linkcheck_fail_on_error:
description: 'a boolean flag that determines if bad links found by the link checker fail fast and stop a complete build'
required: false
default: true
type: boolean
secrets:
# Used to pass repo secrets to this called workflow, since secrets are not inherited
COMMIT_TOKEN:
required: false
workflow_dispatch:
branches:
- main
- develop
- "release-*"
inputs:
commit_resources:
description: 'commit the resources after generating them. Requires a PAT defined as secrets.COMMIT_TOKEN'
required: true
default: false
type: boolean
linkcheck_fail_on_error:
description: 'a boolean flag that determines if bad links found by the link checker fail fast and stop a complete build'
required: false
default: true
type: boolean
linkcheck_create_issue:
description: 'create new GitHub issue if broken links found'
required: false
default: false
type: boolean
jobs:
build-and-push-website:
name: Build and Push Website
runs-on: ubuntu-20.04
env:
BUILD_PATH: ./build
steps:
# use this for builds triggered from the UI and from workflows on protected branches
- id: checkout_latest_workflow
name: Checkout Latest
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.commit_resources == 'true') || (github.event_name == 'push' && inputs.commit_resources == true)
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
persist-credentials: false
submodules: recursive
# use this for overything else (i.e., pull requests) where publication is not needed
- name: Checkout Latest
if: steps.checkout_latest_workflow.conclusion == 'skipped'
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
submodules: recursive
- name: Setup Swap Space
# Since Hugo is requiring more memory
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
with:
swap-size-gb: 10
# Install Hugo
- name: Read .env
id: hugo-version
run: |
. .github/workflows/config/.env
echo "HUGO_VERSION=${HUGO_VERSION}" >> "${GITHUB_OUTPUT}"
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '${{ steps.hugo-version.outputs.HUGO_VERSION }}'
extended: true
- name: Set up NodeJS
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: '.github/workflows/config/.nvmrc'
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Setup Dependencies
run: |
# NodeJS
# If you are a developer and need to modify the workflow, be sure to review
# the package.json and package-lock.json to ensure the following deps are
# at least installed (they will be updated by dependabot):
# - ajv-cli
# - ajv-formats
# - markdown-link-check
# - yaml-convert
npm install --loglevel verbose
echo "$PWD/node_modules/.bin/" >> $GITHUB_PATH
# Dart-Sass
sudo snap install dart-sass
# cache hugo modules
- uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319
with:
path: /tmp/hugo_cache
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Run Hugo
run: |
hugo mod vendor
hugo -e production --logLevel debug --minify
working-directory: ${{ github.workspace }}/website
- name: Zip Artifacts for Upload
run: |
zip ${{ runner.temp }}/metaschema-website.zip -r public/
working-directory: ${{ github.workspace }}/website
- name: Upload generated site
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
name: website
path: |
${{ runner.temp }}/metaschema-website.zip
retention-days: 5
- id: linkchecker
name: Link Checker
uses: lycheeverse/lychee-action@c053181aa0c3d17606addfe97a9075a32723548a
with:
args: --exclude-file .github/workflows/config/.lycheeignore --verbose --no-progress --accept 200,206,429 './website/public/**/*.html' --remap "https://pages.nist.gov/metaschema/ file://${GITHUB_WORKSPACE}/website/public/" --exclude-mail
format: markdown
output: html-link-report.md
debug: true
fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Upload link check report
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
name: html-link-report
path: html-link-report.md
retention-days: 5
- name: Create issue if bad links detected
if: ${{ !cancelled() && env.lychee_exit_code != 0 && inputs.linkcheck_create_issue }}
uses: peter-evans/create-issue-from-file@24452a72d85239eacf1468b0f1982a9f3fec4c94
with:
title: Scheduled Check of Website Content Found Bad Hyperlinks
content-filepath: ./lychee/out.md
labels: |
bug
documentation
- name: Fail on link check error
if: ${{ !cancelled() && env.lychee_exit_code != 0 && (github.event.inputs.linkcheck_fail_on_error == 'true' || inputs.linkcheck_fail_on_error == true) }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
core.setFailed('Link checker detected broken or invalid links, read attached report.')
- name: Deploy Website
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847
if: github.ref_name == 'main' && ((github.event_name == 'push' && inputs.commit_resources == true) || (github.event_name == 'workflow_dispatch' && github.event.inputs.commit_resources == 'true'))
with:
personal_token: ${{ secrets.COMMIT_TOKEN }}
enable_jekyll: false
publish_dir: ./website/public
publish_branch: nist-pages
user_name: GitHub Actions Bot
user_email: metaschema@nist.gov
commit_message: Deploying website [ci deploy skip]