Publish to npm using a GitHub action (#9588)

This commit is contained in:
Nicolò Ribaudo 2019-03-19 18:59:35 +01:00 committed by GitHub
parent 60005b35e4
commit f2ee84b6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 14 deletions

View File

@ -0,0 +1,16 @@
FROM debian:stable-slim
LABEL "name"="create-release-tag"
LABEL "version"="0.0.1"
LABEL "com.github.actions.name"="Create release tag"
LABEL "com.github.actions.description"="Creates a release tag equal to the last commit message"
LABEL "com.github.actions.icon"="tag"
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

@ -0,0 +1,14 @@
#!/bin/sh
set -e
# GitHub doesn't support running actions on new tags yet: we need to run it on the commit.
# For this reason, we can't be sure that the tag already exists. We can use the commit
# message to create the tag. If the tag already exists locally, they won't conflict because
# they have the same name and are on the same commit.
echo "INFO: Getting release version..."
tag_name=$(git log --oneline --format=%B -1 $GITHUB_SHA)
echo "INFO: Creating new tag..."
(git tag $tag_name $GITHUB_SHA) || echo "INFO: Tag already exists"

View File

@ -5,16 +5,8 @@ set -e
echo "INFO: Installing action dependencies..."
(cd /action; npm ci)
# GitHub doesn't support running actions on new tags yet: we need to run it on the commit.
# For this reason, we can't be sure that the tag already exists. We can use the commit
# message to create the tag. If the tag already exists locally, they won't conflict because
# they have the same name and are on the same commit.
echo "INFO: Getting release version..."
# current_tag=$(git describe --abbrev=0 --tags $GITHUB_SHA)
current_tag=$(git log --oneline --format=%B -1 $GITHUB_SHA)
echo "INFO: Creating new tag..."
(git tag $current_tag $GITHUB_SHA) || echo "INFO: Tag already exists"
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."

24
.github/main.workflow vendored
View File

@ -1,6 +1,6 @@
workflow "Release" {
on = "push"
resolves = ["Trigger GitHub release"]
resolves = ["Trigger GitHub release", "Publish to npm"]
}
action "Trigger GitHub release" {
@ -12,8 +12,28 @@ action "Trigger GitHub release" {
COMMIT_AUTHOR_EMAIL = "babel@hopeinsource.com"
}
needs = ["Create release tag"]
}
action "Publish to npm" {
uses = "docker://node:10"
secrets = ["NPM_TOKEN"]
runs = "make"
args = "publish"
env = {
CI = "true"
}
needs = ["Create release tag"]
}
# When GitHub Actions will support the "release" event for public
# repositories, we won't need these checks anymore.
# repositories, we won't need this checks anymore.
action "Create release tag" {
uses ="./.github/actions/create-release-tag"
needs = [
"Is version commit",
"On master branch",

View File

@ -127,11 +127,12 @@ prepublish-build:
make clone-license
prepublish:
git pull --rebase
make bootstrap-only
make prepublish-build
make test
new-version:
git pull --rebase
./node_modules/.bin/lerna version --force-publish="@babel/runtime,@babel/runtime-corejs2,@babel/standalone,@babel/preset-env-standalone"
# NOTE: Run make new-version first
@ -139,9 +140,11 @@ publish: prepublish
./node_modules/.bin/lerna publish from-git --require-scripts
make clean
bootstrap: clean-all
bootstrap-only: clean-all
yarn --ignore-engines
./node_modules/.bin/lerna bootstrap -- --ignore-engines
bootstrap: bootstrap-only
make build
cd packages/babel-plugin-transform-runtime; \
node scripts/build-dist.js