Skip to content

Commit a664501

Browse files
Workflow improvements
1 parent 30a5cef commit a664501

1 file changed

Lines changed: 70 additions & 43 deletions

File tree

.github/workflows/publish-docs.yml

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
name: Build and Publish Documentation
1+
name: Build Documentation
22

33
on:
44
push:
55
branches:
6-
- main
76
- dev
8-
9-
# TODO: Remove this line
7+
- main
108
- new/doc-generation
11-
9+
pull_request:
1210
release:
1311
types:
1412
- published
1513

16-
workflow_dispatch:
17-
18-
permissions:
19-
contents: read
20-
pages: write
21-
id-token: write
22-
23-
# Make sure we avoid a race condition =)
24-
concurrency:
25-
group: "pages"
26-
cancel-in-progress: false
27-
2814
jobs:
2915
build:
3016
name: Build the documentation
@@ -50,12 +36,36 @@ jobs:
5036
pip install certifi -U && \
5137
pip install .[obj,dev]
5238
39+
- name: Resolve the target CLI version
40+
uses: actions/github-script@v7
41+
id: resolve-cli-version
42+
with:
43+
script: |
44+
const latest_release = await github.rest.repos.getLatestRelease({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo
47+
});
48+
49+
if (context.payload.release && latest_release.data.id == context.payload.release.id) {
50+
let result = context.payload.release.tag_name;
51+
52+
if (result.startsWith('v')) {
53+
result = result.slice(1);
54+
}
55+
56+
return result;
57+
}
58+
59+
return '0.0.0.dev+' + context.sha.substring(0, 7);
60+
result-encoding: string
61+
5362
- name: Build the documentation
54-
run: make generate-docs
63+
run: make create-version && make generate-docs
5564
env:
5665
# We need to define a token to prevent the CLI from
5766
# attempting to do a first-time configuration.
5867
LINODE_CLI_TOKEN: foobar
68+
LINODE_CLI_VERSION: ${{ steps.resolve-cli-version.outputs.result }}
5969

6070
- name: Upload the artifact
6171
uses: actions/upload-artifact@v4
@@ -68,43 +78,60 @@ jobs:
6878
runs-on: ubuntu-latest
6979
needs:
7080
- build
81+
# Make sure we avoid a race condition =)
82+
concurrency:
83+
group: "pages"
84+
cancel-in-progress: false
85+
permissions:
86+
contents: write
87+
pages: write
88+
id-token: write
89+
if: (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'new/doc-generation' )) || (github.ref_type == 'tag')
7190
steps:
72-
- name: Checkout the GitHub Pages branch
91+
- name: Checkout the documentation branch
92+
continue-on-error: true
93+
id: checkout-docs
7394
uses: actions/checkout@v4
7495
with:
7596
fetch-depth: 0
7697
submodules: "recursive"
77-
ref: "static/pages"
98+
ref: "static/docs"
99+
100+
- name: Create the documentation branch if it does not already exist
101+
if: "${{ steps.checkout-docs.outcome != 'success' }}"
102+
run: git switch --orphan static/docs
78103

79104
- name: Ensure any previous documentation for this branch are removed
80-
run: rm -rf "./${{ github.ref }}"
105+
run: rm -rf "./${{ github.ref_name }}"
81106

82107
- name: Download the artifact from the previous job
83108
uses: actions/download-artifact@v4
84109
with:
85110
name: generated-docs-html
86-
path: "${{ github.ref }}"
111+
path: "${{ github.ref_name }}"
112+
113+
- name: Override the latest version if necessary
114+
if: ${{ github.event_name == 'release' }}
115+
run: |
116+
rm -rf latest && cp -r ${{ github.ref_name }} latest
87117
88118
- name: Commit and push this change
89119
run: |
90-
git config user.name "Documentation Publisher"
91-
git config user.email "dl-linode-dev-dx@akamai.com"
92-
git add .
93-
git commit -m "Rebuild ${{ github.ref }} from ${{ github.sha }}"
94-
git push origin static/pages
95-
#
96-
# # TODO: Implement some sort of page merging logic here so we can host
97-
# # separate pages for `dev`, `main` and commit hashes.
98-
#
99-
# - name: Configure GitHub Pages
100-
# uses: actions/configure-pages@v5
101-
# with:
102-
# enablement: true
103-
#
104-
# - name: Push the rendered documentation site to GitHub Pages
105-
# uses: actions/upload-pages-artifact@v3
106-
# with:
107-
# path: .docs-html
108-
#
109-
# - name: Deploy to GitHub Pages
110-
# uses: actions/deploy-pages@v4
120+
git config user.name "Documentation Publisher";
121+
git config user.email "dl-linode-dev-dx@akamai.com";
122+
git add .;
123+
git commit --allow-empty -m "Rebuild ${{ github.ref_name }} from ${{ github.sha }}";
124+
git push origin static/docs;
125+
126+
- name: Configure GitHub Pages
127+
uses: actions/configure-pages@v5
128+
with:
129+
enablement: true
130+
131+
- name: Push the rendered documentation site to GitHub Pages
132+
uses: actions/upload-pages-artifact@v3
133+
with:
134+
path: .
135+
136+
- name: Deploy to GitHub Pages
137+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)