Skip to content

Commit 6f6210d

Browse files
Sync organization files (#146)
Automated update from https://github.com/pluginsGLPI/.github/tree/main/sync. Do not edit these files in this repository, change them in the source instead. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dafdfcd commit 6f6210d

5 files changed

Lines changed: 272 additions & 8 deletions

File tree

‎.github/label-commenter-config.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ labels:
1010
issue:
1111
body: |
1212
This issue has been closed as we only track bugs here.
13-
13+
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.
1515
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly.
16-
action: close
16+
action: "close"
1717
- name: "feature suggestion"
1818
labeled:
1919
issue:
2020
body: |
2121
This issue has been closed as we only track bugs here.
22-
22+
2323
You can open a topic to discuss with community about this enhancement on [suggestion website](https://glpi.userecho.com/).
2424
You can also [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly if you are willing to sponsor this feature.
25-
action: close
25+
action: "close"

‎.github/workflows/forward-port.yml‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: "Forward-port"
2+
3+
# `pull_request_target` workflows always run from the default branch, whatever the base branch of the pull request:
4+
# this file only has to be present on the default branch.
5+
6+
on:
7+
pull_request_target:
8+
types:
9+
- "closed"
10+
11+
jobs:
12+
forward-port:
13+
name: "Forward-port"
14+
runs-on: "ubuntu-latest"
15+
# Write operations use the app token: `GITHUB_TOKEN` only lists the protected branches.
16+
permissions:
17+
contents: "read"
18+
# Pull requests opened by bots (dependabot, translations updates, ...) are handled on each branch separately,
19+
# except the forward-port pull requests, so that a fix goes up the whole branches chain.
20+
if: |
21+
github.event.pull_request.merged
22+
&& (github.event.pull_request.user.type != 'Bot' || startsWith(github.event.pull_request.head.ref, 'forward-port/'))
23+
&& !contains(github.event.pull_request.labels.*.name, 'no forward-port')
24+
steps:
25+
# The branches chain is made of the protected `<version>/bugfixes` branches, sorted by version,
26+
# followed by the default branch: a pull request is forward-ported to the next branch of the chain.
27+
- name: "Find target branch"
28+
id: "target"
29+
env:
30+
GH_TOKEN: ${{ github.token }}
31+
REPOSITORY: ${{ github.repository }}
32+
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
33+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
34+
HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
35+
PR_TITLE: ${{ github.event.pull_request.title }}
36+
run: |
37+
# Fetched in its own assignment, so that an API failure fails the job instead of being swallowed.
38+
PROTECTED_BRANCHES=$(gh api --paginate "repos/${REPOSITORY}/branches?protected=true&per_page=100" --jq '.[].name')
39+
BRANCHES=$(
40+
echo "${PROTECTED_BRANCHES}" | grep -E '^[0-9]+(\.[0-9]+)*/bugfixes$' | sort -V
41+
echo "${DEFAULT_BRANCH}"
42+
)
43+
TARGET_BRANCH=$(echo "${BRANCHES}" | awk -v base="${BASE_BRANCH}" 'found { print; exit } $0 == base { found = 1 }')
44+
if [[ -z "${TARGET_BRANCH}" ]]; then
45+
echo "No branch to forward-port \`${BASE_BRANCH}\` to."
46+
else
47+
echo "Forward-port from \`${BASE_BRANCH}\` to \`${TARGET_BRANCH}\`."
48+
fi
49+
echo "branch=${TARGET_BRANCH}" >> "$GITHUB_OUTPUT"
50+
51+
# Do not stack the `[<branch>]` prefixes when a forward-port pull request is itself forward-ported.
52+
TITLE="${PR_TITLE}"
53+
if [[ "${HEAD_BRANCH}" == forward-port/* ]]; then
54+
TITLE="${TITLE#\[*\] }"
55+
fi
56+
# Random delimiter, so that no pull request title can end the block early.
57+
DELIMITER=$(openssl rand -hex 16)
58+
{
59+
echo "title<<${DELIMITER}"
60+
echo "${TITLE}"
61+
echo "${DELIMITER}"
62+
} >> "$GITHUB_OUTPUT"
63+
64+
# Pull requests opened with the workflow `GITHUB_TOKEN` do not trigger the CI: the org bot app is used instead.
65+
# No `workflows` permission, to keep workflow files writable only by humans:
66+
# pull requests changing `.github/workflows/` fail to be pushed and must be forward-ported manually.
67+
- name: "Generate app token"
68+
if: steps.target.outputs.branch != ''
69+
id: "app-token"
70+
uses: "actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510" # v3.3.0
71+
with:
72+
client-id: "${{ vars.GLPI_PROJECT_BOT_CLIENT_ID }}"
73+
private-key: "${{ secrets.GLPI_PROJECT_BOT_PRIVATE_KEY }}"
74+
permission-contents: "write"
75+
permission-pull-requests: "write"
76+
77+
# Only the default branch is checked out: the PR code is cherry-picked, never executed.
78+
- name: "Checkout"
79+
if: steps.target.outputs.branch != ''
80+
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
81+
with:
82+
token: "${{ steps.app-token.outputs.token }}"
83+
84+
- name: "Create forward-port pull request"
85+
if: steps.target.outputs.branch != ''
86+
uses: "korthout/backport-action@8560fb503c275d433c56f05a2f64850093baa9f7" # v4.7.0
87+
with:
88+
github_token: "${{ steps.app-token.outputs.token }}"
89+
target_branches: ${{ steps.target.outputs.branch }}
90+
label_pattern: ""
91+
branch_name: "forward-port/${pull_number}-to-${target_branch}"
92+
pull_title: "[${target_branch}] ${{ steps.target.outputs.title }}"
93+
pull_description: |-
94+
Forward-port of #${pull_number} to `${target_branch}`.
95+
96+
${pull_description}
97+
# The author of a forward-port pull request is the bot: its assignees (the original author) are kept instead.
98+
add_author_as_assignee: ${{ !startsWith(github.event.pull_request.head.ref, 'forward-port/') }}
99+
copy_assignees: true
100+
comment_style: "summary"
101+
merge_commits: "skip"
102+
# On conflict, open a draft PR containing the conflict, to be resolved by the PR author.
103+
experimental: >
104+
{
105+
"conflict_resolution": "draft_commit_conflicts"
106+
}

‎.github/workflows/label-commenter.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
issues:
55
types:
66
- "labeled"
7-
- "unlabeled"
87

98
jobs:
109
comment:
@@ -14,7 +13,9 @@ jobs:
1413
runs-on: "ubuntu-latest"
1514
steps:
1615
- name: "Checkout"
17-
uses: "actions/checkout@v7"
16+
uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
17+
with:
18+
persist-credentials: false
1819

1920
- name: "Label commenter"
20-
uses: "peaceiris/actions-label-commenter@v1"
21+
uses: "peaceiris/actions-label-commenter@f0dbbef043eb1b150b566db36b0bdc8b7f505579" # v1.10.0
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: "Open plugin XML update PR"
2+
3+
# Synced files only reach the default branch, where workflow_run workflows are read from, unlike tag pushes from X.Y/bugfixes
4+
on:
5+
workflow_run:
6+
workflows:
7+
- "Automatically tag new version"
8+
types:
9+
- "completed"
10+
11+
# The pull request is opened with the bot token
12+
permissions:
13+
contents: "read"
14+
15+
jobs:
16+
open-xml-update-pr:
17+
if: github.repository == 'pluginsGLPI/treeview' && github.event.workflow_run.conclusion == 'success'
18+
name: "Open plugin XML update PR"
19+
runs-on: "ubuntu-latest"
20+
steps:
21+
- name: "Generate bot token"
22+
id: "bot-app-token"
23+
uses: "actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510" # v3.3.0
24+
with:
25+
client-id: "${{ vars.GLPI_PROJECT_BOT_CLIENT_ID }}"
26+
private-key: "${{ secrets.GLPI_PROJECT_BOT_PRIVATE_KEY }}"
27+
permission-contents: "write"
28+
permission-pull-requests: "write"
29+
- name: "Copy the tag version block to the default branch XML"
30+
uses: "actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3" # v9.0.0
31+
env:
32+
HEAD_SHA: "${{ github.event.workflow_run.head_sha }}"
33+
DEFAULT_BRANCH: "${{ github.event.repository.default_branch }}"
34+
with:
35+
github-token: "${{ steps.bot-app-token.outputs.token }}"
36+
script: |
37+
const { owner, repo } = context.repo;
38+
const base = process.env.DEFAULT_BRANCH
39+
|| (await github.rest.repos.get({ owner, repo })).data.default_branch;
40+
41+
const readFile = async (path, ref) => {
42+
try {
43+
const { data } = await github.rest.repos.getContent({ owner, repo, path, ref });
44+
return Buffer.from(data.content, 'base64').toString('utf8');
45+
} catch (error) {
46+
if (error.status !== 404) {
47+
throw error;
48+
}
49+
return undefined;
50+
}
51+
};
52+
53+
// Same version extraction as the auto tag workflow, whose tag is named after it
54+
const tag = (await readFile('setup.php', process.env.HEAD_SHA))?.match(/define\s*\(\s*['"]PLUGIN_[A-Z]+_VERSION['"]\s*,\s*['"]([^'"]+)['"]\s*\)/)?.[1];
55+
if (tag === undefined) {
56+
core.info('No plugin version found in setup.php, skipping update.');
57+
return;
58+
}
59+
const tagRef = `refs/tags/${tag}`;
60+
let ref;
61+
try {
62+
({ data: ref } = await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` }));
63+
} catch (error) {
64+
if (error.status !== 404) {
65+
throw error;
66+
}
67+
core.info(`No ${tag} tag, skipping update.`);
68+
return;
69+
}
70+
// Any setup.php push succeeds the auto tag run, only a tag on the triggering commit is a fresh one
71+
const tagSha = ref.object.type === 'tag'
72+
? (await github.rest.git.getTag({ owner, repo, tag_sha: ref.object.sha })).data.object.sha
73+
: ref.object.sha;
74+
if (tagSha !== process.env.HEAD_SHA) {
75+
core.info(`${tag} was not created by this run, skipping update.`);
76+
return;
77+
}
78+
79+
let xmlPath = 'plugin.xml';
80+
let tagXml = await readFile(xmlPath, tagRef);
81+
if (tagXml === undefined) {
82+
const pluginKey = (await readFile('setup.php', tagRef))?.match(/function plugin_version_([a-z0-9_]+)/)?.[1];
83+
if (pluginKey !== undefined) {
84+
xmlPath = `${pluginKey}.xml`;
85+
tagXml = await readFile(xmlPath, tagRef);
86+
}
87+
}
88+
if (tagXml === undefined) {
89+
core.info('No plugin XML file found in the tag, skipping update.');
90+
return;
91+
}
92+
93+
const escapedTag = tag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
94+
const existingRe = new RegExp(`[ \\t]*<version>\\s*<num>\\s*${escapedTag}\\s*</num>[\\s\\S]*?</version>`);
95+
const block = tagXml.match(existingRe)?.[0];
96+
if (block === undefined) {
97+
core.info(`No <version> block for ${tag} in the tag's ${xmlPath}, skipping update.`);
98+
return;
99+
}
100+
101+
const xml = await readFile(xmlPath, base);
102+
if (xml === undefined) {
103+
core.info(`No ${xmlPath} on ${base}, skipping update.`);
104+
return;
105+
}
106+
107+
let updated;
108+
if (existingRe.test(xml)) {
109+
updated = xml.replace(existingRe, () => block);
110+
} else if (/<versions>[ \t]*\r?\n/.test(xml)) {
111+
// Newest first: the block goes right after <versions>.
112+
updated = xml.replace(/<versions>[ \t]*(\r?\n)/, (match, eol) => `${match}${block}${eol}`);
113+
} else {
114+
core.warning(`No <versions> element found in ${xmlPath} on ${base}, skipping update.`);
115+
return;
116+
}
117+
if (updated === xml) {
118+
core.info(`${xmlPath} on ${base} already contains version ${tag}.`);
119+
return;
120+
}
121+
122+
const branch = `release-xml/${tag}`;
123+
const baseSha = (await github.rest.git.getRef({ owner, repo, ref: `heads/${base}` })).data.object.sha;
124+
try {
125+
await github.rest.git.createRef({ owner, repo, ref: `refs/heads/${branch}`, sha: baseSha });
126+
} catch (error) {
127+
// 422: branch left by a previous run, reset it onto the default branch.
128+
if (error.status !== 422) {
129+
throw error;
130+
}
131+
await github.rest.git.updateRef({ owner, repo, ref: `heads/${branch}`, sha: baseSha, force: true });
132+
}
133+
const { data: file } = await github.rest.repos.getContent({ owner, repo, path: xmlPath, ref: branch });
134+
await github.rest.repos.createOrUpdateFileContents({
135+
owner,
136+
repo,
137+
path: xmlPath,
138+
branch,
139+
sha: file.sha,
140+
message: `Add version ${tag} to ${xmlPath}`,
141+
content: Buffer.from(updated, 'utf8').toString('base64'),
142+
});
143+
144+
const { data: openPulls } = await github.rest.pulls.list({ owner, repo, head: `${owner}:${branch}`, base, state: 'open' });
145+
if (openPulls.length > 0) {
146+
core.info(`Updated existing PR: ${openPulls[0].html_url}`);
147+
return;
148+
}
149+
const { data: pull } = await github.rest.pulls.create({
150+
owner,
151+
repo,
152+
head: branch,
153+
base,
154+
title: `Add version ${tag} to ${xmlPath}`,
155+
body: `Copies the \`${tag}\` version block from the tag's \`${xmlPath}\` to \`${base}\`, so that the plugins catalog lists it.`,
156+
});
157+
core.info(`Opened PR: ${pull.html_url}`);

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: "Publish release"
33
on:
44
push:
55
tags:
6-
- '*'
6+
- "*"
77

88
jobs:
99
publish-release:

0 commit comments

Comments
 (0)