forked from googleapis/genai-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (83 loc) · 3.34 KB
/
docs_preview_deploy.yaml
File metadata and controls
94 lines (83 loc) · 3.34 KB
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
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: "Deploy Docs Preview"
on:
workflow_run:
workflows: ["Build Docs Preview"]
types:
- completed
workflow_dispatch:
inputs:
pr_number:
description: 'PR Number to deploy (Manual override)'
required: true
type: string
build_run_id:
description: 'The Run ID from the successful "Build Docs Preview" workflow'
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
deploy-preview:
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-24.04
concurrency:
group: "deploy-${{ github.event.inputs.pr_number || github.event.workflow_run.pull_requests[0].number }}"
cancel-in-progress: true
steps:
- name: Checkout base repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Download Artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: docs-preview-data
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.inputs.build_run_id || github.event.workflow_run.id }}
path: downloaded-artifact
- name: Read PR Number
id: get_pr
run: |
if [ -n "${{ github.event.inputs.pr_number }}" ]; then
PR_NUMBER="${{ github.event.inputs.pr_number }}"
else
PR_NUMBER=$(cat downloaded-artifact/pr_number.txt)
fi
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "Error: PR number [$PR_NUMBER] is invalid."
exit 1
fi
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
- name: Deploy
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: downloaded-artifact/public
publish_branch: versioned-gh-pages
destination_dir: ./previews/PR-${{ steps.get_pr.outputs.pr_number }}
commit_message: "stage: PR-${{ steps.get_pr.outputs.pr_number }} preview"
- name: Comment
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const prNumber = parseInt('${{ steps.get_pr.outputs.pr_number }}', 10);
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🔎 Preview at https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/PR-${prNumber}/`
});