Skip to content

Commit 57132be

Browse files
authored
Merge pull request #64 from NixOS/fixchangelog
Fix outdated “What’s New” section
2 parents 59cc3e9 + 07eda47 commit 57132be

File tree

6 files changed

+123
-44
lines changed

6 files changed

+123
-44
lines changed

.github/scripts/get-release-notes.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
3+
module.exports = async ({github, context, core, outputFile, releaseTagInput, allowFallbackToLatest}) => {
4+
const { RELEASE_TAG_INPUT, ALLOW_FALLBACK_TO_LATEST } = process.env;
5+
const fs = require('fs');
6+
const owner = context.repo.owner;
7+
const repo = context.repo.repo;
8+
9+
if (!outputFile) {
10+
throw new Error("outputFile not specified");
11+
}
12+
13+
let releaseNote;
14+
if (context.eventName === 'release') {
15+
releaseNote = context.payload.release.body;
16+
}
17+
else if (releaseTagInput && context.payload.inputs[releaseTagInput]) {
18+
const tag = context.payload.inputs[releaseTagInput];
19+
try {
20+
const response = await github.rest.repos.getReleaseByTag({owner, repo, tag});
21+
releaseNote = response.data.body;
22+
}
23+
catch (e) {
24+
if (e.status === 404) {
25+
core.setFailed(`No release with tag '${tag}' has been found.`);
26+
return;
27+
}
28+
else {
29+
throw e;
30+
}
31+
}
32+
}
33+
else if (allowFallbackToLatest) {
34+
const response = await github.rest.repos.getLatestRelease({owner, repo});
35+
releaseNote = response.data.body;
36+
}
37+
else {
38+
throw new Error("No release tag specified and allowFallbackToLatest not set");
39+
}
40+
41+
core.info(`Release notes:\n${releaseNote}`);
42+
fs.writeFileSync(outputFile, releaseNote, { encoding: 'utf8', flag: 'wx' });
43+
}

.github/workflows/bump-version.yml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,12 @@ jobs:
5656
uses: actions/github-script@v6
5757
with:
5858
script: |
59-
const fs = require('fs');
60-
const owner = context.repo.owner;
61-
const repo = context.repo.repo;
62-
let releaseNote;
63-
64-
if (context.eventName === 'release') {
65-
releaseNote = context.payload.release.body;
66-
}
67-
else if (context.payload.inputs.release_tag) {
68-
const tag = context.payload.inputs.release_tag;
69-
try {
70-
const response = await github.rest.repos.getReleaseByTag({owner, repo, tag});
71-
releaseNote = response.data.body;
72-
}
73-
catch (e) {
74-
if (e.status === 404) {
75-
core.setFailed(`No release with tag '${tag}' has been found.`);
76-
return;
77-
}
78-
else {
79-
throw e;
80-
}
81-
}
82-
}
83-
else {
84-
const response = await github.rest.repos.getLatestRelease({owner, repo});
85-
releaseNote = response.data.body;
86-
}
87-
88-
core.info(`Release notes:\n${releaseNote}`);
89-
fs.writeFileSync('release_note.md', releaseNote, { encoding: 'utf8', flag: 'wx' });
59+
await require('.github/scripts/get-release-notes.js')({
60+
github, context, core,
61+
outputFile: 'release_note.md',
62+
releaseTagInput: 'release_tag',
63+
allowFallbackToLatest: true,
64+
});
9065
- name: Update files with Gradle
9166
run: ./gradlew --stacktrace metadata patchChangelog --release-note="$(<release_note.md)" bumpVersion
9267
# Commit and push

.github/workflows/publish-to-jetbrains.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ on:
44
release:
55
types: [ published ]
66
workflow_dispatch:
7-
inputs: {}
7+
inputs:
8+
release_tag:
9+
description: 'Use release notes of'
10+
type: string
11+
required: true
812

913
jobs:
1014
publish:
@@ -33,6 +37,18 @@ jobs:
3337
${{hashFiles('gradle/wrapper/gradle-wrapper.properties')}}-\
3438
${{hashFiles('gradle.properties', '**/*.gradle.kts')}}"
3539
# Build and publish
40+
- name: Obtain release notes
41+
uses: actions/github-script@v6
42+
with:
43+
script: |
44+
await require('.github/scripts/get-release-notes.js')({
45+
github, context, core,
46+
outputFile: 'release_note.md',
47+
releaseTagInput: 'release_tag',
48+
allowFallbackToLatest: true,
49+
});
50+
- name: Patch changelog for release
51+
run: ./gradlew --stacktrace patchChangelog --release-note="$(<release_note.md)"
3652
- name: Build and publish plugin
3753
id: gradle-build
3854
env:

