Skip to content

Commit e3d5fdc

Browse files
authored
Fix: sync issue triage labels, skip unchanged labels and add CI (#8)
## Checklist before requesting a review - [x] I have performed a self-review of my code. ## Description - It fixes #N/A - `label-commenter-config.yml` acts on the `invalid`, `support` and `feature suggestion` labels, but nothing created them, so labelling an issue in a repository lacking them was impossible. - `sync/labels.json` now defines them: `invalid` keeps the GitHub default, `support` and `feature suggestion` use the colors of pluginsGLPI/fields. - The label comparison always failed because `gh --jq` sorts keys and returns a null empty description, so every run updated every label of every repository; both sides are now normalized and unchanged labels are skipped. - A new `ci.yml` workflow lints every workflow (including the synced ones) with actionlint, `sync.sh` with shellcheck and validates `sync/*.json`; on pull requests it also runs `sync.sh` in dry run with a read-only app token, so the changes it would apply to every synced repository are visible before merge.
1 parent 91071fe commit e3d5fdc

7 files changed

Lines changed: 173 additions & 9 deletions

File tree

‎.github/scripts/sync.sh‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ while read -r repo; do
5454
repo_dir="$work_dir/$name"
5555

5656
repo_json="$(gh api "repos/$repo")"
57+
# Merge settings are hidden from tokens without contents write, such as the read-only pull request dry run token: settings missing from the response count as applied
58+
if [[ "$dry_run" == "true" && "$(jq '.allow_merge_commit == null' <<< "$repo_json")" == "true" ]]; then
59+
if [[ -z "${hidden_settings_reported:-}" ]]; then
60+
echo "merge settings not visible with a read-only token, skipped"
61+
hidden_settings_reported="true"
62+
fi
63+
repo_json="$(jq --slurpfile wanted "$settings_file" '$wanted[0] + with_entries(select(.value != null))' <<< "$repo_json")"
64+
fi
5765
# The API rejects a commit title or message sent without its counterpart
5866
settings_diff="$(jq -c --slurpfile wanted "$settings_file" '
5967
. as $current | $wanted[0] as $wanted
@@ -129,10 +137,10 @@ while read -r repo; do
129137
continue
130138
fi
131139

132-
# Label names are case insensitive, extra labels of the repository are kept
133-
current_labels="$(gh api "repos/$repo/labels?per_page=100" --paginate --jq '.[] | {name, color, description}' | jq -s .)"
140+
# Label names are case insensitive, extra labels of the repository are kept; keys are sorted and a null description is empty so unchanged labels compare equal
141+
current_labels="$(gh api "repos/$repo/labels?per_page=100" --paginate --jq '.[] | {name, color, description: (.description // "")}' | jq -s .)"
134142
while read -r label; do
135-
current_label="$(jq -c --argjson label "$label" 'map(select((.name | ascii_downcase) == ($label.name | ascii_downcase)))[0] // empty' <<< "$current_labels")"
143+
current_label="$(jq -cS --argjson label "$label" 'map(select((.name | ascii_downcase) == ($label.name | ascii_downcase)))[0] // empty' <<< "$current_labels")"
136144
if [[ -z "$current_label" ]]; then
137145
method="POST" url="repos/$repo/labels" action="created" body="$label"
138146
elif [[ "$current_label" != "$label" ]]; then
@@ -147,7 +155,7 @@ while read -r repo; do
147155
gh api --method "$method" "$url" --input - --silent <<< "$body"
148156
echo "$repo: label $action: $label"
149157
fi
150-
done < <(jq -c '.[] | {name, color, description}' "$labels_file")
158+
done < <(jq -cS '.[] | {name, color, description: (.description // "")}' "$labels_file")
151159

152160
git clone --quiet --depth 1 "https://x-access-token:${GH_TOKEN}@github.com/${repo}.git" "$repo_dir"
153161
default_branch="$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD)"

‎.github/workflows/ci.yml‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "Continuous integration"
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
9+
concurrency:
10+
group: "${{ github.workflow }}-${{ github.ref }}"
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: "read"
15+
16+
jobs:
17+
lint:
18+
name: "Lint"
19+
runs-on: "ubuntu-latest"
20+
steps:
21+
- name: "Checkout"
22+
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
23+
with:
24+
persist-credentials: false
25+
- name: "Lint workflows"
26+
# Synced workflows are not under .github/workflows, so they are listed explicitly
27+
run: |
28+
docker run --rm --volume "$PWD:/repo" --workdir /repo \
29+
rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 \
30+
-color .github/workflows/*.yml sync/files/.github/workflows/*.yml sync/files-public/.github/workflows/*.yml
31+
- name: "Lint shell scripts"
32+
run: |
33+
docker run --rm --volume "$PWD:/mnt" --workdir /mnt \
34+
koalaman/shellcheck@sha256:61862eba1fcf09a484ebcc6feea46f1782532571a34ed51fedf90dd25f925a8d \
35+
.github/scripts/*.sh
36+
- name: "Validate JSON files"
37+
run: |
38+
for file in sync/*.json; do
39+
jq empty "$file"
40+
done
41+
42+
sync-dry-run:
43+
name: "Sync dry run"
44+
# Fork and Dependabot pull requests get no access to the app secret
45+
if: >-
46+
github.event_name == 'pull_request'
47+
&& github.event.pull_request.head.repo.full_name == github.repository
48+
&& github.actor != 'dependabot[bot]'
49+
runs-on: "ubuntu-latest"
50+
steps:
51+
- name: "Checkout"
52+
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
53+
with:
54+
persist-credentials: false
55+
- name: "Generate read-only app token"
56+
id: "app-token"
57+
uses: "actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510" # v3.3.0
58+
with:
59+
client-id: "${{ vars.SYNC_APP_CLIENT_ID }}"
60+
private-key: "${{ secrets.SYNC_APP_PRIVATE_KEY }}"
61+
owner: "${{ github.repository_owner }}"
62+
# The pull request runs unreviewed code, read access keeps it from writing to the synced repositories
63+
permission-administration: "read"
64+
permission-contents: "read"
65+
permission-pull-requests: "read"
66+
- name: "Show sync changes"
67+
run: ".github/scripts/sync.sh"
68+
env:
69+
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
70+
DRY_RUN: "true"

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Default community health files (issue and pull request templates, security polic
77
Files in `sync/files/` are pushed through a pull request to every non archived repository of the organization tagged with the `sync-org-files` topic; paths listed in `sync/delete.txt` are removed from them.
88
Files in `sync/files-public/` are pushed the same way to public repositories only, and removed from private ones.
99
After each successful run of the automatic tag workflow, the synced `open-xml-update-pr.yml` workflow opens a pull request copying the `<version>` block of the matching tag's plugin XML (`plugin.xml` or `<plugin_key>.xml`) to the default branch, with the `GLPI_PROJECT_BOT` GitHub App, which needs the pull requests write permission.
10+
Issues labelled `need feedback` are closed by the stale workflow after 44 days without activity; the synced `need-feedback.yml` workflow removes the label when the issue author comments.
1011
Repository settings in `sync/settings.json` (any field of the [update a repository](https://docs.github.com/rest/repos/repos#update-a-repository) API) are applied directly to the same repositories, along with release immutability, Dependabot alerts and security updates, and private vulnerability reporting, secret scanning and push protection (public repositories only).
1112
The protection of the default branch and of `X.Y/bugfixes` branches is aligned on `sync/branch-protection.json` (body of the [update branch protection](https://docs.github.com/rest/branches/branch-protection#update-branch-protection) API).
1213
Labels in `sync/labels.json` (`name`, `color` and `description`) are created, or updated when their color or description differs; other labels of the repositories are kept.

‎sync/files-public/.github/label-commenter-config.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,30 @@ labels:
1212
This issue has been closed as we only track bugs here.
1313
1414
You can get community support on [forums](https://forum.glpi-project.org/) or you can consider [taking a subscription](https://glpi-project.org/subscriptions/) to get professional support.
15-
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly.
15+
You can also [contact GLPI editor team](https://glpi-project.org/contact_us/) directly.
1616
action: "close"
1717
- name: "feature suggestion"
1818
labeled:
1919
issue:
2020
body: |
2121
This issue has been closed as we only track bugs here.
2222
23-
You can open a topic to discuss with community about this enhancement on [suggestion website](https://glpi.userecho.com/).
24-
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly if you are willing to sponsor this feature.
23+
You can open a topic to discuss with community about this enhancement on [suggestion website](https://suggest.glpi-project.org).
24+
You can also [contact GLPI editor team](https://glpi-project.org/contact_us/) directly if you are willing to sponsor this feature.
25+
action: "close"
26+
- name: "not reproducible"
27+
labeled:
28+
issue:
29+
body: |
30+
This issue has been closed because we could not reproduce it on the latest release.
31+
32+
Feel free to reopen it with the exact steps to reproduce it on the latest release.
33+
action: "close"
34+
- name: "security report"
35+
labeled:
36+
issue:
37+
body: |
38+
This issue has been closed because security problems must not be reported publicly.
39+
40+
Please edit it to remove the vulnerability details, then report it privately as described in our [security policy](https://github.com/pluginsGLPI/.github/blob/main/SECURITY.md).
2541
action: "close"

‎sync/files/.github/workflows/close_stale_issue.yml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
pull-requests: "write" # for actions/stale to close stale pull requests
1313
runs-on: "ubuntu-latest"
1414
steps:
15-
- uses: "actions/stale@v11"
15+
- uses: "actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93" # v11.0.0
1616
with:
1717
stale-issue-message: >-
1818
There has been no activity on this issue for 60 days and therefore it is considered stale
@@ -28,9 +28,25 @@ jobs:
2828
days-before-issue-stale: 60
2929
days-before-pr-stale: 90
3030
days-before-close: 14
31-
exempt-issue-labels: "bug,enhancement,question,security" # Issues with "bug", "enhancement", "question" or "security" labels will not be marked as stale
31+
exempt-issue-labels: "bug,enhancement,question,security,need feedback" # Issues with "bug", "enhancement", "question" or "security" labels will not be marked as stale, "need feedback" ones are handled by the next step
3232
exempt-pr-labels: "security" # PR with "security" label will not be marked as stale
3333
exempt-draft-pr: true # Draft PR are work in progress.
3434
exempt-all-milestones: true # Do not check issues/PR with defined milestone.
3535
ascending: true # First check older issues/PR.
3636
operations-per-run: 750 # Max API calls per run.
37+
# Shares the "_state" cache of the step above, harmless as long as each run processes every issue
38+
- uses: "actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93" # v11.0.0
39+
with:
40+
only-labels: "need feedback"
41+
stale-issue-message: >-
42+
The requested information has not been provided for 30 days,
43+
this issue will be closed automatically in 14 days.
44+
close-issue-message: >-
45+
This issue has been closed because the requested information has not been provided.
46+
Feel free to reopen it with the requested information.
47+
days-before-issue-stale: 30
48+
days-before-issue-close: 14
49+
days-before-pr-stale: -1
50+
days-before-pr-close: -1
51+
ascending: true
52+
operations-per-run: 750
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Need feedback"
2+
3+
on:
4+
issue_comment:
5+
types:
6+
- "created"
7+
8+
jobs:
9+
answered:
10+
if: >-
11+
github.repository == 'pluginsGLPI/{PLUGIN}'
12+
&& github.event.comment.user.login == github.event.issue.user.login
13+
&& contains(github.event.issue.labels.*.name, 'need feedback')
14+
permissions:
15+
issues: "write"
16+
runs-on: "ubuntu-latest"
17+
steps:
18+
- name: "Remove the need feedback label"
19+
env:
20+
GH_TOKEN: "${{ github.token }}"
21+
GH_REPO: "${{ github.repository }}"
22+
ISSUE_NUMBER: "${{ github.event.issue.number }}"
23+
run: gh issue edit "$ISSUE_NUMBER" --remove-label "need feedback"

‎sync/labels.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,35 @@
33
"name": "no forward-port",
44
"color": "cfd3d7",
55
"description": "Do not forward-port this pull request to the next branch"
6+
},
7+
{
8+
"name": "invalid",
9+
"color": "e4e669",
10+
"description": "This doesn't seem right"
11+
},
12+
{
13+
"name": "support",
14+
"color": "06ECC1",
15+
"description": ""
16+
},
17+
{
18+
"name": "feature suggestion",
19+
"color": "0E8A16",
20+
"description": ""
21+
},
22+
{
23+
"name": "need feedback",
24+
"color": "fef2c0",
25+
"description": "Waiting for information from the issue author"
26+
},
27+
{
28+
"name": "not reproducible",
29+
"color": "c5def5",
30+
"description": "Could not be reproduced on the latest release"
31+
},
32+
{
33+
"name": "security report",
34+
"color": "b60205",
35+
"description": "Security problem reported publicly instead of privately"
636
}
737
]

0 commit comments

Comments
 (0)