From f2ee84b6a3a829fffa1e84d17977c36d0049e08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 19 Mar 2019 18:59:35 +0100 Subject: [PATCH] Publish to npm using a GitHub action (#9588) --- .github/actions/create-release-tag/Dockerfile | 16 ++++++++++++ .../actions/create-release-tag/entrypoint.sh | 14 ++++++++++ .../trigger-github-release/entrypoint.sh | 10 +------ .github/main.workflow | 26 ++++++++++++++++--- Makefile | 7 +++-- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 .github/actions/create-release-tag/Dockerfile create mode 100644 .github/actions/create-release-tag/entrypoint.sh diff --git a/.github/actions/create-release-tag/Dockerfile b/.github/actions/create-release-tag/Dockerfile new file mode 100644 index 0000000000..58c743a3d5 --- /dev/null +++ b/.github/actions/create-release-tag/Dockerfile @@ -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"] diff --git a/.github/actions/create-release-tag/entrypoint.sh b/.github/actions/create-release-tag/entrypoint.sh new file mode 100644 index 0000000000..225797f397 --- /dev/null +++ b/.github/actions/create-release-tag/entrypoint.sh @@ -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" diff --git a/.github/actions/trigger-github-release/entrypoint.sh b/.github/actions/trigger-github-release/entrypoint.sh index 11c7f193e3..b284b6289d 100755 --- a/.github/actions/trigger-github-release/entrypoint.sh +++ b/.github/actions/trigger-github-release/entrypoint.sh @@ -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." diff --git a/.github/main.workflow b/.github/main.workflow index 1a6c5a4058..feedcc4d82 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -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" } - # When GitHub Actions will support the "release" event for public - # repositories, we won't need these checks anymore. + 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 this checks anymore. +action "Create release tag" { + uses ="./.github/actions/create-release-tag" + needs = [ "Is version commit", "On master branch", diff --git a/Makefile b/Makefile index 1a52c4cef8..df0e3388f3 100644 --- a/Makefile +++ b/Makefile @@ -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