Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-saks committed May 11, 2021
1 parent 2f32118 commit 2c45068
Show file tree
Hide file tree
Showing 366 changed files with 88,223 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/release_a_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release a Changelog

on:
push:
branches:
- master

jobs:
release_a_changelog:
name: Release a Changelog
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Release a Changelog
uses: ./
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v1.0.0] - 2021-05-11
* Initial release
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Release-a-Changelog action
This GitHub action creates a release based on your `CHANGELOG.md` file.
You must use [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format or this will not work.


# Installation

Add the following to a new `.github/workflows/release_a_changelog.yml` file (or as part of your existing workflow):
```yaml
name: Release a Changelog

on:
push:
branches:
- master

jobs:
release_a_changelog:
name: Release a Changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Release a Changelog
uses: rasmus-saks/[email protected]
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
```
> :warning: Make sure you have a `checkout` action before `release-a-changelog`, otherwise it won't be able to read your `CHANGELOG.md` file

# Usage
1. Add a new version to `CHANGELOG.md` according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2. Push/merge to master
3. ???
4. Profit
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Release a Changelog'
description: 'Creates a GitHub release based on Keep a Changelog'

runs:
using: node12
main: 'index.js'

inputs:
github-token:
description: "GitHub token"
required: true
65 changes: 65 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');

const CHANGELOG_FILE = 'CHANGELOG.md'
const VERSION_REGEX = /## \[(.+)] - (.+)/

async function run() {
const octokit = github.getOctokit(core.getInput("github-token"));
const entry = getLatestChangelogEntry()
if (!entry) {
console.log(`Could not find the latest release from ${CHANGELOG_FILE}`)
return
}

try {
await octokit.repos.getReleaseByTag({
...github.context.repo,
tag: entry.version
})
console.log(`A release already exists for ${entry.version}, skipping`)
} catch (error) {
console.log(`Could not find a GitHub release for ${entry.version}, creating one`)
octokit.repos.createRelease({
...github.context.repo,
tag_name: entry.version,
name: entry.version,
target_commitish: github.context.sha,
body: entry.changelog,
draft: false,
prerelease: false
})
}
}

function getLatestChangelogEntry() {
if (fs.existsSync(CHANGELOG_FILE)) {
const content = fs.readFileSync(CHANGELOG_FILE);
const entry = {
version: "",
changelog: ""
}
let inLatestEntry = false
for (const line of content.toString().split(/\r?\n/)) {
const result = line.match(VERSION_REGEX)
if (result) {
if (!inLatestEntry) {
// Started reading the latest entry
inLatestEntry = true;
entry.version = result[1];
} else {
break;
}
} else if (inLatestEntry) {
entry.changelog += line + "\n";
}
}
return entry;
}
}


run().catch(error => {
core.setFailed(error)
});
180 changes: 180 additions & 0 deletions node_modules/.package-lock.json

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

9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

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

Loading

0 comments on commit 2c45068

Please sign in to comment.