Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/preview-fork-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ jobs:
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.pull_requests[0].number > 0 &&
github.event.workflow_run.head_repository.id != github.event.repository.id
(github.event.workflow_run.head_repository.id != github.event.repository.id ||
startsWith(github.event.workflow_run.head_branch, 'dependabot/'))
runs-on: ubuntu-latest
timeout-minutes: 15
concurrency:
group: documentation-preview-${{ github.event.workflow_run.pull_requests[0].number }}
cancel-in-progress: false
steps:
- name: Download validated preview HTML
uses: actions/download-artifact@v4
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -46,7 +47,7 @@ jobs:

- name: Create scoped Pages deployment token
id: preview-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
private-key: ${{ secrets.LIBRECODE_WORKFLOW_APP_PRIVATE_KEY }}
Expand All @@ -65,7 +66,7 @@ jobs:
preview-branch: gh-pages
pages-base-url: libresign.github.io/site-preview
wait-for-pages-deployment: true
qr-code: false
qr-code: true
token: ${{ steps.preview-token.outputs.token }}

- name: Verify navigable public preview
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/preview-remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Create scoped cleanup token
id: preview-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
private-key: ${{ secrets.LIBRECODE_WORKFLOW_APP_PRIVATE_KEY }}
Expand Down
88 changes: 70 additions & 18 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
python -m versioning.verify --output _build
python -m versioning.publish --built _build --destination _publish
python -m versioning.verify --output _publish
rm _publish/CNAME
rm _publish/CNAME _publish/.nojekyll

- name: Render navigable HTML for unpublished release documentation
env:
Expand All @@ -58,8 +58,8 @@ jobs:
--site _publish --preview-root "$PREVIEW_ROOT"

- name: Upload unprivileged preview for fork PRs
if: github.event.pull_request.head.repo.full_name != github.repository
uses: actions/upload-artifact@v4
if: github.event.pull_request.head.repo.full_name != github.repository || github.event.pull_request.user.login == 'dependabot[bot]'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: documentation-preview-site
path: _publish/
Expand All @@ -68,9 +68,9 @@ jobs:
retention-days: 3

- name: Create scoped preview deployment token
if: github.event.pull_request.head.repo.full_name == github.repository
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
id: preview-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
private-key: ${{ secrets.LIBRECODE_WORKFLOW_APP_PRIVATE_KEY }}
Expand All @@ -79,7 +79,8 @@ jobs:
permission-contents: write

- name: Deploy preview to separate GitHub Pages origin
if: github.event.pull_request.head.repo.full_name == github.repository
id: preview-deploy
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
uses: LibreSign/pr-preview-action@2a6da1177b47dc23173ba9a75e01da0a0d800978
with:
action: deploy
Expand All @@ -89,45 +90,96 @@ jobs:
deploy-repository: LibreSign/site-preview
preview-branch: gh-pages
pages-base-url: libresign.github.io/site-preview
wait-for-pages-deployment: true
qr-code: true
# A newer deployment from another PR can supersede this Pages build.
# Verify our published revision over HTTP instead of waiting on its run ID.
wait-for-pages-deployment: false
comment: false
qr-code: false
token: ${{ steps.preview-token.outputs.token }}

- name: Wait until GitHub Pages serves this exact preview revision
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
env:
PREVIEW_ROOT: https://libresign.github.io/site-preview/docs-preview/pr-${{ github.event.pull_request.number }}
run: |
# The deploy action pushes gh-pages, but Pages publishes it
# asynchronously. Byte equality of versions.json proves the
# exact documentation revision has reached the public origin.
for attempt in $(seq 1 108); do
if curl -fsSL --max-time 15 -H 'Cache-Control: no-cache' \
-o /tmp/libresign-live-versions.json \
"$PREVIEW_ROOT/versions.json?run=$GITHUB_RUN_ID&attempt=$attempt" &&
cmp -s _publish/versions.json /tmp/libresign-live-versions.json; then
echo "GitHub Pages serves the expected documentation revision"
break
fi
if [ "$attempt" -eq 108 ]; then
echo "::error::GitHub Pages did not publish this preview revision" >&2
exit 1
fi
sleep 10
done

- name: Check every navigable preview route on the public origin
if: github.event.pull_request.head.repo.full_name == github.repository
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
env:
PREVIEW_ROOT: https://libresign.github.io/site-preview/docs-preview/pr-${{ github.event.pull_request.number }}
run: |
while IFS= read -r route; do
# GitHub Pages is shared with other PR previews. Its deployment run
# can be superseded even when this preview's HTML is publicly served.
# Compare rendered pages with the public origin instead of a specific
# Pages run or PR merge SHA.
{
cat _publish/_review/routes.txt
find _publish -type f -name '*.html' -printf '/%P\n'
printf '%s\n' '/home.css' '/ecosystem-nav.css' '/ecosystem-nav.js' '/scroll-navigation.js' '/home-theme.js' '/versions.json'
} | sort -u | while IFS= read -r route; do
[ -n "$route" ] || continue
local_page="_publish$route"
if [[ "$route" == */ ]]; then
local_page="${local_page}index.html"
fi
if [ ! -f "$local_page" ]; then
echo "::error::Missing generated preview page: $local_page" >&2
exit 1
fi
url="$PREVIEW_ROOT$route"
success=false
for attempt in $(seq 1 24); do
if curl -fsSL --max-time 15 -o /tmp/libresign-preview-page.html "$url" &&
grep -Eq 'libresign-version-toggle|Documentation by release|Preview-only documentation' /tmp/libresign-preview-page.html; then
echo "Public preview available: $url"
for attempt in $(seq 1 4); do
if curl -fsSL --max-time 15 -H 'Cache-Control: no-cache' \
-o /tmp/libresign-preview-page.html \
"$url?run=$GITHUB_RUN_ID&attempt=$attempt" &&
cmp -s "$local_page" /tmp/libresign-preview-page.html; then
echo "Published preview matches generated content: $url"
success=true
break
fi
sleep 5
done
if [ "$success" != true ]; then
echo "::error::Preview page unavailable: $url" >&2
echo "::error::Public preview missing or stale: $url" >&2
exit 1
fi
done < _publish/_review/routes.txt
done

- name: Comment with navigable preview links
if: github.event.pull_request.head.repo.full_name == github.repository
if: github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PREVIEW_ROOT: https://libresign.github.io/site-preview/docs-preview/pr-${{ github.event.pull_request.number }}
ACTION_VERSION: ${{ steps.preview-deploy.outputs.action-version }}
ACTION_START_TIME: ${{ steps.preview-deploy.outputs.action-start-time }}
run: |
python -m versioning.pr_preview \
--site _publish --preview-root "$PREVIEW_ROOT" \
--action-version "$ACTION_VERSION" --built-at "$ACTION_START_TIME"
body=$(cat _publish/_review/preview-comment.md)
marker='<!-- libresign-documentation-preview-links -->'
legacy='<!-- libresign-documentation-review-screenshots -->'
native='<!-- Sticky Pull Request Commentpr-preview -->'
comment_id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments?per_page=100" \
--paginate --jq ".[] | select(.body | contains(\"$marker\") or contains(\"$legacy\")) | .id" | head -n 1)
--paginate --jq ".[] | select(.body | contains(\"$marker\") or contains(\"$legacy\") or contains(\"$native\")) | .id" | head -n 1)
if [ -n "$comment_id" ]; then
gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment_id" \
-f body="$body" >/dev/null
Expand Down
Loading