Extract release actions to babel/actions

This commit is contained in:
Nicolò Ribaudo 2019-07-20 16:43:22 +02:00
parent fb910e063c
commit 9bc9571381
No known key found for this signature in database
GPG Key ID: 6F2E38DF3E4A6D0C
9 changed files with 2 additions and 1572 deletions

View File

@ -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"]

View File

@ -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

View File

@ -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"]

View File

@ -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 :)"

File diff suppressed because it is too large Load Diff

View File

@ -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"
}
}

View File

@ -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);
});

View File

@ -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);
}

View File

@ -9,7 +9,7 @@ action "Is version tag" {
} }
action "Is tag from master" { action "Is tag from master" {
uses = "./commit-matches-branch/" uses = "babel/actions/commit-matches-branch@master"
needs = [ needs = [
"Is version tag", "Is version tag",
] ]
@ -17,7 +17,7 @@ action "Is tag from master" {
} }
action "Trigger GitHub release" { action "Trigger GitHub release" {
uses = "./trigger-github-release/" uses = "babel/actions/trigger-github-release@master"
secrets = ["GITHUB_TOKEN"] secrets = ["GITHUB_TOKEN"]
env = { env = {
COMMIT_AUTHOR_NAME = "Babel Bot" COMMIT_AUTHOR_NAME = "Babel Bot"