-
Notifications
You must be signed in to change notification settings - Fork 315
135 lines (115 loc) · 4.21 KB
/
versioning.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: versioning
run-name: versioning tasks
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: write
jobs:
pull-request:
# only run on template itself, not user instance of template
if: |
github.repository == 'greenelab/lab-website-template' &&
github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
# for debugging
- uses: crazy-max/ghaction-dump-context@v2
- if: runner.debug == '1'
uses: mxschmitt/action-tmate@v3
- name: Checkout base branch contents
uses: actions/checkout@v4
with:
ref: main
path: base
- name: Checkout pr branch contents
uses: actions/checkout@v4
with:
path: pr
- name: Install packages
run: npm install yaml semver
- name: Check version, date, changelog
uses: actions/github-script@v7
with:
script: |
const { readFileSync } = require("fs");
const { lte, valid } = require("semver");
const { parse } = require("yaml");
// load and parse file contents
const { version: oldVersion, "date-released": oldDate } = parse(
readFileSync("base/CITATION.cff").toString()
);
const { version: newVersion, "date-released": newDate } = parse(
readFileSync("pr/CITATION.cff").toString()
);
const changelog = readFileSync("pr/CHANGELOG.md")
.toString()
.split(/^## /m)
.map((section) => {
const [heading, ...body] = section.split("\n");
return [heading.trim(), body.join("\n").trim()];
});
// check version
if (!valid(newVersion)) throw Error("Version not valid");
if (lte(newVersion, oldVersion)) throw Error("Version not updated");
// check date
if (new Date(newDate).toISOString().split("T")[0] !== newDate)
throw Error("Date not valid");
if (new Date(newDate) <= new Date(oldDate)) throw Error("Date not updated");
// check changelog
const newSection = changelog.find(
([heading, body]) =>
heading.includes(newVersion) && heading.includes(newDate) && body
);
if (!newSection) throw Error("Changelog not updated or not valid");
push:
# only run on template itself, not user instance of template
if: |
github.repository == 'greenelab/lab-website-template' &&
github.event_name == 'push'
runs-on: ubuntu-latest
steps:
# for debugging
- uses: crazy-max/ghaction-dump-context@v2
- name: Checkout branch contents
uses: actions/checkout@v4
- name: Install packages
run: npm install yaml semver
# for debugging
- if: runner.debug == '1'
uses: mxschmitt/action-tmate@v3
- name: Get version and body
id: version
uses: actions/github-script@v7
with:
script: |
const { readFileSync } = require("fs");
const { parse } = require("yaml");
// load and parse file contents
const { version, "date-released": date } = parse(
readFileSync("CITATION.cff").toString()
);
const changelog = readFileSync("CHANGELOG.md")
.toString()
.split(/^## /m)
.map((section) => {
const [heading, ...body] = section.split("\n");
return [heading.trim(), body.join("\n").trim()];
});
// find changelog body for version
const [, body = ""] =
changelog.find(
([heading]) => heading.includes(version) && heading.includes(date)
) || [];
return { version, body };
- name: Create GitHub release
uses: ncipollo/[email protected]
with:
commit: ${{ github.ref }}
tag: v${{ fromJson(steps.version.outputs.result).version }}
name: v${{ fromJson(steps.version.outputs.result).version }}
body: ${{ fromJson(steps.version.outputs.result).body }}