Skip to content
Open
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.rs]
end_of_line = crlf

[*.yaml]
end_of_line = crlf
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.rs text eol=crlf
*.yaml text eol=crlf
7 changes: 7 additions & 0 deletions .github/translator-alert.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Add your GitHub username (including '@') to the 'notify' list to receive alerts when English rules change.
# Append to the existing list on the same line, separated by a single space (e.g. notify=@user1 @user2).
# You do not have to add your Github username if you are already in the mathcat-translators group.

paths=Rules/Languages/en/
exclude=Rules/Languages/en/gb/
notify=@johannes-spsm @daisy/mathcat-translators
119 changes: 119 additions & 0 deletions .github/workflows/library-size-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Library Size Comment

on:
workflow_run:
workflows: [Library Size]
types: [completed]

permissions:
actions: read
pull-requests: write

concurrency:
group: library-size-comment-${{ github.event.workflow_run.head_repository.id }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false

jobs:
comment:
name: Update PR comment
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-24.04
steps:
- name: Download measurements
uses: actions/download-artifact@v8
with:
name: library-size-report
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ runner.temp }}/mathcat-size-report

# This job never checks out or executes PR code. Treat the downloaded report as untrusted.
- name: Update size comment
uses: actions/github-script@v9
env:
REPORT_PATH: ${{ runner.temp }}/mathcat-size-report/report.json
with:
script: |
const fs = require('fs');
const run = context.payload.workflow_run;
const {owner, repo} = context.repo;
const marker = '<!-- mathcat-library-size -->';

// Read and validate the artifact from the untrusted PR build.
function readReport() {
const report = JSON.parse(fs.readFileSync(process.env.REPORT_PATH, 'utf8'));
const shaPattern = /^[0-9a-f]{40}$/i;
if (!Number.isSafeInteger(report.prNumber) || report.prNumber <= 0 ||
!shaPattern.test(report.baseSha) || !shaPattern.test(report.headSha) ||
!Number.isSafeInteger(report.baseBytes) || report.baseBytes <= 0 ||
!Number.isSafeInteger(report.headBytes) || report.headBytes <= 0) {
throw new Error('Invalid library size report');
}
return report;
}

// Only report measurements for the current PR and source branch.
async function matchesCurrentPull(report) {
const {data: pull} = await github.rest.pulls.get({
owner, repo, pull_number: report.prNumber,
});
if (pull.state !== 'open' || pull.base.sha !== report.baseSha ||
pull.head.sha !== report.headSha) {
core.notice('PR revisions changed or PR closed; ignoring stale measurements');
return false;
}
if (run.head_repository?.id !== pull.head.repo?.id ||
run.head_branch !== pull.head.ref ||
(run.pull_requests?.length > 0 &&
!run.pull_requests.some(pr => pr.number === report.prNumber))) {
throw new Error('Report does not belong to the triggering PR branch');
}
return true;
}

// The summary is the entire collapsed view; the table is shown on expansion.
function renderComment(report) {
const mib = bytes => `${(bytes / 1048576).toFixed(2)} MiB`;
const size = bytes => `${mib(bytes)} (${bytes.toLocaleString('en-US')} bytes)`;
const delta = report.headBytes - report.baseBytes;
const percent = `${delta > 0 ? '+' : ''}${(100 * delta / report.baseBytes).toFixed(2)}%`;
return [
marker,
'<details>',
`<summary>Linux library size: ${mib(report.headBytes)} (${percent})</summary>`,
'',
'| Revision | Release `liblibmathcat.so` |',
'| --- | ---: |',
`| Base (${report.baseSha.slice(0, 7)}) | ${size(report.baseBytes)} |`,
`| PR (${report.headSha.slice(0, 7)}) | ${size(report.headBytes)} |`,
`| Change | ${delta > 0 ? '+' : ''}${delta.toLocaleString('en-US')} bytes (${percent}) |`,
'',
`Built with default features, Rust 1.96.0, and Ubuntu 24.04. [Workflow run](${run.html_url}).`,
'</details>',
].join('\n');
}

// Reuse the bot's marked comment instead of posting on every run.
async function upsertComment(prNumber, body) {
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number: prNumber, per_page: 100,
});
const previous = comments.find(comment =>
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker));
if (previous) {
if (previous.body !== body) {
await github.rest.issues.updateComment({
owner, repo, comment_id: previous.id, body,
});
}
} else {
await github.rest.issues.createComment({
owner, repo, issue_number: prNumber, body,
});
}
}

const report = readReport();
if (await matchesCurrentPull(report)) {
await upsertComment(report.prNumber, renderComment(report));
}
83 changes: 83 additions & 0 deletions .github/workflows/library-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Library Size