CHANGELOG.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## [Unreleased]
4+
45
### Added
56

67
### Changed
@@ -10,66 +11,77 @@
1011
### Removed
1112

1213
### Fixed
14+
- Final changes on release notes not applied to *“What’s New”* section
15+
of published plugin
1316

1417
### Security
1518

1619
## [0.4.0.9]
20+
1721
### Added
1822
- Support for [string interpolation in paths](https://nixos.org/manual/nix/stable/language/string-interpolation#path) (#60)
1923

2024
## [0.4.0.8]
25+
2126
### Added
2227
- Highlighting of built-in functions and constants
2328
- Support for [semantic highlighting](https://www.jetbrains.com/help/idea/configuring-colors-and-fonts.html#semantic-highlighting)
2429
- Settings to change the colors used by the highlighter
2530

2631
## [0.4.0.7]
32+
2733
### Added
2834
- Support for IDEA 2023.1 EAP
2935

3036
### Removed
3137
- Support for IDEA 2021.3
3238

3339
## [0.4.0.6]
40+
3441
### Added
3542
- Support for IDEA 2022.3 EAP
3643

3744
### Removed
3845
- Support for IDEA 2021.2
3946

4047
## [0.4.0.5]
48+
4149
### Fixed
4250
- Trailing commas reported as syntax error (#46)
4351

4452
## [0.4.0.4]
53+
4554
### Added
4655
- Support for IDEA 2022.2 EAP
4756

4857
### Removed
4958
- Support for IDEA 2021.1
5059

5160
## [0.4.0.3]
61+
5262
### Added
5363
- Support for IDEA 2022.1
5464

5565
## [0.4.0.2]
66+
5667
### Added
5768
- Support for IDEA 2021.3
5869

5970
### Removed
6071
- Support for IDEA 2020.3
6172

6273
## [0.4.0.1]
74+
6375
### Added
6476
- Support for IDEA 2021.2
6577

6678
### Removed
6779
- Support for IDEA 2020.2
6880

6981
## [0.4.0.0]
70-
7182
This release features a complete rewrite of the parser and lexer within
7283
the plugin.
84+
7385
### Added
7486
- Support for the full syntax of Nix 2.3
7587

@@ -97,24 +109,28 @@ the plugin.
97109
- Incorrect reset of parser state when modifying a file
98110

99111
## [0.3.0.6]
112+
100113
### Added
101114
- Support for IDEA 2021.1
102115

103116
### Removed
104117
- Support for IDEA 2020.1
105118

106119
## [0.3.0.5]
120+
107121
### Added
108122
- Support line comment and block comment IDEA actions
109123

110124
## [0.3.0.4]
125+
111126
### Added
112127
- Support for IDEA 2020.3
113128

114129
### Removed
115130
- Support for IDEA 2019.3
116131

117132
## [0.3.0.3]
133+
118134
### Fixed
119135
- Change ID of plugin back from `org.nixos.idea` in version 0.3.0.0 to
120136
`nix-idea` from earlier versions. The different ID of version 0.3.0.0
@@ -124,5 +140,23 @@ the plugin.
124140
file, you should uninstall it when updating to a new version.**
125141

126142
## [0.3.0.0]
143+
127144
### Changed
128145
- Update project to build for recent IJ versions
146+
147+
[Unreleased]: https://github.com/NixOS/nix-idea/compare/v0.4.0.9...HEAD
148+
[0.3.0.0]: https://github.com/NixOS/nix-idea/commits/v0.3.0.0
149+
[0.3.0.3]: https://github.com/NixOS/nix-idea/compare/v0.3.0.0...v0.3.0.3
150+
[0.3.0.4]: https://github.com/NixOS/nix-idea/compare/v0.3.0.3...v0.3.0.4
151+
[0.3.0.5]: https://github.com/NixOS/nix-idea/compare/v0.3.0.4...v0.3.0.5
152+
[0.3.0.6]: https://github.com/NixOS/nix-idea/compare/v0.3.0.5...v0.3.0.6
153+
[0.4.0.0]: https://github.com/NixOS/nix-idea/compare/v0.3.0.6...v0.4.0.0
154+
[0.4.0.1]: https://github.com/NixOS/nix-idea/compare/v0.4.0.0...v0.4.0.1
155+
[0.4.0.2]: https://github.com/NixOS/nix-idea/compare/v0.4.0.1...v0.4.0.2
156+
[0.4.0.3]: https://github.com/NixOS/nix-idea/compare/v0.4.0.2...v0.4.0.3
157+
[0.4.0.4]: https://github.com/NixOS/nix-idea/compare/v0.4.0.3...v0.4.0.4
158+
[0.4.0.5]: https://github.com/NixOS/nix-idea/compare/v0.4.0.4...v0.4.0.5
159+
[0.4.0.6]: https://github.com/NixOS/nix-idea/compare/v0.4.0.5...v0.4.0.6
160+
[0.4.0.7]: https://github.com/NixOS/nix-idea/compare/v0.4.0.6...v0.4.0.7
161+
[0.4.0.8]: https://github.com/NixOS/nix-idea/compare/v0.4.0.7...v0.4.0.8
162+
[0.4.0.9]: https://github.com/NixOS/nix-idea/compare/v0.4.0.8...v0.4.0.9

build.gradle.kts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.changelog.Changelog
12
import org.jetbrains.changelog.markdownToHTML
23
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
34
import org.jetbrains.grammarkit.tasks.GenerateParserTask
@@ -8,7 +9,7 @@ plugins {
89
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
910
id("org.jetbrains.intellij") version "1.13.3"
1011
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
11-
id("org.jetbrains.changelog") version "1.3.1"
12+
id("org.jetbrains.changelog") version "2.1.0"
1213
// grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
1314
id("org.jetbrains.grammarkit") version "2021.2.2"
1415
}
@@ -52,7 +53,11 @@ intellij {
5253
}
5354

5455
changelog {
56+
repositoryUrl.set("https://github.com/NixOS/nix-idea")
57+
lineSeparator.set("\n")
58+
// Workarounds because our version numbers do not match the format of semantic versioning:
5559
headerParserRegex.set("^[-._+0-9a-zA-Z]+\$")
60+
combinePreReleases.set(false)
5661
}
5762

5863
grammarKit {
@@ -129,7 +134,14 @@ tasks {
129134
dir.mkdirs()
130135
dir.resolve("version.txt").writeText(pluginVersion)
131136
dir.resolve("zipfile.txt").writeText(buildPlugin.get().archiveFile.get().toString())
132-
dir.resolve("latest_changelog.md").writeText(changelog.getLatest().toText())
137+
dir.resolve("latest_changelog.md").writeText(with(changelog) {
138+
renderItem(
139+
(getOrNull(pluginVersion) ?: getUnreleased())
140+
.withHeader(false)
141+
.withEmptySections(false),
142+
Changelog.OutputType.MARKDOWN
143+
)
144+
})
133145
}
134146
}
135147

@@ -175,7 +187,14 @@ tasks {
175187
)
176188

177189
// Get the latest available change notes from the changelog file
178-
changeNotes.set(provider { changelog.getLatest().toHTML() })
190+
changeNotes.set(provider { with(changelog) {
191+
renderItem(
192+
(getOrNull(pluginVersion) ?: getUnreleased())
193+
.withHeader(false)
194+
.withEmptySections(false),
195+
Changelog.OutputType.HTML
196+
)
197+
}})
179198
}
180199

181200
runPluginVerifier {

gradle/bumpVersion.gradle.kts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ tasks.named("patchChangelog") {
2424
setProperty("releaseNote", releaseNote.replace("\r\n", "\n"))
2525
}
2626
}
27-
// The task (as of org.jetbrains.changelog 1.3.1) removes trailing newlines from the changelog.
28-
// Add a trailing newline afterwards as a workaround.
29-
doLast {
30-
val file = file(property("outputFile"))
31-
if (!file.readText().endsWith("\n")) {
32-
file.appendText("\n")
33-
}
34-
}
3527
}
3628

3729
/**

0 commit comments

Comments
 (0)