Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Labeling: pinned actions, minimal permissions, only existing labels, label once

KnifeLemond3b248623e75
diff --git a/.github/labeler.yml b/.github/labeler.yml
index ff8c3074..220c9ba6 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -1,25 +1,16 @@
+# Labels .github/workflows/label-pr.yml adds to a new pull request by the files it changes. Only the sure cases: a pull
+# request that changes nothing but these files. The release notes (.github/release.yml) sort pull requests by their
+# labels, so a new format or a fix in the engines is labeled by hand. Every label here must exist in the repository.
build:
- changed-files:
- - any-glob-to-any-file:
- - build/**
- - installer/**
- - global.json
-
-ci:
- - changed-files:
- - any-glob-to-any-file:
- - .github/workflows/**
+ - all-globs-to-all-files:
+ - "{build/**,installer/**,.github/**,global.json,Directory.Packages.props}"
documentation:
- changed-files:
- all-globs-to-all-files:
- "{docs/**,**/*.md}"
-formats:
- - changed-files:
- - any-glob-to-any-file:
- - src/Filee.Engines/**
-
translation:
- changed-files:
- all-globs-to-all-files:
diff --git a/.github/workflows/label-issue.yml b/.github/workflows/label-issue.yml
index ab5302fd..7a9b3bac 100644
--- a/.github/workflows/label-issue.yml
+++ b/.github/workflows/label-issue.yml
@@ -1,21 +1,25 @@
name: Label issues
+# Labels a new issue by keywords in its title, unless it already has labels (the issue templates add their own). Only
+# when it is opened, and labels are only added. The title is read from the event payload, never put into the script.
on:
issues:
types: [opened]
-permissions:
- issues: write
+permissions: {}
jobs:
label:
runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions:
+ issues: write # add labels
steps:
- - uses: actions/github-script@v9
+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const issue = context.payload.issue;
- if (issue.labels.length) return; // already labeled, e.g. by an issue form
+ if (issue.labels.length) return;
const title = issue.title.toLowerCase();
const rules = [
@@ -25,10 +29,17 @@ jobs:
[/\b(docs?|documentation|readme|typo)\b/, 'documentation'],
[/\b(translation|translate|localization|localisation|i18n|l10n)\b/, 'translation'],
[/\b(accessibility|a11y|screen reader|high contrast|narrator|nvda)\b/, 'accessibility'],
- [/\b(installer|msix)\b/, 'build'],
- [/\?\s*$|^(how|why|what|can|is|does)\b/, 'question'],
+ [/\b(installer|setup)\b/, 'build'],
+ [/\?\s*$|^(how|why)\b/, 'question'],
];
- const labels = rules.filter(([re]) => re.test(title)).map(([, label]) => label);
+ // Only labels the repository has: adding an unknown name would create a new label.
+ const known = new Set((await github.paginate(github.rest.issues.listLabelsForRepo, {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ per_page: 100,
+ })).map(label => label.name));
+ const labels = rules.filter(([re]) => re.test(title)).map(([, label]) => label)
+ .filter(label => known.has(label));
if (labels.length) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml
index 86b5bdfb..a171f01d 100644
--- a/.github/workflows/label-pr.yml
+++ b/.github/workflows/label-pr.yml
@@ -1,39 +1,55 @@
name: Label pull requests
+# Labels a new pull request by the files it changes (.github/labeler.yml) and by a Conventional Commits title
+# ("feat: ...", "fix(hwp): ..."). Only when it is opened, and labels are only added: labels changed by hand later stay.
+#
+# pull_request_target runs in this repository with a token that can add labels, also for pull requests from forks. It
+# must never check out or run the pull request's code: labeler reads .github/labeler.yml from the base branch and the
+# changed file names through the API, and the title is read from the event payload, never put into the script.
on:
pull_request_target:
- types: [opened, reopened, synchronize, edited]
+ types: [opened]
-permissions:
- contents: read
- pull-requests: write
+permissions: {}
jobs:
label:
runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions:
+ contents: read # .github/labeler.yml of the base branch
+ pull-requests: write # add labels
steps:
- # By changed files, using .github/labeler.yml. Labels are only added, never removed.
- - uses: actions/labeler@v6
+ - uses: actions/labeler@bf12e9b00b37c5c0ca2b87b79b2daf7891dbda13 # v7.0.0
+ with:
+ sync-labels: false
- # By title prefix: "feat: ...", "fix: ...", "docs: ...", "ci: ...".
- - uses: actions/github-script@v9
+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
- const title = context.payload.pull_request.title.toLowerCase();
+ const pull = context.payload.pull_request;
+ const title = pull.title.toLowerCase();
const rules = [
[/^feat(\(.+\))?!?:/, 'feature'],
[/^fix(\(.+\))?!?:/, 'bug'],
[/^docs(\(.+\))?!?:/, 'documentation'],
- [/^ci(\(.+\))?!?:/, 'ci'],
- [/^build(\(.+\))?!?:/, 'build'],
+ [/^(build|ci)(\(.+\))?!?:/, 'build'],
[/^(i18n|l10n)(\(.+\))?!?:/, 'translation'],
];
- const labels = rules.filter(([re]) => re.test(title)).map(([, label]) => label);
+ // Only labels the repository has: adding an unknown name would create a new label.
+ const known = new Set((await github.paginate(github.rest.issues.listLabelsForRepo, {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ per_page: 100,
+ })).map(label => label.name));
+ const current = new Set(pull.labels.map(label => label.name));
+ const labels = rules.filter(([re]) => re.test(title)).map(([, label]) => label)
+ .filter(label => known.has(label) && !current.has(label));
if (labels.length) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
- issue_number: context.payload.pull_request.number,
+ issue_number: pull.number,
labels,
});
}