Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-lebleu committed Jun 6, 2021
0 parents commit b5fc9ff
Show file tree
Hide file tree
Showing 3,734 changed files with 1,504,176 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
31 changes: 31 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and test
on:
push:
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache dependencies
uses: actions/cache@v2
with:
path: '**/node_modules'
key: node-modules-${{ hashfiles('**/package-lock.json') }}
- name: Github checkout
uses: actions/checkout@v2
- name: Setup node.js environment
uses: actions/setup-node@v1
with:
node-version: '14.16'
- name: Install NPM dependencies
run: npm i typescript -g && npm i
- name: Compile Typescript files
run: tsc
- name: Execute unit testing sets
run: npm run coverage
- name: Publish to coveralls.io
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./reports/coverage/lcov.info
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
.nyc_output/
reports/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Steve Lebleu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[![Build and test](https://github.com/konfer-be/action-create-release-from-tag/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/konfer-be/action-create-release-from-tag/actions/workflows/build-and-test.yml)
[![Coverage Status](https://coveralls.io/repos/github/konfer-be/action-create-release-from-tag/badge.svg?branch=main)](https://coveralls.io/github/konfer-be/action-create-release-from-tag?branch=main)
![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/konfer-be/action-create-release-from-tag/main)
![Requires.io (branch)](https://img.shields.io/requires/github/konfer-be/action-create-release-from-tag/main)

# Create release whith changelog as release note

As repetitive and simple task, release creation is an ideal candidate to automation with Github action. This package create a release where:

- Label is the last tag version
- Body is the commits related to this tag, and formated as changelog

## Getting started

Simple as that in your action definition:

```yaml
- name: Create release with changelog
uses: konfer-be/action-create-release-from-tag@v1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }} # required
```

:warning: Be aware that the checkout must absolutely bring back the entire commit history.

## Licence

[MIT](/LICENSE)
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Create release from last tag
description: Create release from last tag with changelog on commits history based.
author: Steve Lebleu
branding:
icon: tag
color: blue
inputs:
token:
description: GitHub access token
required: true
outputs:
changelog:
description: Generated changelog
runs:
using: node12
main: './lib/index.js'
45 changes: 45 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = void 0;
const core_1 = require("@actions/core");
const git_service_1 = require("./services/git.service");
const github_service_1 = require("./services/github.service");
const format_util_1 = require("./utils/format.util");
/**
* @description Entry point of the action
*
* @param tag
* @param token
*/
const main = (token) => __awaiter(void 0, void 0, void 0, function* () {
try {
core_1.debug('Token input:' + token);
const tags = yield git_service_1.GitService.getLastTags(2);
if (!tags) {
throw new Error('Tags cannot be retrieved');
}
core_1.debug(`tags: ${tags}`);
const messages = yield git_service_1.GitService.getCommits(tags);
const changelog = format_util_1.toChangelog(messages);
core_1.debug(`Changelog: ${changelog}`);
const githubService = new github_service_1.GithubService(token);
githubService.createRelease(tags.slice(0, 1).shift(), changelog);
core_1.setOutput('changelog', changelog);
}
catch (e) {
core_1.setFailed(e.message);
}
});
exports.main = main;
main(core_1.getInput('token'))
.then(response => core_1.debug(`Success with ${response}`))
.catch(error => core_1.setFailed(error.message));
63 changes: 63 additions & 0 deletions lib/services/git.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitService = void 0;
const core_1 = require("@actions/core");
const child_process_promise_1 = require("child-process-promise");
/**
* @description Implements git interactions commands
*/
class GitService {
constructor() { }
/**
* Finds the n last tags in history
*
* @param n Max number of tags to return
*/
static getLastTags(n) {
return __awaiter(this, void 0, void 0, function* () {
const tags = yield child_process_promise_1.exec('git tag -l --sort=-creatordate');
core_1.debug(`${n} last tags are ${tags.stdout}`);
if (!tags.stdout || tags.stdout === '') {
core_1.setFailed('Tags cannot be retrieved');
}
return tags.stdout.split('\n').slice(0, n) || null;
});
}
/**
* List all commit messages since last tag
*
* @param tag Last tag reference
*/
static getCommits(tags) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
core_1.debug(`Tags received in input ${tags}`);
let command = '';
switch (tags.length) {
case 1:
command = `git log --oneline --pretty=format:"%s"`;
break;
case 2:
command = `git log ${tags.slice().pop().trim()}..${tags.slice().shift().trim()} --oneline --pretty=format:"%s"`;
break;
}
core_1.debug(`Command ${command}`);
const messages = yield child_process_promise_1.exec(command);
core_1.debug(`The commit messages are ${messages.stdout}`);
if (!messages || !(messages === null || messages === void 0 ? void 0 : messages.stdout)) {
core_1.warning(`No messages have been found`);
}
return (_a = messages.stdout) !== null && _a !== void 0 ? _a : 'N/A';
});
}
}
exports.GitService = GitService;
65 changes: 65 additions & 0 deletions lib/services/github.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GithubService = void 0;
const core_1 = require("@actions/core");
const github_1 = require("@actions/github");
/**
* @description Implements Github interactions methods
*/
class GithubService {
constructor(token) {
this.token = token;
core_1.debug(`GithubService.token: ${this.token}`);
}
/**
* @description Check if a release with the same tag alreadyExist
*
* @param tag
*/
isExistingReleaseWithSameLabel(tag) {
return __awaiter(this, void 0, void 0, function* () {
const octokit = github_1.getOctokit(this.token);
const releaseByTag = yield octokit.rest.repos.getReleaseByTag({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
tag,
});
return true;
});
}
/**
* @description Create a release with tag_name and changelog as text
*
* @param tag
* @param changelog
*/
createRelease(tag, changelog) {
return __awaiter(this, void 0, void 0, function* () {
core_1.debug(`#GithubService.createRelease tag supplied: ${tag}`);
core_1.debug(`#GithubService.createRelease changelog supplied: ${changelog}`);
const octokit = github_1.getOctokit(this.token);
const response = yield octokit.rest.repos.createRelease({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
tag_name: tag,
name: tag,
body: changelog
});
if (response.status != 201) {
throw new Error(`Failed to create the release: ${response.status}`);
}
core_1.info(`Release created ${response.data.name}`);
return response.data.html_url;
});
}
}
exports.GithubService = GithubService;
Loading

0 comments on commit b5fc9ff

Please sign in to comment.