Skip to content

Commit e007f02

Browse files
authored
Merge pull request #173 from oasisprotocol/mz/ci-lint
Init Change Log fragments
2 parents 39b096a + d45a5dd commit e007f02

File tree

12 files changed

+246
-5
lines changed

12 files changed

+246
-5
lines changed

.changelog/.markdownlint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json
2+
3+
# markdownlint configuration for Change Log fragments.
4+
5+
# For more information, see:
6+
# https://github.com/DavidAnson/markdownlint#optionsconfig.
7+
8+
# Extend project's main configuration.
9+
extends: ../.markdownlint.yml
10+
11+
line-length:
12+
# Line length checking is not strict by default.
13+
strict: true
14+
# Change Log fragments will be listed as bullets indented by 2 spaces so they
15+
# should be 2 characters shorter than ordinary lines.
16+
line_length: 78
17+
18+
# Change Log fragments should not have a heading as the first line.
19+
first-line-heading: false
20+
21+
ul-style:
22+
# Enforce a uniform symbol for unordered lists across all Change Log
23+
# fragments.
24+
style: dash

.changelog/173.process.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Add Change Log and the Change Log fragments process for assembling it
2+
3+
This follows the same Change Log fragments process as is used by [Oasis Core].
4+
5+
For more details, see [Change Log fragments].
6+
7+
[Oasis Core]: https://github.com/oasisprotocol/oasis-core
8+
[Change Log fragments]: .changelog/README.md

.changelog/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Change Log Fragments
2+
3+
This directory collects Change Log fragments:
4+
short files that each contain a snippet of Markdown formatted text that will
5+
be assembled using [towncrier] to form the [Change Log] section for the next
6+
release.
7+
8+
This repository follows the same Change Log fragments style as the
9+
[Oasis Core] repository.
10+
Please, see [its Change Log fragments documentation] for more details.
11+
12+
[Change Log]: ../CHANGELOG.md
13+
[towncrier]: https://github.com/oasisprotocol/towncrier
14+
[Oasis Core]: https://github.com/oasisprotocol/oasis-core
15+
[its Change Log fragments documentation]: https://github.com/oasisprotocol/oasis-core/blob/master/.changelog/README.md

.changelog/template.md.j2

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{# This a Jinja2 template for preparing a new section of the Change Log with the towncrier utility.#}
2+
## {{ versiondata.version }} ({{ versiondata.date }})
3+
{% for section, _ in sections.items() %}
4+
5+
{% if sections[section] %}
6+
{% for category, val in definitions.items() if category in sections[section] %}
7+
{% if definitions[category]['showcontent'] %}
8+
{{ "### " + definitions[category]['name'] }}
9+
10+
{% for text, values in sections[section][category].items() %}
11+
{% set lines = text.splitlines() %}
12+
{% set referenced_issues = "(" + values | join(',\n ') + ")" %}
13+
{% if lines | length > 2 and lines[1] == "" %}
14+
- {{ lines[0] }}
15+
{{ referenced_issues }}
16+
17+
{{ lines[2:] | join('\n') }}
18+
{% else %}
19+
- {{ text }}
20+
{{ referenced_issues }}
21+
{% endif %}
22+
{% if not loop.last %}
23+
24+
{% endif %}
25+
{% endfor %}
26+
{% endif %}
27+
{% if sections[section][category]|length == 0 %}
28+
No significant changes.
29+
30+
{% else %}
31+
{% endif %}
32+
33+
{% endfor %}
34+
{% else %}
35+
No significant changes.
36+
37+
38+
{% endif %}
39+
{% endfor %}

.github/workflows/ci-lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,33 @@ jobs:
5858
- name: Install gitlint
5959
run: |
6060
python -m pip install gitlint
61+
# Needed for Towncrier fork to work with 3.12 and above
62+
- name: Install setuptools
63+
run: |
64+
python -m pip install setuptools
65+
- name: Install towncrier
66+
run: |
67+
python -m pip install https://github.com/oasisprotocol/towncrier/archive/oasis-master.tar.gz
68+
- name: Check for presence of a Change Log fragment (only pull requests)
69+
# NOTE: The pull request' base branch needs to be fetched so towncrier
70+
# is able to compare the current branch with the base branch.
71+
# Source: https://github.com/actions/checkout/#fetch-all-branches.
72+
run: |
73+
git fetch --no-tags origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}"
74+
towncrier check --compare-with "origin/${BASE_BRANCH}"
75+
env:
76+
BASE_BRANCH: ${{ github.base_ref }}
77+
if: github.event_name == 'pull_request'
6178
- name: Lint documentation
6279
run: |
6380
pnpm lint-docs
6481
# Always run this step so that all linting errors can be seen at once.
6582
if: always()
83+
- name: Lint Change Log fragments
84+
run: |
85+
pnpm lint-changelog
86+
# Always run this step so that all linting errors can be seen at once.
87+
if: always()
6688
- name: Lint git commits
6789
run: |
6890
pnpm lint-git

