forked from usnistgov/OSCAL
-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (164 loc) · 6.52 KB
/
workflow-generate-website-reference.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
name: Generate Reference Docs
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
secrets:
access_token:
description: 'the access token to use for commits'
required: false
workflow_dispatch:
branches:
- main
- develop
- "feature-*"
- "release-*"
tags:
- "v*"
inputs:
commit_resources:
description: 'commit the resources after generating them. Requires a PAT defined as secrets.COMMIT_TOKEN'
required: true
default: false
type: boolean
jobs:
build-and-push-website:
name: Build and Push Website Reference
runs-on: ubuntu-20.04
env:
JAVA_CLASSPATH: ${{ github.workspace}}/lib
MAIN_PATH: ${{ github.workspace }}/main
BRANCH_PATH: ${{ github.workspace }}/branch
MAIN_BRANCH_REF: main
steps:
# This workflow requires two branches to be checked out
# 1) The main branch where live web assets are managed. Generated reference pages need to be
# pushed here.
# 2) The target branch where the metaschemas exist that are the basis of reference information.
# Checkout the current branch for reading
- name: Checkout Latest
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
path: ${{ env.BRANCH_PATH }}
submodules: recursive
fetch-depth: 0 # this ensures that the tag and commit history are available
# use this for builds triggered from the UI on protected branches
- name: Checkout Main (using COMMIT_TOKEN)
if: github.event_name == 'workflow_dispatch' && github.event.inputs.commit_resources == 'true'
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
path: ${{ env.MAIN_PATH }}
ref: ${{ env.MAIN_BRANCH_REF }}
token: ${{ secrets.COMMIT_TOKEN }}
submodules: recursive
id: checkout_main_workflow
# use this for builds triggered from other workflows on protected branches
- name: Checkout Main (using access_token)
if: github.event_name == 'push' && inputs.commit_resources == true
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
path: ${{ env.MAIN_PATH }}
ref: ${{ env.MAIN_BRANCH_REF }}
token: ${{ secrets.access_token }}
submodules: recursive
id: checkout_main_push
# use this for overything else (i.e., pull requests) where publication is not needed
- name: Checkout Main
if: steps.checkout_main_workflow.conclusion == 'skipped' && steps.checkout_main_push.conclusion == 'skipped'
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
path: ${{ env.MAIN_PATH }}
ref: ${{ env.MAIN_BRANCH_REF }}
submodules: recursive
- name: Set env
run: |
echo "SAXON_HOME=${JAVA_CLASSPATH}" >> $GITHUB_ENV
echo "CALABASH_HOME=${JAVA_CLASSPATH}" >> $GITHUB_ENV
# Setup runtime environment
# -------------------------
# Java JDK 11
- name: Set up JDK
uses: actions/setup-java@f0bb91606209742fe3ea40199be2f3ef195ecabf
with:
java-version: 11
distribution: 'temurin'
cache: 'maven'
- name: Install JDK Deps Saxon and XML Calabash
run: |
cd "${{ env.BRANCH_PATH }}/build"
mkdir -p "${JAVA_CLASSPATH}"
mvn dependency:copy-dependencies -DoutputDirectory="${JAVA_CLASSPATH}"
# Install Hugo
- name: Store Hugo Executable in Cache
uses: actions/cache@0865c47f36e68161719c5b124609996bb5c40129
with:
path: /home/runner/go/bin/hugo
key: ${{ runner.os }}-hugo-${{ hashFiles(format('{0}/build/go.sum', env.BRANCH_PATH)) }}
id: cache-hugo
- name: Add Cached Hugo Executable to PATH
if: steps.cache-hugo.outputs.cache-hit == 'true'
run: |
echo "/home/runner/go/bin" >> $GITHUB_PATH
- name: Setup Golang
if: steps.cache-hugo.outputs.cache-hit != 'true'
uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923
with:
go-version-file: '${{ env.BRANCH_PATH }}/build/go.mod'
cache: true
cache-dependency-path: '${{ env.BRANCH_PATH }}/build/go.sum'
- name: Install Hugo
if: steps.cache-hugo.outputs.cache-hit != 'true'
run: |
cd "${{ env.BRANCH_PATH }}/build"
go install -tags "extended" github.com/gohugoio/hugo
# Build Artifacts
# ---------------
- name: Generate Model Reference Documentation
# perform this step in the target branch, but generate the results to the main branch
run: |
echo "PWD: ${PWD}"
echo "Github Workspace: ${{ github.workspace }}"
echo "Current Branch: $(git branch --show-current)"
echo "GITHUB_REF: ${GITHUB_REF}"
BRANCH="${GITHUB_REF}"
if [[ "$BRANCH" =~ ^refs/pull/.* ]]; then
BRANCH="${GITHUB_HEAD_REF}"
elif [[ "$BRANCH" =~ ^refs/heads/.* ]]; then
BRANCH="${GITHUB_REF#refs/heads/}"
elif [[ "$BRANCH" =~ ^refs/tags/.* ]]; then
BRANCH="${GITHUB_REF#refs/tags/}"
fi
echo "Using Branch: ${BRANCH}"
bash "${{ env.MAIN_PATH }}/build/ci-cd/generate-model-documentation.sh" -b "${BRANCH}" -a "${BRANCH_PATH}" -w "${MAIN_PATH}" -o "${MAIN_PATH}"
working-directory: ${{ env.BRANCH_PATH }}
- name: Run Hugo
run: |
hugo --config "config.yaml,development-config.yaml" -v --debug --minify
working-directory: ${{ env.MAIN_PATH }}/docs
- name: Zip Artifacts for Upload
run: |
zip ${{ runner.temp }}/metaschema-website.zip -r public/
working-directory: ${{ env.MAIN_PATH }}/docs
- uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
with:
name: website
path: |
${{ runner.temp }}/metaschema-website.zip
retention-days: 5
- name: Publish Generated Pages
# only do this on master
if: github.event.inputs.commit_resources == 'true' || inputs.commit_resources == true
uses: stefanzweifel/git-auto-commit-action@be7095c202abcf573b09f20541e0ee2f6a3a9d9b
with:
repository: ${{ env.MAIN_PATH }}
file_pattern: docs
# push_options: --force-with-lease
skip_dirty_check: false
commit_user_name: OSCAL GitHub Actions Bot
commit_user_email: [email protected]
commit_author: OSCAL GitHub Actions Bot <[email protected]>
commit_message: Pushing generated website pages [ci skip]