Skip to content

Commit f108842

Browse files
Sync organization files
1 parent 1b2257a commit f108842

7 files changed

Lines changed: 199 additions & 29 deletions

‎.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/auto-tag-new-version.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ on:
88
paths:
99
- "setup.php"
1010

11+
# Tags are pushed with AUTOTAG_TOKEN
12+
permissions:
13+
contents: "read"
14+
1115
jobs:
1216
auto-tag-new-version:
1317
name: "Automatically tag new version"
1418
uses: "glpi-project/plugin-release-workflows/.github/workflows/auto-tag-new-version.yml@v1"
19+
with:
20+
bot-client-id: "${{ vars.GLPI_PROJECT_BOT_CLIENT_ID }}"
1521
secrets:
16-
github-token: "${{ secrets.AUTOTAG_TOKEN }}"
22+
bot-private-key: "${{ secrets.GLPI_PROJECT_BOT_PRIVATE_KEY }}"
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
name: 'Close stale issues'
1+
name: "Close stale issues and pull requests"
2+
23
on:
34
schedule:
4-
- cron: '0 8 * * *'
5+
- cron: "0 8 * * *"
56

67
jobs:
78
stale:
89
if: github.repository == 'pluginsGLPI/fields'
910
permissions:
10-
issues: write # for actions/stale to close stale issues
11-
runs-on: ubuntu-latest
11+
issues: "write" # for actions/stale to close stale issues
12+
pull-requests: "write" # for actions/stale to close stale pull requests
13+
runs-on: "ubuntu-latest"
1214
steps:
13-
- uses: actions/stale@v11
15+
- uses: "actions/stale@v11"
1416
with:
1517
stale-issue-message: >-
16-
There has been no activity on this issue for some time and therefore it is considered stale
17-
and will be closed automatically in 10 days.
18-
19-
20-
If this issue is related to a bug, please try to reproduce on latest release. If the problem persist,
18+
There has been no activity on this issue for 60 days and therefore it is considered stale
19+
and will be closed automatically in 14 days.
20+
21+
22+
If this issue is related to a bug, please try to reproduce on latest release. If the problem persists,
2123
feel free to add a comment to revive this issue.
22-
23-
If it is related to a new feature, please open a topic to discuss with community about this enhancement
24-
on [suggestion website](https://glpi.userecho.com/).
25-
26-
27-
You may also consider taking a [subscription](https://glpi-project.org/subscriptions/) to get professionnal
28-
support or [contact GLPI editor team](https://portal.glpi-network.com/contact-us) directly.
29-
days-before-issue-stale: 15
30-
days-before-pr-stale: -1 # PR will be marked as stale manually.
31-
days-before-close: 5
24+
stale-pr-message: >-
25+
There has been no activity on this pull request for 90 days and therefore it is considered stale
26+
and will be closed automatically in 14 days.
27+
Feel free to add a comment or push new commits to keep it open.
28+
days-before-issue-stale: 60
29+
days-before-pr-stale: 90
30+
days-before-close: 14
3231
exempt-issue-labels: "bug,enhancement,question,security" # Issues with "bug", "enhancement", "question" or "security" labels will not be marked as stale
32+
exempt-pr-labels: "security" # PR with "security" label will not be marked as stale
33+
exempt-draft-pr: true # Draft PR are work in progress.
3334
exempt-all-milestones: true # Do not check issues/PR with defined milestone.
3435
ascending: true # First check older issues/PR.
3536
operations-per-run: 750 # Max API calls per run.

‎.github/workflows/continuous-integration.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ concurrency:
1515
group: "${{ github.workflow }}-${{ github.ref }}"
1616
cancel-in-progress: true
1717

18+
# The changelog and plugin manifest checks read the pull request files
19+
permissions:
20+
contents: "read"
21+
pull-requests: "read"
22+
1823
jobs:
1924
generate-ci-matrix:
2025
name: "Generate CI matrix"

‎.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/fields' && 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)