Skip to content

Commit 1c7dd8a

Browse files
Push container images (#113)
* Separate push and pull_request build paths * Build image for PRs * Load image into Docker for next step * Use sudo to delete unnecessary files in PRs --------- Signed-off-by: Mike McKiernan <[email protected]>
1 parent 5ecbcbb commit 1c7dd8a

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: docs-build-pr
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [ opened, synchronize ]
7+
8+
env:
9+
GH_TOKEN: ${{ github.token }}
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build-docs:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
- name: Build image
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: .
27+
file: docker/Dockerfile
28+
load: true
29+
tags: pr-image:${{ github.sha }}
30+
- name: Build docs
31+
run: |
32+
docker run -v $(pwd):/work -w /work pr-image:${{ github.sha }} ./repo docs
33+
- name: Delete unnecessary files
34+
run: |
35+
sudo find _build -name .doctrees -prune -exec rm -rf {} \;
36+
sudo find _build -name .buildinfo -exec rm {} \;
37+
- name: Copy review page
38+
run: |
39+
sudo mv _build/docs/review/latest/* _build/docs
40+
sudo rm -rf _build/docs/review _build/docs/tmp _build/docs/sphinx_warnings.txt
41+
- name: Upload HTML
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: html-build-artifact
45+
path: _build/docs
46+
if-no-files-found: error
47+
retention-days: 1
48+
- name: Store PR information
49+
run: |
50+
mkdir ./pr
51+
echo ${{ github.event.number }} > ./pr/pr.txt
52+
echo ${{ github.event.pull_request.merged }} > ./pr/merged.txt
53+
echo ${{ github.event.action }} > ./pr/action.txt
54+
- name: Upload PR information
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: pr
58+
path: pr/

.github/workflows/docs-build.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
name: docs-build
22

33
on:
4-
pull_request:
5-
branches: [ master, main ]
6-
types: [ opened, synchronize ]
7-
84
push:
9-
branches: [ master, main ]
5+
branches: [ main ]
106
tags:
117
- v*
128
workflow_dispatch:
139

1410
env:
1511
REGISTRY: ghcr.io
1612
IMAGE_NAME: ${{ github.repository }}
17-
TAG: 0.2.0
13+
TAG: 0.3.0
1814
GH_TOKEN: ${{ github.token }}
1915

2016
concurrency:
@@ -33,8 +29,6 @@ jobs:
3329
steps:
3430
- name: Checkout
3531
uses: actions/checkout@v4
36-
with:
37-
fetch-depth: 2
3832
- name: Log in to Container Registry
3933
uses: docker/login-action@v3
4034
with:
@@ -77,8 +71,8 @@ jobs:
7771
steps:
7872
- name: Checkout
7973
uses: actions/checkout@v4
80-
with:
81-
fetch-depth: 1
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
8276
- name: Log in to Container Registry
8377
uses: docker/login-action@v3
8478
with:
@@ -95,16 +89,13 @@ jobs:
9589

9690
build-docs:
9791
needs: [dockerfile-changed, build-and-push-image]
98-
if: ${{ always() }}
99-
runs-on: ubuntu-latest
10092
container:
10193
image: ${{ needs.dockerfile-changed.outputs.image }}
94+
if: ${{ always() }}
95+
runs-on: ubuntu-latest
10296
steps:
10397
- name: Checkout
10498
uses: actions/checkout@v4
105-
- name: Set ownership
106-
run: |
107-
chown -R $(id -u):$(id -g) $PWD
10899
- name: Build docs
109100
run: |
110101
./repo docs
@@ -124,7 +115,7 @@ jobs:
124115
if-no-files-found: error
125116
retention-days: 1
126117
- name: Store PR information
127-
if: ${{ github.event_name == 'pull_request' }}
118+
if: github.event_name == 'pull_request'
128119
run: |
129120
mkdir ./pr
130121
echo ${{ github.event.number }} > ./pr/pr.txt
@@ -139,7 +130,6 @@ jobs:
139130

140131
store-html:
141132
needs: [ build-docs ]
142-
if: ${{ github.event_name == 'push' }}
143133
runs-on: ubuntu-latest
144134
steps:
145135
- uses: actions/checkout@v4

.github/workflows/docs-preview-pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: docs-preview-pr
22

33
on:
44
workflow_run:
5-
workflows: [ docs-build ]
5+
workflows: [ docs-build-pr ]
66
types: [ completed ]
7-
branches-ignore: [ 'master' ]
7+
branches-ignore: [ main ]
88

99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

0 commit comments

Comments
 (0)