Extract release actions to babel/actions
This commit is contained in:
parent
fb910e063c
commit
9bc9571381
16
.github/actions/commit-matches-branch/Dockerfile
vendored
16
.github/actions/commit-matches-branch/Dockerfile
vendored
@ -1,16 +0,0 @@
|
||||
FROM debian:stable-slim
|
||||
|
||||
LABEL "name"="commit-matches-branch"
|
||||
LABEL "version"="1.0.0"
|
||||
|
||||
LABEL "com.github.actions.name"="Commit matches branch"
|
||||
LABEL "com.github.actions.description"="Only continue the workflow if the current commit is the last commit of the given branch"
|
||||
LABEL "com.github.actions.icon"="filter"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
ADD entrypoint.sh /action/entrypoint.sh
|
||||
|
||||
RUN chmod +x /action/entrypoint.sh
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends git
|
||||
|
||||
ENTRYPOINT ["/action/entrypoint.sh"]
|
||||
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
current=$(git rev-parse HEAD)
|
||||
git checkout $1
|
||||
branch=$(git rev-parse HEAD)
|
||||
|
||||
if [ "$current" = "$branch" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 78
|
||||
fi
|
||||
@ -1,19 +0,0 @@
|
||||
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
|
||||
ADD update-changelog.js /action/update-changelog.js
|
||||
|
||||
RUN chmod +x /action/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/action/entrypoint.sh"]
|
||||
@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "INFO: Installing action dependencies..."
|
||||
(cd /action; npm ci)
|
||||
|
||||
echo "INFO: Getting release version..."
|
||||
current_tag=$(git describe --abbrev=0 --tags $GITHUB_SHA)
|
||||
|
||||
last_tag=$(git describe --abbrev=0 --tags $current_tag^)
|
||||
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: Updating CHANGELOG.md..."
|
||||
echo "$changelog" | node /action/update-changelog
|
||||
|
||||
echo "INFO: Committing changelog..."
|
||||
git add CHANGELOG.md
|
||||
git -c user.name="$COMMIT_AUTHOR_NAME" -c user.email="$COMMIT_AUTHOR_EMAIL" \
|
||||
commit -m "Add $current_tag to CHANGELOG.md [skip ci]" --no-verify --quiet
|
||||
|
||||
echo "INFO: Pushing updates..."
|
||||
git push "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" master
|
||||
|
||||
echo "INFO: Done! Don't forget to thank new contributors :)"
|
||||
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
File diff suppressed because it is too large
Load Diff
@ -1,12 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
"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,
|
||||
draft: true,
|
||||
}))
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const getStdin = require("get-stdin");
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
|
||||
const { GITHUB_WORKSPACE } = process.env;
|
||||
|
||||
const INSERTION_POINT = "<!-- insert-new-changelog-here -->";
|
||||
const CHANGELOG = path.resolve(GITHUB_WORKSPACE, "CHANGELOG.md");
|
||||
|
||||
main();
|
||||
async function main() {
|
||||
let [stdin, changelog] = await Promise.all([
|
||||
getStdin(),
|
||||
fs.readFile(CHANGELOG, "utf8"),
|
||||
]);
|
||||
|
||||
if (!changelog.includes(INSERTION_POINT)) {
|
||||
throw new Error(`Missing "${INSERTION_POINT}" in CHANGELOG.md`);
|
||||
}
|
||||
|
||||
// Remove committers
|
||||
stdin = stdin.split("\n\n#### Committers")[0];
|
||||
changelog = changelog.replace(
|
||||
INSERTION_POINT,
|
||||
INSERTION_POINT + "\n" + stdin
|
||||
);
|
||||
|
||||
await fs.writeFile(CHANGELOG, changelog);
|
||||
}
|
||||
4
.github/main.workflow
vendored
4
.github/main.workflow
vendored
@ -9,7 +9,7 @@ action "Is version tag" {
|
||||
}
|
||||
|
||||
action "Is tag from master" {
|
||||
uses = "./commit-matches-branch/"
|
||||
uses = "babel/actions/commit-matches-branch@master"
|
||||
needs = [
|
||||
"Is version tag",
|
||||
]
|
||||
@ -17,7 +17,7 @@ action "Is tag from master" {
|
||||
}
|
||||
|
||||
action "Trigger GitHub release" {
|
||||
uses = "./trigger-github-release/"
|
||||
uses = "babel/actions/trigger-github-release@master"
|
||||
secrets = ["GITHUB_TOKEN"]
|
||||
env = {
|
||||
COMMIT_AUTHOR_NAME = "Babel Bot"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user