Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fstreicher committed Apr 30, 2021
1 parent ff41a3f commit fc0caf6
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 105 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
create-release:
name: "Create Release"
runs-on: "ubuntu-latest"

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read Changelog
uses: ./
id: read
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.read.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104 changes: 1 addition & 103 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,2 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
.vscode/
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# [1.0.0]() (2021-04-30)
## Initial release
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# snapaddy-changelog-parser
Github action to parse changelog to create automatic Github releases
# snapADDY Changelog Parser

A Github Action to parse manually created changelogs for automatic Github Releases.

This action reads a markdown changelog file, and provides the latest versions release notes to steps further down the pipeline.

### Simple example:
```yaml
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
tagged-release:
name: "Tagged Release"
runs-on: "ubuntu-latest"

steps:
- name: Read Changelog
uses: snapADDY/[email protected]
id: read
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.read.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
---
## Required changelog formatting:
Each section hast to start with a `#` followed by a space (markdown H1) and a semver formatted version number. Brackets around the version number are also supported, in case it's a hyperlink.
```markdown
# 1.0.0
or
# [1.0.0](https://)
```

### Example:
This input:
```markdown
# [1.0.0](https://github.com/...) (2021-04-30)
## Features
- CI Magic 🧙‍♂️
# [0.1.0](https://github.com/...) (2021-04-27)
## Fixes
- more notes
```
would return:
```markdown
## Features
- CI Magic 🧙‍♂️
```

---

### Input
| Name | Type | Description | Default |
|---|---|---|---|
| changelog-path | string | Path to the changelog file | `CHANGELOG.md` |

### Output
| Name | Type | Description |
|---|---|---|
| changelog | string | |
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'snapADDY Changelog Parser'
author : 'snapADDY GmbH'
description: 'Extract latest entry from markdown formatted changelog'
branding:
icon: 'file-text'
color: 'green'
inputs:
changelog-path:
description: 'path to changelog file'
required: true
default: 'CHANGELOG.md'
outputs:
changelog:
description: 'The changelog for the given tag'
runs:
using: 'node12'
main: 'dist/index.js'
1 change: 1 addition & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "snapaddy-changelog-parser",
"version": "1.0.0",
"description": "Parser for CHANGELOG.md to create automatic Github Releases",
"main": "index.ts",
"scripts": {
"build": "npx ncc build -m src/index.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/snapADDY/snapaddy-changelog-parser.git"
},
"author": "snapADDY GmbH",
"license": "GNU GPL v3",
"bugs": {
"url": "https://github.com/snapADDY/snapaddy-changelog-parser/issues"
},
"homepage": "https://github.com/snapADDY/snapaddy-changelog-parser#readme",
"dependencies": {
"@actions/core": "^1.2.7"
},
"devDependencies": {
"@types/node": "^15.0.1",
"@vercel/ncc": "^0.28.4",
"typescript": "^4.2.4"
}
}
38 changes: 38 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as core from '@actions/core';
import * as fs from 'fs';
import * as readline from 'readline';

async function run(): Promise<void> {
try {
const filepath = core.getInput('changelog-path');
const changelog = await readChangelog(filepath);
core.setOutput('changelog', changelog);

} catch (error) {
core.setFailed(error.message);
}
}

async function readChangelog(filepath: string): Promise<string> {
const fileStream = fs.createReadStream(filepath);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});

let versionCounter = 0;
const changelogLines: Array<string> = [];

for await (const line of rl) {
if (/^# \[?[0-9]+\.[0-9]+\.[0-9]+\]?/.test(line)) {
versionCounter++;
if (versionCounter > 1) {
break;
}
}
changelogLines.push(line);
}
return changelogLines.slice(1).join('\n').trim();
}

run();
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}

0 comments on commit fc0caf6

Please sign in to comment.