-
Notifications
You must be signed in to change notification settings - Fork 170
125 lines (115 loc) · 4.49 KB
/
pr-preview.yml
File metadata and controls
125 lines (115 loc) · 4.49 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# This code is a Qiskit project.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
name: PR preview
on:
pull_request:
paths:
- "docs/**/*"
- "learning/**/*"
- "public/images/**/*"
# PR previews don't build API docs.
- "!docs/api/**/*"
- "!public/images/api/**/*"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
pr-preview:
name: PR preview
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
env:
PR_PREVIEW_PATH: pr-${{ github.event.pull_request.number }}
PR_PREVIEW_URL: https://qiskit.github.io/documentation/pr-${{ github.event.pull_request.number }}/
# Refer to https://yarnpkg.com/features/security#hardened-mode. We cannot enable this
# because the Dockerfile already has the dependencies pre-installed and eagerly
# validating the lockfile will miss the required auth token.
YARN_ENABLE_HARDENED_MODE: 0
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: docker/login-action@v3
with:
registry: icr.io
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- name: Set up deployment status
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: pr_preview
ref: ${{ github.event.pull_request.head.ref }}
- name: Get all changed files
id: changed-files
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CHANGED_FILES="$(node scripts/ci/determine-changed-files.ts "${{ github.event.number }}")"
{
echo "ALL_CHANGED_FILES<<__GH_OUTPUT__"
printf '%s\n' "$CHANGED_FILES"
echo "__GH_OUTPUT__"
} >> "$GITHUB_OUTPUT"
- name: Determine changed content files
env:
GH_TOKEN: ${{ github.token }}
CHANGED_FILES: ${{ steps.changed-files.outputs.ALL_CHANGED_FILES }}
# If changing these regexes, test them on https://regex101.com/ with the
# following paths (you can paste the block in and uncomment it):
# Add new tests if necessary
CONTENT_FILE_REGEX: (docs|learning)(?!\/api)\/.*\.(mdx|ipynb|json)
# -- Should match:
# docs/guides/thing.ipynb
# docs/guides/thing.mdx
# learning/courses/my-course/introduction.ipynb
# docs/guides/_toc.json
#
# -- Should not match:
# docs/api/qiskit/index.mdx
# scripts/nb-tester/example-notebook.ipynb
id: changed-content-files
run: |
CHANGED_CONTENT_FILES=$(echo "${CHANGED_FILES[@]}" | grep -P $CONTENT_FILE_REGEX || true)
mkdir -p .github/outputs
echo "Detected these changed content files:"
echo $CHANGED_CONTENT_FILES
echo $CHANGED_CONTENT_FILES >> .github/outputs/changed-content-files.txt
- name: Build static site
run: >
scripts/pr-previews/builder.py
${{ env.PR_PREVIEW_PATH }}
--basepath /documentation/${{ env.PR_PREVIEW_PATH }}
- name: Delete temp files
# Otherwise this gets pushed to the gh-pages branch
run: rm -r .github/outputs
- name: Deploy to GitHub Pages
run: scripts/pr-previews/deploy.py ${{ env.PR_PREVIEW_PATH }}
- name: Determine deployment result
run: scripts/pr-previews/poll_deployment.py ${{ env.PR_PREVIEW_URL }}
- name: Report deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ github.token }}
env: ${{ steps.deployment.outputs.env }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ env.PR_PREVIEW_URL }}
override: false