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
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ _Give a narrative description of what has been changed._
## Checklist
- [ ] This PR represents a single feature, fix, or change.
- [ ] All applicable changes have been documented.
- [ ] If this is a stable release introducing a new major/minor version line, its tag has been added to `api-docs/versions.json` (patch releases and prereleases do not add entries).
- [ ] Any `TO DO` items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.
93 changes: 93 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Deploy API docs

on:
workflow_run:
workflows: ['Build and publish docs']
types: [completed]
workflow_dispatch:
push:
branches: [main]
paths:
- 'api-docs/**'
- 'scripts/generate_api_docs.py'
- 'scripts/generate_versioned_api_docs.py'
- 'scripts/docs_versions.py'
- 'scripts/promote_docs_release.py'
- 'requirements-dev.txt'
- '.github/workflows/publish-docs.yml'
- '.github/workflows/deploy-docs.yml'

permissions:
contents: read

# Coalesce publications, not promotions. Every admitted run builds current main
# after entering this group, so replacement of pending events cannot lose state.
concurrency:
group: >-
${{ (github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository)) &&
'github-pages' || format('docs-ignored-{0}', github.run_id) }}
cancel-in-progress: false

jobs:
build:
if: >-
(github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository))
runs-on: ubuntu-latest
outputs:
revision: ${{ steps.source.outputs.revision }}
steps:
- uses: actions/checkout@v4
with:
filter: tree:0
fetch-depth: 0
ref: main
persist-credentials: false
- id: source
run: echo "revision=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
- name: Install documentation dependencies
run: python -m pip install -r requirements-dev.txt
- name: Build exact release sources with current tooling
env:
GITHUB_TOKEN: ${{ github.token }}
run: python scripts/generate_versioned_api_docs.py
- uses: actions/upload-pages-artifact@v3
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 obsolete build
id: current
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
BUILT_REVISION: ${{ needs.build.outputs.revision }}
run: |
latest=$(gh api "repos/$REPOSITORY/commits/main" --jq .sha)
if [[ "$latest" == "$BUILT_REVISION" ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Skipping obsolete build; a queued publication builds current main. Manually dispatch if only unrelated paths changed."
fi
- uses: actions/configure-pages@v5
if: steps.current.outputs.publish == 'true'
- uses: actions/deploy-pages@v4
if: steps.current.outputs.publish == 'true'
id: deployment
89 changes: 25 additions & 64 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,44 @@ on:

workflow_dispatch:

push:
branches: [main]
paths:
- 'api-docs/**'
- 'scripts/generate_api_docs.py'
- 'scripts/generate_versioned_api_docs.py'
- 'requirements-dev.txt'
- '.github/workflows/publish-docs.yml'

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

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

# Do not queue promotions in a concurrency group: GitHub discards pending runs.
jobs:
deploy:
permissions:
contents: write
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
promote:
if: github.event_name == 'release' && !github.event.release.prerelease && !github.event.release.draft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
filter: tree:0
fetch-depth: 0
ref: main

- name: Add release to versioned documentation
if: github.event_name == 'release' && !github.event.release.prerelease
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Require dedicated documentation App
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
APP_ID: ${{ vars.C2PA_DOCS_APP_ID }}
APP_KEY: ${{ secrets.C2PA_DOCS_APP_PRIVATE_KEY }}
run: |
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "::error::Release tags must use the format vX.Y.Z with an optional prerelease suffix (e.g. v1.2.3-alpha)"
if [[ -z "$APP_ID" || -z "$APP_KEY" ]]; then
echo "::error::Configure C2PA_DOCS_APP_ID and C2PA_DOCS_APP_PRIVATE_KEY for the repository-scoped docs App; no workflow-token fallback is permitted."
exit 1
fi
jq --arg tag "$RELEASE_TAG" '.versions = [$tag] + (.versions - [$tag])' \
api-docs/versions.json > api-docs/versions.json.tmp
mv api-docs/versions.json.tmp api-docs/versions.json
git add api-docs/versions.json
if ! git diff --cached --quiet; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "docs: add $RELEASE_TAG to the versioned docs"
git push origin HEAD:main
fi

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Set up Python
uses: actions/setup-python@v5
- name: Mint manifest writer token
id: app
uses: actions/create-github-app-token@v2
with:
python-version: "3.10"
cache: "pip"

- name: Install dev deps
run: python3 -m pip install -r requirements-dev.txt

- name: Build docs
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: Verify and promote stable release
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_ID: ${{ github.event.release.id }}
GITHUB_TOKEN: ${{ github.token }}
run: python3 scripts/generate_versioned_api_docs.py

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'api-docs/_build/versioned/'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
DOCS_WRITE_TOKEN: ${{ steps.app.outputs.token }}
run: python scripts/promote_docs_release.py
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ See the [`examples` directory](https://github.com/contentauth/c2pa-python/tree/m

API documentation is published at [github.io/c2pa-python/api/c2pa](https://contentauth.github.io/c2pa-python/api/c2pa/index.html).

Use the documentation version dropdown to choose a published release.
The versions are selected in `api-docs/versions.json`; the first entry is the default at the existing documentation URL.
Publishing a stable GitHub release automatically adds its tag as the default while retaining older versions.
Use the documentation version dropdown to choose a retained major/minor line.
`api-docs/versions.json` selects one exact stable patch per line, in numeric descending order;
the highest line is the default at the existing documentation URL.
Once the documentation App is configured, stable releases advance retained lines or
introduce newer lines automatically. Maintenance releases never displace a newer default.

To build documentation locally, see [Contributing to the project](https://github.com/contentauth/c2pa-python/blob/main/docs/project-contributions.md#api-reference-documentation).

Expand Down
5 changes: 3 additions & 2 deletions api-docs/_templates/version-selector.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<div class="sidebar-tree">
<select id="docs-version" aria-label="Documentation version">
{% for item in docs_versions %}
<option value="{{ item.url | e }}"{% if item.tag == docs_tag %} selected{% endif %}>{{ item.tag | e }}</option>
<option value="{{ item.url | e }}"{% if item.tag == docs_tag %} selected{% endif %}>{{ item.line | e }}</option>
{% endfor %}
</select>
<noscript>
<ul>
{% for item in docs_versions %}
<li><a href="{{ item.url | e }}">{{ item.tag | e }}</a></li>
<li><a href="{{ item.url | e }}">{{ item.line | e }}</a></li>
{% endfor %}
</ul>
</noscript>
<p>API source: {{ docs_tag | e }}</p>
</div>
8 changes: 6 additions & 2 deletions api-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
docs_prefix = os.environ.get("C2PA_DOCS_PREFIX", "")
if docs_versions:
release = docs_tag
version = docs_tag
version = ".".join(docs_tag.removeprefix("v").split(".")[:2])
html_sidebars = {
"**": [
"sidebar/brand.html",
Expand Down Expand Up @@ -108,7 +108,11 @@ def _add_version_selector(app, pagename, templatename, context, doctree):
context["docs_versions"] = [
{
"tag": tag,
"url": posixpath.relpath(f"versions/{tag}/index.html", current_directory),
"line": ".".join(tag.removeprefix("v").split(".")[:2]),
"url": posixpath.relpath(
"versions/" + ".".join(tag.removeprefix("v").split(".")[:2]) + "/index.html",
current_directory,
),
}
for tag in docs_versions
]
Expand Down
20 changes: 13 additions & 7 deletions api-docs/versions.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"versions": [
"v0.39.0",
"v0.38.4",
"v0.38.3",
"v0.38.2",
"v0.38.1",
"v0.38.0",
"v0.39.0",
"v0.38.4",
"v0.37.12"
]
],
"retiredLines": [],
"aliases": {
"v0.39.0": "0.39",
"v0.38.4": "0.38",
"v0.38.3": "0.38",
"v0.38.2": "0.38",
"v0.38.1": "0.38",
"v0.38.0": "0.38",
"v0.37.12": "0.37"
}
}
86 changes: 70 additions & 16 deletions docs/project-contributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,27 @@ This uses `sphinx-autoapi` to parse `src/c2pa` directly, avoiding imports of nat

### Versioned release documentation

Edit [api-docs/versions.json](../api-docs/versions.json) to choose the exact
GitHub release tags shown in the sidebar dropdown. Entries must be unique
tags such as `v0.38.0`. The first entry is the default served at the existing
documentation URL. When a stable GitHub release is published, the publishing
workflow prepends its tag and commits the updated list to `main` before building
the site. Older entries are retained; pre-releases are not automatically added.
[api-docs/versions.json](../api-docs/versions.json) is the publication policy:
`versions` selects one exact stable `vX.Y.Z` tag per retained major/minor line,
sorted numerically descending. The highest line is the root default. `aliases`
maps historical exact tags to unprefixed `X.Y` lines; every selected tag must
have an alias. `retiredLines` records lines automation must never restore.
The validator rejects empty selections, duplicate lines, prereleases, invalid
aliases, and active/retired overlap.

On stable release publication, the standard-library-only promoter verifies
the release tag, event release ID, published timestamp and stable/draft flags.
It reconciles all published stable releases: retained lines advance to their
highest patch, and new lines are admitted only above every active or retired
line. It never backfills unlisted historical lines or regresses a patch/default.
Migration consolidates only the previously listed lines and preserves their
exact-tag aliases; it does not discover additional historical lines.

To retire a line, submit a human PR removing its selected tag and every alias
targeting it, and add its unprefixed `X.Y` to `retiredLines`. Keep at least one
active line. To deliberately restore or backfill a historical line, use a human
PR with an exact published tag and matching aliases (remove its retirement
entry if applicable). Do not manually add a future, unpublished release tag.

Fetch the release tags and build the complete site:

Expand All @@ -186,15 +201,54 @@ API pages untouched.
The complete site is written to `api-docs/_build/versioned/`:

- The default version is also served at the root, preserving existing API URLs.
- Each selected release has a stable URL under `versions/<tag>/`.
- Switching versions opens that release's documentation home page.
- Each line has a canonical URL under `versions/X.Y/`; the sidebar displays
`X.Y` and the page identifies its exact source patch.
- Historical `versions/vX.Y.Z/` HTML URLs redirect to equivalent canonical
pages, preserving nested suffixes, query strings and fragments. Removed pages
without an equivalent are not redirected to an unrelated API.
- Switching lines opens that line's documentation home page.
- A regular `make docs` build remains an unversioned working-tree preview.

The publishing workflow always checks out `main` for the release list and
build tooling, including when triggered by a release. It rebuilds all selected
versions when a release is published, when relevant documentation files change
on `main`, or when manually dispatched. The workflow needs permission to push
the version-list commit to `main`, including under any branch protection rules.
The same release-triggered run builds and deploys the updated list; it does not
rely on the bot's push triggering another workflow. Publish manual changes to
the list on `main` to add, remove, or reorder dropdown entries.
The workflow uses current `main` tooling, never release-supplied scripts.
Promotion is an isolated job with no dependency installation or docs build.
Its only remote write is a Contents API compare-and-swap on the exact allowlisted
path `api-docs/versions.json` on `main`. Five bounded retries reread and recompute
against concurrent edits, without force pushes or lost unrelated main changes.
There is no promotion concurrency group to silently discard burst events;
release reconciliation also converges when releases arrive out of order.

Organization administrators can share the documentation App across the SDK
repositories using the Actions organization variable `C2PA_DOCS_APP_ID` and
organization secret `C2PA_DOCS_APP_PRIVATE_KEY`. Grant both selected-repository
access to this repository; workflows read them as `vars.C2PA_DOCS_APP_ID` and
`secrets.C2PA_DOCS_APP_PRIVATE_KEY`. Repository-level values override organization
values, so remove stale repository overrides when adopting the shared credentials.
Install the App on each participating repository with Contents write permission,
and separately authorize it under each repository's applicable main
protection/ruleset. Configuring credentials alone does not grant installation
access or protection bypass. The workflow mints a short-lived,
repository-scoped installation token and fails explicitly if setup is absent.
It never falls back to the ordinary workflow token for protected-branch writes.
App permissions are repository-level, not path-level; the writer's fixed API
endpoint enforces its manifest-only allowlist. Do not expose this credential to
builds, dependency installation, pull requests or release source code.

The separate `Deploy API docs` workflow starts explicitly on successful
completion of `Build and publish docs` (`workflow_run`); it does not depend on
the App push retriggering workflows. Relevant pushes to `main` and manual dispatch
still publish; App-push and workflow-completion publications may coalesce.
The complete build/deploy workflow is serialized, but checks out current `main`
only after admission, so coalescing pending publication events cannot discard
manifest updates. Failed upstream runs use isolated concurrency groups so they
cannot displace successful pending publications. Publishing never writes to the
repository, so it cannot create a push loop. The build remains read-only; only the separate deployment
job gets Pages write and OIDC permissions. Deployment rejects artifacts whose
source SHA no longer matches current `main`; rerun publication manually if an
unrelated main change superseded the latest build. No live deployment or
App/protection provisioning is part of local validation.

Run the policy, promotion and generator tests with:

```sh
python -m unittest tests.test_docs_versions tests.test_versioned_docs -v
```
Loading
Loading