.github/workflows/deploy-gh-pages.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
# For more details on GitHub Actions' pattern match syntax, see:
1111
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags.
1212
- 'v[0-9]+.[0-9]+*'
13-
workflow_dispatch: # Manual
1413

1514
jobs:
1615
build:

.markdownlint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ default: true
1111
line-length:
1212
# Line length checking is not strict by default.
1313
strict: true
14-
line_length: 120
14+
line_length: 80
1515
# Allow longer lines for code blocks.
1616
code_block_line_length: 100
17+
# Ignore on tables
18+
tables: false
1719

1820
# Do not always require language specifiers with fenced code blocks since they
1921
# are not part of the Markdown spec.

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log
2+
3+
All notables changes to this project are documented in this file.
4+
5+
The format is inspired by [Keep a Changelog].
6+
7+
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
8+
9+
<!-- markdownlint-disable no-duplicate-heading -->
10+
11+
<!-- NOTE: towncrier will not alter content above the TOWNCRIER line below. -->
12+
13+
<!-- TOWNCRIER -->

internals/scripts/changelog.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/* eslint-disable no-undef */
3+
const execSync = require('child_process').execSync
4+
const semver = require('semver')
5+
const glob = require('glob')
6+
const packageJson = require('../../package.json')
7+
8+
const folderPath = '.changelog/'
9+
const majorPattern = `${folderPath}*breaking*.md`
10+
const minorPattern = `${folderPath}*feature*.md`
11+
const patchPattern = `${folderPath}*{process,cfg,bugfix,doc,internal,trivial}*.md`
12+
13+
console.log('Assembling Change Log and updating package version')
14+
15+
let version = packageJson.version
16+
if (glob.sync(majorPattern).length > 0) {
17+
console.log('\x1b[31m%s\x1b[0m', 'Warning: This release contains breaking changes.')
18+
version = semver.inc(version, 'major')
19+
} else if (glob.sync(minorPattern).length > 0) {
20+
version = semver.inc(version, 'minor')
21+
} else if (glob.sync(patchPattern).length > 0) {
22+
version = semver.inc(version, 'patch')
23+
} else {
24+
console.log('No Change Log fragments found. Aborting release...')
25+
process.exit(1)
26+
}
27+
28+
if (!semver.valid(version)) {
29+
console.log(`Invalid version: ${version}`)
30+
process.exit(1)
31+
}
32+
33+
if (semver.lte(version, packageJson.version)) {
34+
console.log(`Version ${version} is not greater than ${packageJson.version}`)
35+
process.exit(1)
36+
}
37+
38+
execSync(`pnpm version --no-git-tag-version ${version}`, { stdio: 'inherit' })
39+
execSync(`towncrier build --version ${version}`, { stdio: 'inherit' })

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"eslint": "eslint . --cache --ext .js,.ts,.tsx --max-warnings 0",
99
"lint-git": "node ./internals/scripts/gitlint.mjs",
1010
"lint-docs": "markdownlint --ignore '**/node_modules/**' '**/*.md'",
11+
"lint-changelog": "markdownlint --config .changelog/.markdownlint.yml .changelog/",
12+
"changelog": "node ./internals/scripts/changelog.js",
1113
"release-tag": "node ./internals/scripts/release-tag.js",
1214
"prettier-check": "prettier --check . --ignore-path .eslintignore",
1315
"prettier": "prettier --write . --ignore-path .eslintignore",
@@ -31,9 +33,11 @@
3133
"eslint-config-prettier": "^9.1.0",
3234
"eslint-plugin-react-hooks": "^4.6.0",
3335
"eslint-plugin-react-refresh": "^0.4.5",
36+
"glob": "^11.0.1",
3437
"husky": "^9.0.11",
3538
"lint-staged": "^15.2.2",
3639
"markdownlint-cli": "^0.39.0",
37-
"prettier": "^3.2.5"
40+
"prettier": "^3.2.5",
41+
"semver": "^7.7.1"
3842
}
3943
}

0 commit comments

Comments
 (0)