forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (126 loc) · 4.96 KB
/
release-doc.yaml
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
name: "Release documentation set"
on:
push:
tags:
- v*
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
defaults:
run:
shell: bash
env:
#SITE="https://goswagger.io"
SITE: "https://fredbi.github.io"
GH_PAGES_OWNER: fredbi
GH_PAGES_REPO: go-swagger.github.io
GH_PAGES_STAGING: hack/doc-site/github-pages
jobs:
build-doc:
runs-on: ubuntu-latest
steps:
-
name: Generate token authorized to site repository
# This step requires an organization app to be configured
# and installed with write permissions on GH_PAGES_REPO
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_DOC_BOT_APP_ID }}
private-key: ${{ secrets.GH_DOC_BOT_KEY }}
owner: ${{ env.GH_PAGES_OWNER }}
repositories: ${{ env.GH_PAGES_REPO }}
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '1'
#fetch-tags: 'true'
submodules: recursive
sparse-checkout: |
hack/
docs/
- name: Get all tags
run: git fetch --prune --unshallow --tags
-
name: Initialize themes
run: |
(cd hack/doc-site/hugo/ && git clone https://github.com/alex-shpak/hugo-book themes/hugo-book)
-
name: Checkout github pages main site
uses: actions/checkout@v4
with:
repository: ${{ env.GH_PAGES_OWNER }}/${{ env.GH_PAGES_REPO }}
path: ${{ env.GH_PAGES_STAGING }}
# We don't need to checkout all this content. Remember later to git add with --sparse.
sparse-checkout: |
index.html
fetch-depth: '1'
-
name: Prepare config
run: |
# For released documentation, we use a slightly different configuration than for master,
# as the baseURL will be {site}/{release} instead of {site}/go-swagger.
#
# Also, we disable the "edit" button on this frozen version and add a banner to mention the released doc set.
cd hack/doc-site/hugo
LATEST_RELEASE=$(git describe --tags --abbrev=0)
VERSION_MESSAGE="Documentation set for release ${LATEST_RELEASE}."
ROOT=$(git rev-parse --show-toplevel)
REQUIRED_GO_VERSION=$(grep "^go\s" "${ROOT}"/go.mod|cut -d" " -f2)
printf \
"params:\n goswagger:\n goVersion: '%s'\n latestRelease: '%s'\n versionMessage: '%s'\n" \
"${REQUIRED_GO_VERSION}" "${LATEST_RELEASE}" "${VERSION_MESSAGE}" > goswagger.yaml
# Tweak HUGO configuration to produce released documentation site at {url}/vx.y.z.
sed 's/^baseURL:[[:space:]]*\(.\+\)$/baseURL: '$(echo "${SITE}/${LATEST_RELEASE}"|sed 's/\//\\\//g')'/' hugo.yaml | \
sed 's/^[[:space:]]\+BookEditPath:\(.\+\)$/ #BookEditPath:\1/' > release.yaml
-
name: Build site with Hugo for release documentation set
uses: crazy-max/ghaction-hugo@v3
with:
version: v0.123.8 # <- pin the HUGO version, at they often break things
extended: true
args: >
--config release.yaml,goswagger.yaml
--buildDrafts
--cleanDestinationDir
--minify
--printPathWarnings
--ignoreCache
--noBuildLock
--logLevel info
--source ${{ github.workspace }}/hack/doc-site/hugo"
-
name: Copy generated site
run: |
ROOT=$(git rev-parse --show-toplevel)
LATEST_RELEASE=$(git describe --tags --abbrev=0)
cd ${{env.GH_PAGES_STAGING}}
mkdir "${LATEST_RELEASE}"
(cd "${ROOT}"/hack/doc-site/hugo/public;tar cf - .)|(cd "${LATEST_RELEASE}";tar xf -)
-
name: Create PR for goswagger.github.io
# TODO: directly push to master & tag
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
cd $(git rev-parse --show-toplevel)
LATEST_RELEASE=$(git describe --tags --abbrev=0)
BRANCH="doc/${LATEST_RELEASE}"
cd ${{env.GH_PAGES_STAGING}}
gh auth status
GH_DEBUG=1 gh auth setup-git
git checkout -b "${BRANCH}"
git config --global user.email "[email protected]"
git config --global user.name "fredbi-doc-site-bot[bot]"
git add "${LATEST_RELEASE}" --sparse
git commit --quiet -m "doc: release documentation set for release ${LATEST_RELEASE}"
echo "pushing content to ${GH_PAGES_OWNER}/${GH_PAGES_REPO}, branch: ${BRANCH}"
git push --set-upstream origin "${BRANCH}"
echo "creating PR with content to ${GH_PAGES_OWNER}/${GH_PAGES_REPO}"
gh pr create -R ${GH_PAGES_OWNER}/${GH_PAGES_REPO} --fill --base master --label release --label "${LATEST_RELEASE}"