-
Notifications
You must be signed in to change notification settings - Fork 112
85 lines (71 loc) · 3.15 KB
/
metadata.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: WP Discourse Metadata
on:
pull_request:
types:
- labeled
jobs:
build:
if: github.event.label.name == 'release'
runs-on: ubuntu-latest
name: Metadata
steps:
- name: Checkout base repository
uses: actions/checkout@v3
with:
ref: '${{ github.base_ref }}'
- name: Store base versions
run: |
echo "base_readme_version=$(grep -Pio -m 1 '(?<=Stable tag: )(\d\.\d\.\d)' readme.txt)" >> $GITHUB_ENV
echo "base_change_version=$(grep -Pio -m 1 '(?<=#### )(\d\.\d\.\d)' readme.txt)" >> $GITHUB_ENV
echo "base_change_date=$(grep -Pio -m 1 "(?<=#### (\d\.\d\.\d) )(\d\d\/\d\d\/\d\d\d\d)" readme.txt)" >> $GITHUB_ENV
echo "base_plugin_version=$(grep -Pio -m 1 "(?<=Version: )(\d\.\d\.\d)" wp-discourse.php)" >> $GITHUB_ENV
echo "base_constant_version=$(grep -Pio -m 1 "(?<=WPDISCOURSE_VERSION\'\, \')(\d\.\d\.\d)" wp-discourse.php)" >> $GITHUB_ENV
- name: Checkout head repository
uses: actions/checkout@v3
- name: Store head versions
run: |
echo "head_readme_version=$(grep -Pio -m 1 '(?<=Stable tag: )(\d\.\d\.\d)' readme.txt)" >> $GITHUB_ENV
echo "head_change_version=$(grep -Pio -m 1 '(?<=#### )(\d\.\d\.\d)' readme.txt)" >> $GITHUB_ENV
echo "head_change_date=$(grep -Pio -m 1 "(?<=#### (\d\.\d\.\d) )(\d\d\/\d\d\/\d\d\d\d)" readme.txt)" >> $GITHUB_ENV
echo "head_plugin_version=$(grep -Pio -m 1 "(?<=Version: )(\d\.\d\.\d)" wp-discourse.php)" >> $GITHUB_ENV
echo "head_constant_version=$(grep -Pio -m 1 "(?<=WPDISCOURSE_VERSION\'\, \')(\d\.\d\.\d)" wp-discourse.php)" >> $GITHUB_ENV
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- run: npm install --include=dev
- name: Run checks
uses: actions/github-script@v6
with:
script: |
const semver = require('semver');
const variables = [
'readme_version',
'change_version',
'change_date',
'plugin_version',
'constant_version'
];
const headVersions = [];
variables.forEach(variable => {
let headVar = process.env[`head_${variable}`];
let baseVar = process.env[`base_${variable}`];
let type = variable.split('_')[1];
if (type === 'version') {
if (semver.lte(headVar, baseVar)) {
core.setFailed(`Head ${variable} is less than or equal to base ${variable}.`);
}
headVersions.push(headVar);
}
if (type === 'date') {
let headDate = new Date(headVar);
let baseDate = new Date(baseVar);
if (headDate.getTime() <= baseDate.getTime()) {
core.setFailed(`Head ${variable} is older than or the same as base ${variable}.`);
}
}
});
if (!headVersions.every(hv => hv === headVersions[0])) {
core.setFailed('Head versions do not match.');
}