Quelle export_crossrefs.yml Sprache: unbekannt
|
|
Spracherkennung für: .yml vermutete Sprache: SQL {SQL[54] VDM[42] Fortran[40]} [Methode: maximale Elemente, drei Dimensionen]
name: Export cross-reference data
# Generates a JSON dictionary of every declaration with a `CrossRef.Tag` attribute, e.g. `@[s tacks]`,
# with name, file, line, referenced ids and resolved urls.
# Pushes it to a versioned repository (`CROSSREFS_REPO`), where it is publicly
# available at `https://raw.githubusercontent.com/<CROSSREFS_REPO>/master/crossrefs.json`.
#
# The data is read from the fully-imported `Mathlib` environment by
# `scripts/export_crossrefs.lean`, like the `#stacks_tags` command.
on:
workflow_run:
workflows: ["continuous integration"]
branches: [master]
types: [completed]
workflow_dispatch:
inputs:
dry_run:
description: "Dry run: mint the app token and verify push permission, but don't push to the crossrefs repo"
type: boolean
default: true
concurrency:
# Keyed on the repository of the triggering run, so that runs triggered from forks,
# which the `export` job skips, can't cancel ours.
group: export-crossrefs-${{ github.event.workflow_run.head_repository.full_name || github.repository }}
cancel-in-progress: true
permissions:
contents: read
env:
CROSSREFS_REPO: leanprover-community/crossref-exports
BUILT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
jobs:
export:
name: Export cross-reference JSON
runs-on: ubuntu-latest
# `workflow_run` matches the triggering workflow by name and branch name only, which
# doesn't identify it. Only act on runs for pushes to this repository.
if: >-
github.repository == 'leanprover-community/mathlib4' &&
(github.event_name == 'workflow_dispatch'
|| (github.event.workflow_run.conclusion == 'success'
&& github.event.workflow_run.event == 'push'
&& github.event.workflow_run.head_repository.full_name == github.repository))
# This job runs Mathlib code and loads the cached oleans, so it gets no credentials, no
# OIDC token and no Actions cache. The `publish` job reads its result as data.
permissions:
contents: read
cache-mode: none
steps:
# For a tag push, `head_branch` is the tag name, so also check that the commit is on
# the master branch. (`branches/master` can't resolve to a tag.)
- name: Check that the built commit is on master
env:
GH_TOKEN: ${{ github.token }}
run: |
master_sha="$(gh api "repos/${GITHUB_REPOSITORY}/branches/master" --jq .commit.sha)"
status="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${BUILT_SHA}...${master_sha}?per_page=1" --jq .status)"
if [[ "${status}" != "identical" && "${status}" != "ahead" ]]; then
echo "::error::${BUILT_SHA} is not on master (compare status: ${status})."
exit 1
fi
- name: Checkout the built commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# The exact commit CI validated; for manual runs, the dispatched ref.
ref: ${{ env.BUILT_SHA }}
- name: Configure Lean and fetch the Mathlib cache
uses: leanprover/lean-action@fe408643ea7367d8c0404a8be3975bb145f5fb64 # v1.7.0
with:
auto-config: false
use-github-cache: false
use-mathlib-cache: true
reinstall-transient-toolchain: true
- name: Generate crossrefs.json
env:
CROSSREFS_OUT: crossrefs.json
CROSSREFS_COMMIT: ${{ env.BUILT_SHA }}
run: lake env lean scripts/export_crossrefs.lean
- name: Sanity-check the output
run: |
jq -e '.entries | length > 0' crossrefs.json > /dev/null
echo "Exported $(jq '.entries | length' crossrefs.json) entries."
- name: Upload crossrefs.json
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: crossrefs
path: crossrefs.json
if-no-files-found: error
retention-days: 3
publish:
name: Publish cross-reference JSON
needs: export
runs-on: ubuntu-latest
environment:
name: crossref-exports
deployment: false
# Holds the app token. Nothing from the checkout runs in this job: it only takes
# `crossrefs.json` from the `export` job's artifact.
permissions:
contents: read
# Required for the token-minting action to request a GitHub OIDC token,
# which it exchanges (via Azure Key Vault) for a GitHub App installation token.
id-token: write
steps:
- name: Download crossrefs.json
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: crossrefs
# Split `owner/repo` so the token can be scoped to the crossrefs repo. The
# app is installed on the crossrefs repo's owner, not on this repository,
# so the token-minting action must resolve the installation from there.
- name: Resolve crossrefs repository owner and name
id: repo
run: |
echo "owner=${CROSSREFS_REPO%%/*}" >> "$GITHUB_OUTPUT"
echo "name=${CROSSREFS_REPO#*/}" >> "$GITHUB_OUTPUT"
# Mint a short-lived GitHub App installation token scoped to the crossrefs
# repo, instead of relying on a long-lived personal access token.
- name: Generate app token
id: app-token
uses: leanprover-community/mathlib-ci/.github/actions/azure-create-github-app-token@d6393a535c054122e507b6c5e1b2f4c31c604121
with:
app-id: ${{ secrets.MATHLIB_CROSSREFS_APP_ID }}
key-vault-name: ${{ vars.MATHLIB_AZ_KEY_VAULT_NAME }}
key-name: crossref-exports-app-pk
azure-client-id: ${{ vars.GH_APP_AZURE_CLIENT_ID_CROSSREFS }}
azure-tenant-id: ${{ secrets.LPC_AZ_TENANT_ID }}
owner: ${{ steps.repo.outputs.owner }}
repositories: ${{ steps.repo.outputs.name }}
- name: Push to the crossrefs repository
env:
CROSSREFS_PUSH_TOKEN: ${{ steps.app-token.outputs.token }}
# On manual runs this defaults to true (see the workflow_dispatch
# inputs); on the automatic workflow_run trigger `inputs` is empty, so
# this is false and the push happens for real.
DRY_RUN: ${{ inputs.dry_run || false }}
run: |
git clone --depth 1 \
"https://x-access-token:${CROSSREFS_PUSH_TOKEN}@github.com/${CROSSREFS_REPO}.git" \
crossrefs-repo
cd crossrefs-repo
git config user.name "leanprover-community-bot"
git config user.email "leanprover-community-bot@users.noreply.github.com"
# Commit only when the entries themselves change. The `generated`
# timestamp and source `commit` change on every run, so comparing the
# whole file would produce a commit even when nothing of substance did.
# Consequence: the published `generated`/`commit` fields record when the
# entries last changed, not the latest commit the export ran against, so
# consumers should not read `generated` as a "data freshness" signal.
# Read each file fully into a string and compare; using `diff -q` on two
# `jq` process substitutions makes `diff` close the pipes at the first
# difference, which leaves the `jq` writers with a SIGPIPE ("broken pipe")
# and noisy spurious errors in the log.
if [ -f crossrefs.json ] && \
[ "$(jq -Sc '.entries' crossrefs.json)" = "$(jq -Sc '.entries' ../crossrefs.json)" ]; then
echo "No change in entries."
changed=false
else
cp ../crossrefs.json crossrefs.json
git add crossrefs.json
git commit -m "Update crossrefs (mathlib4@${BUILT_SHA})"
changed=true
fi
if [ "${DRY_RUN}" = "true" ]; then
# Verify the minted token can actually push, without mutating the
# remote: `git push --dry-run` performs the authenticated
# git-receive-pack handshake (which GitHub gates on write access) but
# never sends the update. If nothing changed, add a throwaway local
# commit so there is a ref update to negotiate.
if [ "${changed}" != "true" ]; then
git commit --allow-empty -m "Dry-run push permission check (never sent)"
fi
echo "Dry run: verifying push permission against ${CROSSREFS_REPO} without pushing."
git push --dry-run
elif [ "${changed}" = "true" ]; then
git push
else
echo "No change in entries; nothing to commit."
fi
report_failure:
name: Report failure
needs: [export, publish]
if: failure()
runs-on: ubuntu-latest
steps:
- name: Post failure message on Zulip
uses: zulip/github-actions-zulip/send-message@f675f2b4eb2a95fae974215476dcb7ad8dfeff6b # v2.0.2
with:
api-key: ${{ secrets.ZULIP_API_KEY }}
email: 'github-mathlib4-bot@leanprover.zulipchat.com'
organization-url: 'https://leanprover.zulipchat.com'
to: 'nightly-testing-mathlib'
type: 'stream'
topic: 'crossrefs export failure'
content: |
❌ Cross-reference export [failed](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) on ${{ env.BUILT_SHA }}
[Dauer der Verarbeitung: 0.4 Sekunden, vorverarbeitet 2026-11-18]
|
2026-11-24
|