Skip to content

Commit

Permalink
feat(circleci-orb): initial setup for publishing dev-infra orb
Browse files Browse the repository at this point in the history
Initial setup for publihsing an dev-infra orb.
  • Loading branch information
devversion committed May 24, 2022
1 parent a53d820 commit acf5173
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ng-dev/commit-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export const commitMessage: CommitMessageConfig = {
...buildScopesFor('apps', []),
...buildScopesFor('tslint-rules', []),
...buildScopesFor('shared-scripts', []),
...buildScopesFor('circleci-orb', []),
],
};
2 changes: 2 additions & 0 deletions circleci-orb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file will be generated by the publish script.
packed-orb.yml
7 changes: 7 additions & 0 deletions circleci-orb/@orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2.1

description: Angular Dev-Infra Private Orb

display:
home_url: 'https://angular.io'
source_url: 'https://github.com/angular/dev-infra'
20 changes: 20 additions & 0 deletions circleci-orb/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ORB_NAME = "angular/dev-infra"

ORB_VERSION = "dev:0.0.1"

filegroup(
name = "orb_generated_files",
srcs = [
"//circleci-orb/scripts/rebase-on-target-branch:script",
],
)

sh_binary(
name = "publish",
srcs = ["publish.sh"],
args = [
ORB_NAME,
ORB_VERSION,
],
data = [":orb_generated_files"],
)
18 changes: 18 additions & 0 deletions circleci-orb/commands/rebase-on-target-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
description: Rebase PR on the target branch

parameters:
branch:
type: string
description: The `pipeline.git.branch` pipeline value.
base_revision:
type: string
description: The `pipeline.git.base_revision` pipeline value.

steps:
- run:
environment:
CIRCLE_BASE_REVISION: << parameters.base_revision >>
CIRCLE_BRANCH: << parameters.branch >>

name: Rebasing PR on the target branch
command: << include(../dist/bin/circleci-orb/scripts/rebase-on-target-branch/script.sh) >>
20 changes: 20 additions & 0 deletions circleci-orb/index.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Helper rules for building CircleCI orbs with the help of Bazel."""

def nodejs_script_to_sh_script(name, output_file, bundle_file):
"""Rule that takes a NodeJS script and wraps it into a Bash script.
This is useful for inclusion in CircleCI `run` commands in Orbs because
there cannot be an external NodeJS script file, or direct NodeJS `run` commands.
"""
native.genrule(
name = name,
srcs = [bundle_file],
outs = [output_file],
cmd = """
touch $@
echo '(cat <<"EOF" ' >> $@
cat $< >> $@
echo 'EOF' >> $@
echo ') | node' >> $@
""",
)
17 changes: 17 additions & 0 deletions circleci-orb/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

orbName=${1}
orbVersion=${2}

cd ${BUILD_WORKSPACE_DIRECTORY}/circleci-orb

# Pack the Orb (i.e. inline the built scripts etc.)
circleci orb pack $PWD > $PWD/packed-orb.yml

# Print the packed ORB for debugging/sanity check.
cat $PWD/packed-orb.yml

read -p "Do you want to proceed publishing? (press any key to continue)" -n 1 -r

# Run the publish with the provided version and orb name.
circleci orb publish $PWD/packed-orb.yml "${orbName}@${orbVersion}"
24 changes: 24 additions & 0 deletions circleci-orb/scripts/rebase-on-target-branch/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("//tools:defaults.bzl", "esbuild", "ts_library")
load("//circleci-orb:index.bzl", "nodejs_script_to_sh_script")

package(default_visibility = ["//circleci-orb:__subpackages__"])

ts_library(
name = "rebase-on-target-branch",
srcs = ["index.ts"],
deps = ["@npm//@types/node"],
)

esbuild(
name = "bundle",
entry_point = "index.ts",
format = "iife",
sourcemap = "inline",
deps = [":rebase-on-target-branch"],
)

nodejs_script_to_sh_script(
name = "script",
bundle_file = ":bundle.js",
output_file = "script.sh",
)
6 changes: 6 additions & 0 deletions circleci-orb/scripts/rebase-on-target-branch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node

const circleBaseRevision = process.env.CIRCLE_BASE_REVISION;
const circleBranch = process.env.CIRCLE_BRANCH;

console.error('Works', circleBaseRevision, circleBranch);

0 comments on commit acf5173

Please sign in to comment.