Skip to content

Commit b4d5651

Browse files
committed
Trigger publish from multiple branches (neo4j#2598)
1 parent cd3f5b7 commit b4d5651

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

.github/workflows/docs-generate-html.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
11

2-
name: "Generate and Publish HTML"
2+
name: "Generate HTML"
33

4+
# edit the list of branches according to your repository
5+
# the list of branches should contain all the branches in your Antora publish playbooks
46
on:
57
push:
68
branches:
79
- 'dev'
10+
- 'main'
11+
- '5.x'
12+
- '4.4'
813
workflow_dispatch:
914

15+
# change `dev` and `main` according to your repository's branch names
16+
# `dev` is the branch you use to build and publish to staging
17+
# `main` is the branch you use to build and publish to neo4j.com/docs
18+
# in some cases, PROD_BRANCH and DEV_BRANCH may be the same branch
1019
env:
11-
PUBLISH_TO: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
20+
PROD_BRANCH: 'main'
21+
DEV_BRANCH: 'dev'
1222

1323
jobs:
1424

25+
prepare-ref-env:
26+
name: Set build branch and environments
27+
runs-on: ubuntu-latest
28+
outputs:
29+
build-ref: ${{ steps.set-ref-env.outputs.build-ref }}
30+
environments: ${{ steps.set-ref-env.outputs.environments }}
31+
steps:
32+
- name: Set Build Ref
33+
id: set-ref-env
34+
run: |
35+
if [[ "${GITHUB_REF}" == "refs/heads/${{ env.DEV_BRANCH }}" ]]; then
36+
build_from=${{ env.DEV_BRANCH }}
37+
environments='["dev"]'
38+
else
39+
build_from=${{ env.PROD_BRANCH }}
40+
environments='["prod"]'
41+
fi
42+
# if dev branch = prod branch publish to both
43+
if [[ "${{ env.DEV_BRANCH }}" == "${{ env.PROD_BRANCH }}" ]]; then
44+
environments='["dev","prod"]'
45+
fi
46+
echo "build-ref=${build_from}" >> $GITHUB_OUTPUT
47+
echo "environments=${environments[@]}" >> $GITHUB_OUTPUT
48+
1549
docs-build:
1650
name: Generate HTML
51+
needs: prepare-ref-env
1752
uses: neo4j/docs-tools/.github/workflows/reusable-docs-build.yml@v2
1853
with:
1954
package-script: 'verify:publish'
55+
build-ref: ${{needs.prepare-ref-env.outputs.build-ref}}
56+
fetch-depth: 0
2057

2158
docs-verify:
2259
name: Verify HTML
@@ -27,11 +64,15 @@ jobs:
2764

2865
publish-html:
2966
name: Publish HTML
30-
needs: docs-verify
67+
needs: [docs-verify, prepare-ref-env]
3168
runs-on: ubuntu-latest
3269

70+
strategy:
71+
matrix:
72+
environments: ${{ fromJson(needs.prepare-ref-env.outputs.environments) }}
73+
3374
steps:
34-
- name: Trigger Publish
75+
- name: Publish to ${{ matrix.environments }}
3576
uses: peter-evans/repository-dispatch@bf47d102fdb849e755b0b0023ea3e81a44b6f570 # v2.1.2
3677
with:
3778
token: ${{ secrets.DOCS_DISPATCH_TOKEN }}
@@ -43,5 +84,5 @@ jobs:
4384
"repo": "${{ github.event.repository.name }}",
4485
"run_id": "${{ github.run_id }}",
4586
"args": "--dryrun",
46-
"publish_env": "${{ env.PUBLISH_TO }}"
87+
"publish_env": "${{ matrix.environments }}"
4788
}

0 commit comments

Comments
 (0)