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
16 changes: 12 additions & 4 deletions .github/scripts/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ while read -r repo; do
repo_dir="$work_dir/$name"

repo_json="$(gh api "repos/$repo")"
# 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
if [[ "$dry_run" == "true" && "$(jq '.allow_merge_commit == null' <<< "$repo_json")" == "true" ]]; then
if [[ -z "${hidden_settings_reported:-}" ]]; then
echo "merge settings not visible with a read-only token, skipped"
hidden_settings_reported="true"
fi
repo_json="$(jq --slurpfile wanted "$settings_file" '$wanted[0] + with_entries(select(.value != null))' <<< "$repo_json")"
fi
# The API rejects a commit title or message sent without its counterpart
settings_diff="$(jq -c --slurpfile wanted "$settings_file" '
. as $current | $wanted[0] as $wanted
Expand Down Expand Up @@ -129,10 +137,10 @@ while read -r repo; do
continue
fi

# Label names are case insensitive, extra labels of the repository are kept
current_labels="$(gh api "repos/$repo/labels?per_page=100" --paginate --jq '.[] | {name, color, description}' | jq -s .)"
# 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
current_labels="$(gh api "repos/$repo/labels?per_page=100" --paginate --jq '.[] | {name, color, description: (.description // "")}' | jq -s .)"
while read -r label; do
current_label="$(jq -c --argjson label "$label" 'map(select((.name | ascii_downcase) == ($label.name | ascii_downcase)))[0] // empty' <<< "$current_labels")"
current_label="$(jq -cS --argjson label "$label" 'map(select((.name | ascii_downcase) == ($label.name | ascii_downcase)))[0] // empty' <<< "$current_labels")"
if [[ -z "$current_label" ]]; then
method="POST" url="repos/$repo/labels" action="created" body="$label"
elif [[ "$current_label" != "$label" ]]; then
Expand All @@ -147,7 +155,7 @@ while read -r repo; do
gh api --method "$method" "$url" --input - --silent <<< "$body"
echo "$repo: label $action: $label"
fi
done < <(jq -c '.[] | {name, color, description}' "$labels_file")
done < <(jq -cS '.[] | {name, color, description: (.description // "")}' "$labels_file")

git clone --quiet --depth 1 "https://x-access-token:${GH_TOKEN}@github.com/${repo}.git" "$repo_dir"
default_branch="$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD)"
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Continuous integration"

on:
push:
branches:
- "main"
pull_request:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

permissions:
contents: "read"

