Skip to content

Commit

Permalink
Publish to npm using a GitHub action (#9588)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 19, 2019
1 parent 60005b3 commit f2ee84b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .github/actions/create-release-tag/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions .github/actions/create-release-tag/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 1 addition & 9 deletions .github/actions/trigger-github-release/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
26 changes: 23 additions & 3 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
workflow "Release" {
on = "push"
resolves = ["Trigger GitHub release"]
resolves = ["Trigger GitHub release", "Publish to npm"]
}

action "Trigger GitHub release" {
Expand All @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,24 @@ 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
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
Expand Down

0 comments on commit f2ee84b

Please sign in to comment.