@@ -2,17 +2,7 @@ name: Generate Docs
22
33on :
44 workflow_dispatch :
5- inputs :
6- preview :
7- description : should be preview
8- type : boolean
9- default : false
10- workflow_call :
11- inputs :
12- preview :
13- description : should be preview
14- type : boolean
15- default : false
5+ workflow_call :
166
177permissions :
188 contents : read
@@ -28,66 +18,73 @@ jobs:
2818 runs-on : ubuntu-latest
2919 outputs :
3020 preview-path : ${{ steps.preview-path.outputs.value }}
21+ is-preview : ${{ steps.mode.outputs.value }}
3122 steps :
3223 - uses : actions/checkout@v7
3324 with :
3425 fetch-depth : 0
3526
27+ # single source of truth for preview-vs-production, reused by every step below and by deploy
28+ - name : Determine preview mode
29+ id : mode
30+ shell : bash
31+ run : echo "value=${{ github.ref != 'refs/heads/main' }}" >> "$GITHUB_OUTPUT"
32+
3633 - name : Determine preview path
37- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
34+ if : ${{ steps.mode.outputs.value == 'true ' }}
3835 id : preview-path
3936 shell : bash
4037 run : echo "value=$(printf '%s' "$GITHUB_REF_NAME" | sed 's#[^A-Za-z0-9._-]#-#g')" >> "$GITHUB_OUTPUT"
4138
4239 - name : Build documentation
43- if : ${{ !inputs.preview && github.ref == 'refs/heads/main ' }}
40+ if : ${{ steps.mode.outputs.value == 'false ' }}
4441 uses : ./.github/actions/build-docs
4542
4643 - name : Build preview
47- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
44+ if : ${{ steps.mode.outputs.value == 'true ' }}
4845 uses : ./.github/actions/build-docs
4946 env :
5047 VUEPRESS_BASE : /fusion-framework/previews/${{ steps.preview-path.outputs.value }}/
5148 with :
5249 upload-artifact : false
5350
5451 - name : Preserve preview output
55- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
52+ if : ${{ steps.mode.outputs.value == 'true ' }}
5653 shell : bash
5754 run : |
5855 mkdir -p "$RUNNER_TEMP/docs-preview"
5956 cp -R vue-press/dist/. "$RUNNER_TEMP/docs-preview/"
6057
6158 - name : Checkout main
62- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
59+ if : ${{ steps.mode.outputs.value == 'true ' }}
6360 uses : actions/checkout@v7
6461 with :
6562 ref : main
6663 fetch-depth : 0
6764
6865 - name : Build production documentation
69- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
66+ if : ${{ steps.mode.outputs.value == 'true ' }}
7067 uses : ./.github/actions/build-docs
7168 with :
7269 upload-artifact : false
7370
7471 - name : Add preview to production output
75- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
72+ if : ${{ steps.mode.outputs.value == 'true ' }}
7673 shell : bash
7774 run : |
7875 mkdir -p "vue-press/dist/previews/${{ steps.preview-path.outputs.value }}"
7976 cp -R "$RUNNER_TEMP/docs-preview/." "vue-press/dist/previews/${{ steps.preview-path.outputs.value }}/"
8077
8178 - name : Upload Pages artifact
82- if : ${{ inputs.preview || github.ref != 'refs/heads/main ' }}
79+ if : ${{ steps.mode.outputs.value == 'true ' }}
8380 uses : actions/upload-pages-artifact@v4
8481 with :
8582 path : ./vue-press/dist
8683
8784 deploy :
8885 environment :
8986 name : github-pages
90- url : ${{ (inputs. preview || github.ref != 'refs/heads/main') && format('{0}previews/{1}/', steps.deployment.outputs.page_url, needs.build.outputs.preview-path) || steps.deployment.outputs.page_url }}
87+ url : ${{ needs.build.outputs.is- preview == 'true' && format('{0}previews/{1}/', steps.deployment.outputs.page_url, needs.build.outputs.preview-path) || steps.deployment.outputs.page_url }}
9188 runs-on : ubuntu-latest
9289 needs : build
9390 steps :
9693 uses : actions/deploy-pages@v5
9794
9895 - name : Publish preview URL
99- if : ${{ inputs. preview || github.ref != 'refs/heads/main ' }}
96+ if : ${{ needs.build.outputs.is- preview == 'true ' }}
10097 shell : bash
10198 run : echo "### [Open docs preview](${{ steps.deployment.outputs.page_url }}previews/${{ needs.build.outputs.preview-path }}/)" >> "$GITHUB_STEP_SUMMARY"
0 commit comments