diff --git a/actions/licence/action.yml b/actions/licence/action.yml new file mode 100644 index 0000000..9d8108c --- /dev/null +++ b/actions/licence/action.yml @@ -0,0 +1,133 @@ +# Enforces the ONLYOFFICE licence notices with licence-modification-tooling +# (https://github.com/Euro-Office/licence-modification-tooling, public, so no +# secret is needed; pinned at tooling-ref). +# +# mode: gate (pull requests and pushes of a component repository) runs the +# header gates without --stamp. They fail on a changed upstream file without +# our block, a broken upstream header, a removed 7(b)/7(e) clause (a pick that +# brought back a file the licence PR removed), a changed licence file and a +# new file without the SPDX pair, with one annotation per file, and checks +# that MODIFICATIONS.txt is the tooling's note. Pin and bases come from the +# tooling's relicence.conf by repository name. Check out the +# repository with full history first: +# +# - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 +# with: +# fetch-depth: 0 +# persist-credentials: false +# - uses: Euro-Office/.github/actions/licence@main +# +# mode: record (DocumentServer and DesktopEditors releases) clones the listed +# submodules with full history, writes each one's full MODIFICATIONS.txt for +# its pinned commit (and the repository's own for ".", which needs +# fetch-depth: 0) and uploads them as the artifact "licence-records". The +# build jobs put them over the committed MODIFICATIONS.txt, which is only a +# short note pointing to the git history, so the packages ship the full +# records. +# +# SPDX-FileCopyrightText: 2026 Euro-Office contributors +# SPDX-License-Identifier: MIT + +name: Licence notices +description: Check the ONLYOFFICE licence notices, or regenerate the modification records of a release. + +inputs: + mode: + description: gate or record. + default: gate + submodules: + description: "record: the submodules to write a record for, separated by spaces (their paths, which are their names in the tooling's configs/); . is the repository itself." + default: "" + tooling-ref: + description: Commit of licence-modification-tooling to run. + default: 624f487e8852ed7b0a218709b5309cf5993225fd + +runs: + using: composite + steps: + - name: Check out licence-modification-tooling + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: Euro-Office/licence-modification-tooling + ref: ${{ inputs.tooling-ref }} + path: .licence-tooling + persist-credentials: false + + - name: Run + shell: bash + env: + MODE: ${{ inputs.mode }} + REPO: ${{ github.event.repository.name }} + SUBMODULES: ${{ inputs.submodules }} + run: | + set -euo pipefail + ws=$GITHUB_WORKSPACE + tool=$ws/.licence-tooling + # Python runs from the tooling directory, never from the checkout under test. + cd "$tool" + python3 -c 'import sys, tomllib; assert sys.version_info >= (3, 11)' || + { echo "::error::The licence gate needs Python 3.11 or later."; exit 2; } + case "$MODE" in + gate) + [[ "$(git -C "$ws" rev-parse --is-shallow-repository)" == false ]] || + { echo "::error::Check out with fetch-depth: 0: the gate reads the history and the upstream/* tags."; exit 2; } + line=$(awk -v r="$REPO" '$1 == r' relicence.conf) + [[ -n "$line" ]] || { echo "::error::$REPO is not in relicence.conf of licence-modification-tooling, so it has no pin and bases: add it there, or drop this workflow (server-private and other repositories outside the licence round)."; exit 2; } + read -r _ _ pin bases <<<"$line" + args=(--repo "$ws" --pin "$pin") + for b in $bases; do args+=(--base "$b"); done + status=0 + python3 -m modrecord.headers "${args[@]}" --github || status=$? + # The committed MODIFICATIONS.txt is the short note; releases ship the full record. + if [[ ! -f "$ws/MODIFICATIONS.txt" ]] || + ! python3 -m modrecord --repo "$ws" --config "configs/$REPO.conf" --note --check "$ws/MODIFICATIONS.txt"; then + echo "::error file=MODIFICATIONS.txt::MODIFICATIONS.txt is not the note. Write it with: python3 -m modrecord --repo --config configs/$REPO.conf --note -o /MODIFICATIONS.txt" + status=1 + fi + if (( status )); then + { + echo "### Licence notices" + echo "The gate failed, see the annotations. Locally, from a licence-modification-tooling checkout:" + echo '```' + echo "python3 -m modrecord.headers --repo ${args[*]:2} [--stamp]" + echo "python3 -m modrecord --repo --config configs/$REPO.conf --note -o /MODIFICATIONS.txt" + echo '```' + } >>"$GITHUB_STEP_SUMMARY" + fi + exit "$status" + ;; + record) + [[ -n "$SUBMODULES" ]] || { echo "::error::Set submodules for the record mode."; exit 2; } + for s in $SUBMODULES; do + if [[ "$s" == . ]]; then + name=$REPO dir=$ws + else + name=$s dir=$ws/$s + # A full clone: the record reads the whole history and the upstream/* tags. + git -C "$ws" submodule update --init -- "$s" + fi + [[ "$(git -C "$dir" rev-parse --is-shallow-repository)" == false ]] || + { echo "::error::$s is a shallow clone: check out with fetch-depth: 0 and without submodules."; exit 2; } + [[ -f "configs/$name.conf" ]] || { echo "::error::No record config configs/$name.conf."; exit 2; } + python3 -m modrecord --repo "$dir" --config "configs/$name.conf" --ref HEAD -o "$dir/MODIFICATIONS.txt" + # A release must ship the full record, never the committed note. + ! grep -q '^git history: ' "$dir/MODIFICATIONS.txt" || + { echo "::error::$name: MODIFICATIONS.txt is still the note, not the full record."; exit 1; } + echo "$name: record written for $(git -C "$dir" rev-parse HEAD)" + done + ;; + *) + echo "::error::Unknown mode $MODE (gate or record)." + exit 2 + ;; + esac + + - name: Upload the records + if: inputs.mode == 'record' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: licence-records + path: | + MODIFICATIONS.txt + */MODIFICATIONS.txt + if-no-files-found: error diff --git a/workflow-templates/licence.properties.json b/workflow-templates/licence.properties.json new file mode 100644 index 0000000..00e701b --- /dev/null +++ b/workflow-templates/licence.properties.json @@ -0,0 +1,6 @@ +{ + "name": "Licence notices", + "description": "Check the ONLYOFFICE licence notices with the header gates of licence-modification-tooling.", + "iconName": "octicon law", + "filePatterns": [".*"] +} diff --git a/workflow-templates/licence.yml b/workflow-templates/licence.yml new file mode 100644 index 0000000..145effb --- /dev/null +++ b/workflow-templates/licence.yml @@ -0,0 +1,41 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/Euro-Office/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# Checks the ONLYOFFICE licence notices (upstream headers, our block on +# upstream files we changed, the SPDX pair on new files, the licence files) +# with the header gates of licence-modification-tooling, on pull requests to +# and pushes of the default branch only (older stable branches predate the +# notices), forks included. Only for the component repositories listed in its +# relicence.conf. +# Details: +# https://github.com/Euro-Office/.github/blob/main/actions/licence/action.yml +# +# SPDX-FileCopyrightText: 2026 Euro-Office contributors +# SPDX-License-Identifier: MIT + +name: Licence notices + +on: + pull_request: + branches: [$default-branch] + push: + branches: [$default-branch] + +permissions: + contents: read + +concurrency: + group: licence-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + licence: + runs-on: [self-hosted, ubuntu-latest] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + - uses: Euro-Office/.github/actions/licence@main # zizmor: ignore[unpinned-uses] organization action, pins the tooling itself