on: pull_request

permissions:
contents: read

concurrency:
group: library-size-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
measure:
name: Measure Linux shared library
runs-on: ubuntu-24.04
steps:
- name: Check out base revision
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
persist-credentials: false

- name: Check out PR revision
uses: actions/checkout@v5
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: head
persist-credentials: false

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.96.0

- name: Build base library
id: base
working-directory: base
env:
CARGO_TARGET_DIR: ${{ runner.temp }}/mathcat-size-base-target
run: |
cargo build --release --lib --locked
bytes=$(stat -c%s "$CARGO_TARGET_DIR/release/liblibmathcat.so")
echo "bytes=$bytes" >> "$GITHUB_OUTPUT"

- name: Build PR library
id: head
working-directory: head
env:
CARGO_TARGET_DIR: ${{ runner.temp }}/mathcat-size-head-target
run: |
cargo build --release --lib --locked
bytes=$(stat -c%s "$CARGO_TARGET_DIR/release/liblibmathcat.so")
echo "bytes=$bytes" >> "$GITHUB_OUTPUT"

- name: Save measurements
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_BYTES: ${{ steps.base.outputs.bytes }}
HEAD_BYTES: ${{ steps.head.outputs.bytes }}
REPORT_DIR: ${{ runner.temp }}/mathcat-size-report
run: |
mkdir -p "$REPORT_DIR"
node - <<'NODE'
const fs = require('fs');
const path = require('path');
const report = {
prNumber: Number(process.env.PR_NUMBER),
baseSha: process.env.BASE_SHA,
headSha: process.env.HEAD_SHA,
baseBytes: Number(process.env.BASE_BYTES),
headBytes: Number(process.env.HEAD_BYTES),
};
fs.writeFileSync(path.join(process.env.REPORT_DIR, 'report.json'), JSON.stringify(report));
NODE

- name: Upload measurements
uses: actions/upload-artifact@v7
with:
name: library-size-report
path: ${{ runner.temp }}/mathcat-size-report/report.json
retention-days: 1
55 changes: 47 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,59 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Remove empty Rules directories
run: find Rules -type d -empty -delete
- name: Remove test directory
run: rm -r Rules/Languages/zz
- name: create Rules.zip
run: zip -r Rules.zip Rules
- uses: dtolnay/rust-toolchain@stable
- name: Create Rules.zip
run: cargo run --bin package-rules -- Rules Rules.zip
- name: Create Rules-minimized.zip
run: cargo run --bin package-rules -- Rules Rules-minimized.zip --minimize
- name: Upload Rules.zip
uses: actions/upload-artifact@v7
with:
name: 'Rules.zip'
path: 'Rules.zip'
compression-level: 0
retention-days: 1
- name: Upload Rules-minimized.zip
uses: actions/upload-artifact@v7
with:
name: 'Rules-minimized.zip'
path: 'Rules-minimized.zip'
compression-level: 0
retention-days: 1

test-rules-package:
name: Test (${{ matrix.feature_name }}, ${{ matrix.rules_zip }})
needs: zip-rules
strategy:
fail-fast: false
matrix:
rules_zip: [Rules.zip, Rules-minimized.zip]
include:
- feature_name: default
features: ""
- feature_name: no-unsafe
features: "--features no-unsafe"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download ${{ matrix.rules_zip }}
uses: actions/download-artifact@v8
with:
name: ${{ matrix.rules_zip }}
- name: Install packaged Rules
run: |
rm -rf Rules
unzip -q "${{ matrix.rules_zip }}"
# Release zips omit the synthetic zz test language; restore it for unit tests only.
git checkout HEAD -- Rules/Languages/zz
- name: Run tests (${{ matrix.feature_name }})
run: cargo test ${{ matrix.features }} --verbose

pre-release:
name: Pre Release
continue-on-error: false
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # otherwise, job fails on pull requests, as GITHUB_TOKEN is not available
needs: [build, clippy, zip-rules]
needs: [build, clippy, zip-rules, test-rules-package]
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -73,6 +107,10 @@ jobs:
uses: actions/download-artifact@v8
with:
name: Rules.zip
- name: download Rules-minimized.zip
uses: actions/download-artifact@v8
with:
name: Rules-minimized.zip
# Moving 'latest' prerelease (replaces marvinpinto/action-automatic-releases)
- name: Development Build release
env:
Expand All @@ -90,4 +128,5 @@ jobs:
--latest=false \
--title "Development Build" \
--notes "Development build from ${SHA}" \
Rules.zip
Rules.zip \
Rules-minimized.zip
Loading
Loading