Skip to content
Merged
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
76 changes: 75 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,62 @@ on:
- reopened
- synchronize
- labeled
- unlabeled
push:
branches:
- main

jobs:
docs-config:
name: Documentation version configuration
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout trusted validator
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha || github.sha }}
path: trusted
persist-credentials: false
sparse-checkout: |
scripts/docs_versions.py
scripts/generate_versioned_api_docs.py
sparse-checkout-cone-mode: false
- name: Checkout candidate configuration
uses: actions/checkout@v4
with:
path: candidate
persist-credentials: false
sparse-checkout: api-docs/versions.json
sparse-checkout-cone-mode: false
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Validate candidate configuration with trusted code
working-directory: trusted
run: |
python3 -I - <<'PY'
import importlib.util
from pathlib import Path

validator = Path("scripts/docs_versions.py")
if validator.is_file():
entry_point = "load"
else:
validator = Path("scripts/generate_versioned_api_docs.py")
entry_point = "load_versions"
print(
"::notice::Using the trusted base's legacy tag-list validator. "
"Full release-line validation runs in the authorized docs build "
"until the new validator reaches the base branch."
)
spec = importlib.util.spec_from_file_location("docs_validator", validator)
docs = importlib.util.module_from_spec(spec)
spec.loader.exec_module(docs)
getattr(docs, entry_point)(Path("../candidate/api-docs/versions.json"))
PY

docs:
name: Versioned API documentation
permissions:
Expand All @@ -37,12 +88,35 @@ jobs:
run: sudo apt-get install doxygen
- name: Test documentation tooling
run: |
python3 -m unittest discover -s tests -p 'test_versioned_docs.py'
python3 -m unittest discover -s tests -p 'test_*docs*.py'
node --test tests/test_version_selector.js
- name: Build versioned documentation
env:
GH_TOKEN: ${{ github.token }}
run: python3 scripts/generate_versioned_api_docs.py
- name: Upload documentation preview
uses: actions/upload-artifact@v4
with:
name: versioned-api-documentation
path: api-docs/_build/versioned/
if-no-files-found: error

docs-required:
name: Documentation checks
needs: [docs-config, docs]
if: always()
permissions: {}
runs-on: ubuntu-latest
steps:
- name: Require successful validation and build
env:
CONFIG_RESULT: ${{ needs.docs-config.result }}
BUILD_RESULT: ${{ needs.docs.result }}
run: |
if [ "$CONFIG_RESULT" != success ] || [ "$BUILD_RESULT" != success ]; then
echo "::error::Documentation checks did not succeed (configuration: $CONFIG_RESULT, build: $BUILD_RESULT). A maintainer must authorize gated builds with the 'safe to test' label."
exit 1
fi

tests:
name: Unit tests
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/promote-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Promote API documentation versions

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read

# Do not serialize promotions with Actions concurrency: pending runs can be lost.
# Each run reconciles all releases and retries conflicting manifest writes.
jobs:
promote:
if: github.event_name != 'release' || github.event.release.prerelease == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
persist-credentials: false

- name: Require dedicated documentation App credentials
env:
APP_ID: ${{ vars.C2PA_DOCS_APP_ID }}
APP_KEY: ${{ secrets.C2PA_DOCS_APP_PRIVATE_KEY }}
run: |
if [[ -z "$APP_ID" || -z "$APP_KEY" ]]; then
echo "::error::Configure vars.C2PA_DOCS_APP_ID and secrets.C2PA_DOCS_APP_PRIVATE_KEY for the dedicated documentation GitHub App."
exit 1
fi

- name: Create repository-scoped manifest promotion token
id: app
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.C2PA_DOCS_APP_ID }}
private-key: ${{ secrets.C2PA_DOCS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write

- name: Reconcile stable published releases into the manifest only
env:
DOCS_APP_TOKEN: ${{ steps.app.outputs.token }}
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || '' }}
run: python3 scripts/promote_docs_versions.py
94 changes: 43 additions & 51 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,36 @@
name: Build and publish docs

on:
release:
types: [published]

push:
branches: ['main']

workflow_dispatch:

workflow_run:
workflows: ['Promote API documentation versions']
types: [completed]

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: 'github-pages'
group: github-pages
cancel-in-progress: false

jobs:
update-versions:
if: github.event_name == 'release' && github.event.release.prerelease == false
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main

- name: Update documentation versions
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Expected a stable release tag such as v0.26.14."
exit 1
fi
jq --arg tag "$RELEASE_TAG" \
'.versions = [$tag] + (.versions - [$tag])' \
api-docs/versions.json > "$RUNNER_TEMP/versions.json"
mv "$RUNNER_TEMP/versions.json" api-docs/versions.json
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add api-docs/versions.json
if git diff --cached --quiet; then
echo "Documentation versions already include $RELEASE_TAG as the default."
else
git commit -m "docs: update API documentation versions for $RELEASE_TAG"
git push origin HEAD:main
fi

deploy:
needs: update-versions
if: |
!cancelled() &&
(needs.update-versions.result == 'success' || needs.update-versions.result == 'skipped')
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
build:
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
revision: ${{ steps.revision.outputs.sha }}
steps:
- uses: actions/checkout@v4
with:
filter: tree:0
fetch-depth: 0
ref: main
persist-credentials: false

- name: Setup Pages
uses: actions/configure-pages@v5
- name: Record current main revision
id: revision
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- name: Install Doxygen
run: sudo apt-get install doxygen
Expand All @@ -88,6 +50,36 @@ jobs:
with:
path: 'api-docs/_build/versioned/'

deploy:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Reject stale artifacts
id: current
env:
GH_TOKEN: ${{ github.token }}
BUILT_SHA: ${{ needs.build.outputs.revision }}
REPOSITORY: ${{ github.repository }}
run: |
current=$(gh api "repos/$REPOSITORY/git/ref/heads/main" --jq .object.sha)
if [[ "$current" == "$BUILT_SHA" ]]; then
echo "deploy=true" >> "$GITHUB_OUTPUT"
else
echo "Skipping stale artifact $BUILT_SHA; main is $current."
fi

- name: Setup Pages
if: steps.current.outputs.deploy == 'true'
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
if: steps.current.outputs.deploy == 'true'
id: deployment
uses: actions/deploy-pages@v4
Loading
Loading