Skip to content

Commit 05c1575

Browse files
authored
Merge pull request #319 from BitGo/dx-3144-add-express-api-to-changelog
feat: add Express API changelog generation
2 parents b8f6a11 + e84fab4 commit 05c1575

4 files changed

Lines changed: 87 additions & 18 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* @BitGo/developer-experience
22
api.yaml @BitGo/developer-experience @BitGo/technical-writers
3+
express-api.yaml @BitGo/developer-experience @BitGo/technical-writers

.github/workflows/generate-release.yml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- master
77
paths:
88
- 'api.yaml'
9+
- 'express-api.yaml'
910

1011
jobs:
1112
generate-release:
@@ -24,17 +25,61 @@ jobs:
2425
with:
2526
node-version-file: .nvmrc
2627

27-
- name: Get API specs and generate JSON files
28+
- name: Get Platform API specs and generate JSON files
2829
run: |
2930
PREVIOUS_MERGE=$(git rev-list --merges master | head -n 2 | tail -n 1)
3031
git show $PREVIOUS_MERGE:api.yaml > previous.yaml || echo "v0.0.0" > previous.yaml
31-
yq -o=json previous.yaml > previous.json
32-
33-
yq -o=json api.yaml > current.json
32+
yq -o=json previous.yaml > previous-platform.json
33+
34+
yq -o=json api.yaml > current-platform.json
3435
rm previous.yaml
3536
36-
- name: Run API diff
37-
run: node scripts/api-diff.js
37+
- name: Get Express API specs and generate JSON files
38+
run: |
39+
PREVIOUS_MERGE=$(git rev-list --merges master | head -n 2 | tail -n 1)
40+
git show $PREVIOUS_MERGE:express-api.yaml > previous-express.yaml || echo "v0.0.0" > previous-express.yaml
41+
yq -o=json previous-express.yaml > previous-express.json
42+
43+
if [ -f express-api.yaml ]; then
44+
yq -o=json express-api.yaml > current-express.json
45+
else
46+
echo "{}" > current-express.json
47+
fi
48+
rm -f previous-express.yaml
49+
50+
- name: Run Platform API diff
51+
run: node scripts/api-diff.js previous-platform.json current-platform.json platform-release.md
52+
53+
- name: Run Express API diff
54+
run: node scripts/api-diff.js previous-express.json current-express.json express-release.md
55+
56+
- name: Combine release descriptions
57+
run: |
58+
PLATFORM_HAS_CONTENT=false
59+
EXPRESS_HAS_CONTENT=false
60+
61+
if [ -s platform-release.md ]; then
62+
PLATFORM_HAS_CONTENT=true
63+
fi
64+
if [ -s express-release.md ]; then
65+
EXPRESS_HAS_CONTENT=true
66+
fi
67+
68+
# Clear output
69+
> release-description.md
70+
71+
if [ "$PLATFORM_HAS_CONTENT" = true ] && [ "$EXPRESS_HAS_CONTENT" = true ]; then
72+
# Both have content — nest under headers
73+
echo "## Platform API" >> release-description.md
74+
sed 's/^## /### /' platform-release.md >> release-description.md
75+
echo "" >> release-description.md
76+
echo "## Express API" >> release-description.md
77+
sed 's/^## /### /' express-release.md >> release-description.md
78+
elif [ "$PLATFORM_HAS_CONTENT" = true ]; then
79+
cat platform-release.md >> release-description.md
80+
elif [ "$EXPRESS_HAS_CONTENT" = true ]; then
81+
cat express-release.md >> release-description.md
82+
fi
3883
3984
- name: Determine version
4085
id: version
@@ -43,11 +88,11 @@ jobs:
4388
YEAR=$(date +%Y)
4489
MONTH=$(date +%m)
4590
DAY=$(date +%d)
46-
91+
4792
# Get the latest tag for current year.month.day
4893
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v$YEAR.$MONTH.$DAY.0")
4994
echo "Current version: $CURRENT_VERSION"
50-
95+
5196
# Extract version number
5297
if [[ $CURRENT_VERSION == v$YEAR.$MONTH.$DAY.* ]]; then
5398
# If we already have a tag for today, increment its number
@@ -57,7 +102,7 @@ jobs:
57102
# If this is the first tag for today, start at .1
58103
NEW_VERSION="v$YEAR.$MONTH.$DAY.1"
59104
fi
60-
105+
61106
echo "New version: $NEW_VERSION"
62107
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
63108
@@ -76,7 +121,7 @@ jobs:
76121
echo "Release summary is empty, skipping release creation"
77122
exit 0
78123
fi
79-
124+
80125
# Create GitHub Release
81126
gh release create ${{ steps.version.outputs.new_version }} \
82127
--title "${{ steps.version.outputs.new_version }}" \

scripts/api-diff.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const fs = require('fs');
22

3-
// Read the JSON files
4-
const previousSpec = JSON.parse(fs.readFileSync('previous.json', 'utf8'));
5-
const currentSpec = JSON.parse(fs.readFileSync('current.json', 'utf8'));
3+
// Read the JSON files (paths configurable via CLI args)
4+
const previousPath = process.argv[2] || 'previous.json';
5+
const currentPath = process.argv[3] || 'current.json';
6+
const outputPath = process.argv[4] || 'release-description.md';
7+
8+
const previousSpec = JSON.parse(fs.readFileSync(previousPath, 'utf8'));
9+
const currentSpec = JSON.parse(fs.readFileSync(currentPath, 'utf8'));
610

711
// Initialize change tracking
812
const changes = {
@@ -491,4 +495,4 @@ detectRenamedEndpoints();
491495
const releaseDescription = generateReleaseNotes();
492496

493497
// Write release notes to markdown file
494-
fs.writeFileSync('release-description.md', releaseDescription);
498+
fs.writeFileSync(outputPath, releaseDescription);

tests/generate-release.test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ describe('Generate Release Description', async () => {
1111

1212
beforeEach(() => {
1313
// Clean up any existing output files
14-
if (fs.existsSync('release-description.md')) {
15-
fs.unlinkSync('release-description.md');
16-
}
14+
['release-description.md', 'custom-output.md', 'previous.json', 'current.json'].forEach(file => {
15+
if (fs.existsSync(file)) {
16+
fs.unlinkSync(file);
17+
}
18+
});
1719
});
1820

1921
scenarios.forEach(scenario => {
@@ -43,9 +45,26 @@ describe('Generate Release Description', async () => {
4345
});
4446
});
4547

48+
it('supports custom file paths via CLI args', () => {
49+
const scenarioDir = path.join(FIXTURES_DIR, 'new-route-and-method');
50+
51+
// Run the script with custom input/output paths
52+
execSync(
53+
`node scripts/api-diff.js ${path.join(scenarioDir, 'previous.json')} ${path.join(scenarioDir, 'current.json')} custom-output.md`
54+
);
55+
56+
const actual = fs.readFileSync('custom-output.md', 'utf8').trim();
57+
const expected = fs.readFileSync(
58+
path.join(scenarioDir, 'expected.md'),
59+
'utf8'
60+
).trim();
61+
62+
assert.strictEqual(actual, expected);
63+
});
64+
4665
afterEach(() => {
4766
// Clean up test files
48-
['previous.json', 'current.json', 'release-description.md'].forEach(file => {
67+
['previous.json', 'current.json', 'release-description.md', 'custom-output.md'].forEach(file => {
4968
if (fs.existsSync(file)) {
5069
fs.unlinkSync(file);
5170
}

0 commit comments

Comments
 (0)