Use a GitHub Action to generate the changelog (#9434) [skip ci]
* Use a GitHub Action to generate the changelog * Update main.workflow [skip ci]
This commit is contained in:
parent
344d35bbe9
commit
44d8a59361
18
.github/actions/trigger-github-release/Dockerfile
vendored
Normal file
18
.github/actions/trigger-github-release/Dockerfile
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM node:10
|
||||||
|
|
||||||
|
LABEL "name" = "trigger-github-release"
|
||||||
|
LABEL "version" = "0.0.1"
|
||||||
|
|
||||||
|
LABEL "com.github.actions.name" = "Trigger GitHub release"
|
||||||
|
LABEL "com.github.actions.description" = "Trigger a new GitHub release and generate the changelog using lerna-changelog."
|
||||||
|
LABEL "com.github.actions.icon" = "tag"
|
||||||
|
LABEL "com.github.actions.color" = "yellow"
|
||||||
|
|
||||||
|
ADD entrypoint.sh /action/entrypoint.sh
|
||||||
|
ADD package.json /action/package.json
|
||||||
|
ADD package-lock.json /action/package-lock.json
|
||||||
|
ADD release.js /action/release.js
|
||||||
|
|
||||||
|
RUN chmod +x /action/entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/action/entrypoint.sh"]
|
||||||
29
.github/actions/trigger-github-release/entrypoint.sh
vendored
Executable file
29
.github/actions/trigger-github-release/entrypoint.sh
vendored
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "INFO: Installing action dependencies..."
|
||||||
|
(cd /action; npm ci)
|
||||||
|
|
||||||
|
echo "INFO: Checking out current tag..."
|
||||||
|
git -c advice.detachedHead=false checkout $GITHUB_REF
|
||||||
|
|
||||||
|
echo "INFO: Getting tag info..."
|
||||||
|
current_tag=$(git describe --abbrev=0 --tags)
|
||||||
|
last_tag=$(git describe --abbrev=0 --tags HEAD^)
|
||||||
|
echo "INFO: New version is $current_tag; last version is $last_tag."
|
||||||
|
|
||||||
|
echo "INFO: Generating the changelog..."
|
||||||
|
|
||||||
|
# lerna-changelog expects the token to be provided as GITHUB_AUTH,
|
||||||
|
# but GitHub actions don't allow to predefine custom env vars prefixed with
|
||||||
|
# GITHUB_. We need to define it here.
|
||||||
|
changelog=$(
|
||||||
|
GITHUB_AUTH="$GITHUB_TOKEN" \
|
||||||
|
node /action/node_modules/.bin/lerna-changelog --tag-from $last_tag --tag-to $current_tag
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "INFO: Publishing the new GitHub release..."
|
||||||
|
echo "$changelog" | node /action/release $current_tag
|
||||||
|
|
||||||
|
echo "INFO: Done! Don't forget to thank new contributors :)"
|
||||||
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
Normal file
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
.github/actions/trigger-github-release/package.json
vendored
Normal file
12
.github/actions/trigger-github-release/package.json
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "@internal/trigger-github-release",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@octokit/rest": "^16.3.0",
|
||||||
|
"get-stdin": "^6.0.0",
|
||||||
|
"lerna-changelog": "^0.8.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
.github/actions/trigger-github-release/release.js
vendored
Normal file
25
.github/actions/trigger-github-release/release.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const [ /* node */, /* file */, tag ] = process.argv;
|
||||||
|
|
||||||
|
const getStdin = require("get-stdin");
|
||||||
|
const octokit = require("@octokit/rest")();
|
||||||
|
|
||||||
|
octokit.authenticate({
|
||||||
|
type: "token",
|
||||||
|
token: process.env.GITHUB_TOKEN
|
||||||
|
});
|
||||||
|
|
||||||
|
const [ repoOwner, repoName ] = process.env.GITHUB_REPOSITORY.split("/");
|
||||||
|
|
||||||
|
getStdin()
|
||||||
|
.then(changelog => octokit.repos.createRelease({
|
||||||
|
owner: repoOwner,
|
||||||
|
repo: repoName,
|
||||||
|
tag_name: tag,
|
||||||
|
body: changelog,
|
||||||
|
}))
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
26
.github/main.workflow
vendored
Normal file
26
.github/main.workflow
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
workflow "Release" {
|
||||||
|
on = "push"
|
||||||
|
resolves = ["Trigger GitHub release"]
|
||||||
|
}
|
||||||
|
|
||||||
|
action "Trigger GitHub release" {
|
||||||
|
uses = "./.github/actions/trigger-github-release/"
|
||||||
|
secrets = ["GITHUB_TOKEN"]
|
||||||
|
|
||||||
|
# When GitHub Actions will support the "release" event for public
|
||||||
|
# repositories, we won't need these checks anymore.
|
||||||
|
needs = [
|
||||||
|
"Is version tag",
|
||||||
|
"On master branch",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
action "Is version tag" {
|
||||||
|
uses = "actions/bin/filter@master"
|
||||||
|
args = "tag v*"
|
||||||
|
}
|
||||||
|
|
||||||
|
action "On master branch" {
|
||||||
|
uses = "actions/bin/filter@master"
|
||||||
|
args = "branch master"
|
||||||
|
}
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/.github/actions/*/node_modules
|
||||||
/packages/*/node_modules
|
/packages/*/node_modules
|
||||||
/packages/*/LICENSE
|
/packages/*/LICENSE
|
||||||
!/packages/babel-parser/LICENSE
|
!/packages/babel-parser/LICENSE
|
||||||
@ -15,6 +16,7 @@ coverage
|
|||||||
dist
|
dist
|
||||||
/.package.json
|
/.package.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
!/.github/actions/*/package-lock.json
|
||||||
|
|
||||||
/packages/babel-runtime/helpers/*.js
|
/packages/babel-runtime/helpers/*.js
|
||||||
!/packages/babel-runtime/helpers/toArray.js
|
!/packages/babel-runtime/helpers/toArray.js
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user