jobs:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
with:
persist-credentials: false
- name: "Lint workflows"
# Synced workflows are not under .github/workflows, so they are listed explicitly
run: |
docker run --rm --volume "$PWD:/repo" --workdir /repo \
rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 \
-color .github/workflows/*.yml sync/files/.github/workflows/*.yml sync/files-public/.github/workflows/*.yml
- name: "Lint shell scripts"
run: |
docker run --rm --volume "$PWD:/mnt" --workdir /mnt \
koalaman/shellcheck@sha256:61862eba1fcf09a484ebcc6feea46f1782532571a34ed51fedf90dd25f925a8d \
.github/scripts/*.sh
- name: "Validate JSON files"
run: |
for file in sync/*.json; do
jq empty "$file"
done

sync-dry-run:
name: "Sync dry run"
# Fork pull requests get no secrets
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
with:
persist-credentials: false
- name: "Generate read-only app token"
id: "app-token"
uses: "actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510" # v3.3.0
with:
client-id: "${{ vars.SYNC_APP_CLIENT_ID }}"
private-key: "${{ secrets.SYNC_APP_PRIVATE_KEY }}"
owner: "${{ github.repository_owner }}"
# The pull request runs unreviewed code, read access keeps it from writing to the synced repositories
permission-administration: "read"
permission-contents: "read"
permission-pull-requests: "read"
- name: "Show sync changes"
run: ".github/scripts/sync.sh"
env:
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
DRY_RUN: "true"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Default community health files (issue and pull request templates, security polic
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.
Files in `sync/files-public/` are pushed the same way to public repositories only, and removed from private ones.
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.
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.
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).
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).
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.
Expand Down
22 changes: 19 additions & 3 deletions sync/files-public/.github/label-commenter-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@ labels:
This issue has been closed as we only track bugs here.

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.
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly.
You can also [contact GLPI editor team](https://glpi-project.org/contact_us/) directly.
action: "close"
- name: "feature suggestion"
labeled:
issue:
body: |
This issue has been closed as we only track bugs here.

You can open a topic to discuss with community about this enhancement on [suggestion website](https://glpi.userecho.com/).
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly if you are willing to sponsor this feature.
You can open a topic to discuss with community about this enhancement on [suggestion website](https://suggest.glpi-project.org).
You can also [contact GLPI editor team](https://glpi-project.org/contact_us/) directly if you are willing to sponsor this feature.
action: "close"
- name: "not reproducible"
labeled:
issue:
body: |
This issue has been closed because we could not reproduce it on the latest release.

Feel free to reopen it with the exact steps to reproduce it on the latest release.
action: "close"
- name: "security report"
labeled:
issue:
body: |
This issue has been closed because security problems must not be reported publicly.

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).
action: "close"
20 changes: 18 additions & 2 deletions sync/files/.github/workflows/close_stale_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
pull-requests: "write" # for actions/stale to close stale pull requests
runs-on: "ubuntu-latest"
steps:
- uses: "actions/stale@v11"
- uses: "actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93" # v11.0.0
with:
stale-issue-message: >-
There has been no activity on this issue for 60 days and therefore it is considered stale
Expand All @@ -28,9 +28,25 @@ jobs:
days-before-issue-stale: 60
days-before-pr-stale: 90
days-before-close: 14
exempt-issue-labels: "bug,enhancement,question,security" # Issues with "bug", "enhancement", "question" or "security" labels will not be marked as stale
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
exempt-pr-labels: "security" # PR with "security" label will not be marked as stale
exempt-draft-pr: true # Draft PR are work in progress.
exempt-all-milestones: true # Do not check issues/PR with defined milestone.
ascending: true # First check older issues/PR.
operations-per-run: 750 # Max API calls per run.
# Shares the "_state" cache of the step above, harmless as long as each run processes every issue
- uses: "actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93" # v11.0.0
with:
only-labels: "need feedback"
stale-issue-message: >-
The requested information has not been provided for 30 days,
this issue will be closed automatically in 14 days.
close-issue-message: >-
This issue has been closed because the requested information has not been provided.
Feel free to reopen it with the requested information.
days-before-issue-stale: 30
days-before-issue-close: 14
days-before-pr-stale: -1
days-before-pr-close: -1
ascending: true
operations-per-run: 750
23 changes: 23 additions & 0 deletions sync/files/.github/workflows/need-feedback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Need feedback"

on:
issue_comment:
types:
- "created"

jobs:
answered:
if: >-
github.repository == 'pluginsGLPI/{PLUGIN}'
&& github.event.comment.user.login == github.event.issue.user.login
&& contains(github.event.issue.labels.*.name, 'need feedback')
permissions:
issues: "write"
runs-on: "ubuntu-latest"
steps:
- name: "Remove the need feedback label"
env:
GH_TOKEN: "${{ github.token }}"
GH_REPO: "${{ github.repository }}"
ISSUE_NUMBER: "${{ github.event.issue.number }}"
run: gh issue edit "$ISSUE_NUMBER" --remove-label "need feedback"
30 changes: 30 additions & 0 deletions sync/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,35 @@
"name": "no forward-port",
"color": "cfd3d7",
"description": "Do not forward-port this pull request to the next branch"
},
{
"name": "invalid",
"color": "e4e669",
"description": "This doesn't seem right"
},
{
"name": "support",
"color": "06ECC1",
"description": ""
},
{
"name": "feature suggestion",
"color": "0E8A16",
"description": ""
},
{
"name": "need feedback",
"color": "fef2c0",
"description": "Waiting for information from the issue author"
},
{
"name": "not reproducible",
"color": "c5def5",
"description": "Could not be reproduced on the latest release"
},
{
"name": "security report",
"color": "b60205",
"description": "Security problem reported publicly instead of privately"
}
]
Loading