Skip to content

Commit

Permalink
feat: run bootstrap (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard authored May 5, 2021
1 parent d4c0271 commit 1d3d975
Show file tree
Hide file tree
Showing 61 changed files with 5,068 additions and 751 deletions.
307 changes: 307 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
version: 2.1

commands:
with_job_span:
parameters:
steps:
type: steps
steps:
- run:
name: Creating span for job
command: |-
echo "STEP_START=$(date +%s)" >> $BASH_ENV
echo "STEP_SPAN_ID=$(echo $CIRCLE_JOB | sum | cut -f 1 -d \ )" >> $BASH_ENV
- steps: << parameters.steps >>
- run:
name: Finishing span for job
command: buildevents step "$CIRCLE_WORKFLOW_ID" "$STEP_SPAN_ID" "$STEP_START" "$CIRCLE_JOB"
when: always

jobs:
###Block(circleJobs)
###EndBlock(circleJobs)
send_traces:
docker:
- image: gcr.io/outreach-docker/buildevents:latest
auth:
username: _json_key
password: $GCLOUD_SERVICE_ACCOUNT
steps:
- run:
name: Watch for workflow to finish
command: /tmp/buildevents watch $CIRCLE_WORKFLOW_ID

test: # runs not using Workflows must have a build job as entry point
docker: # run the steps with Docker
# CircleCI Go images available at: https://hub.docker.com/r/cimg/go
- image: gcr.io/outreach-docker/bootstrap/testbed:1.16.2
auth:
username: _json_key
password: $GCLOUD_SERVICE_ACCOUNT
# directory where steps are run.
working_directory: ~/localizer

environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
GOPRIVATE: github.com/getoutreach/*
GOPROXY: https://proxy.golang.org
###Block(testEnvVars)
###EndBlock(testEnvVars)

steps: # steps that comprise the build job
- with_job_span:
steps:
# adds the ssh key that Wheatley put here for us. Ask Wheatley on slack to "setup circle for <project_name>"
# see https://outreach-io.atlassian.net/wiki/spaces/EN/pages/701596137/Services+Checklist for the setup process
- add_ssh_keys
- checkout
- run: mkdir -p $TEST_RESULTS # create the test results directory

- restore_cache: # restores saved cache if no changes are detected since last run
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
keys:
# looks for the cache for this go.sum
- v2-pkg-cache-{{ checksum "go.sum" }}
# fallback to the latest cached versions
- v2-pkg-cache-

# we make this a seperate step to prevent obscure SSH error messages
- run:
name: Install Dependencies
command: buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID install-go-dependencies -- make dep

- run:
name: Run unit tests
# Store the results of our tests in the $TEST_RESULTS directory
command:
buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID unit-tests --
make test | tee ${TEST_RESULTS}/go-test.out

- run:
name: Upload Code Coverage
command: |
if [[ -n "$COVERALLS_TOKEN" ]]; then
buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID upload-code-coverage -- \
goveralls -coverprofile=/tmp/coverage.out -service=circle-ci -repotoken=$COVERALLS_TOKEN;
fi
- save_cache:
key: v2-pkg-cache-{{ checksum "go.sum" }}
paths:
- "~/go/pkg"

- store_artifacts: # Upload test coverage for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
path: /tmp/coverage.out
destination: raw-coverage-profile

- store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
path: /tmp/test-results
destination: raw-test-output

- store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
path: /tmp/test-results

release-dryrun:
docker:
- image: gcr.io/outreach-docker/bootstrap/testbed:1.16.2
auth:
username: _json_key
password: $GCLOUD_SERVICE_ACCOUNT
environment:
GOPRIVATE: github.com/getoutreach/*
GOPROXY: https://proxy.golang.org
steps:
- with_job_span:
steps:
- setup_remote_docker:
docker_layer_caching: true
version: 19.03.13
- checkout
- add_ssh_keys
- run:
name: Setup npm Authentication
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Configuring Golang SSH
command: |-
git config --global url."[email protected]:".insteadOf "https://github.com/"
- restore_cache:
keys:
- v1-release-node-cache-{{ checksum "package.json" }}
- v1-release-node-cache-
- run:
name: Install semantic-release Dependencies
command: buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID install-sem-release-dependencies -- yarn --frozen-lockfile
- save_cache:
key: v1-release-node-cache-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Release (Dry-run)
command: |-
# Make https://github.com/pvdlg/env-ci/blob/master/services/circleci.js
# think we're not on a PR.
# Store these and set them after
OLD_CIRCLE_PR_NUMBER=$CIRCLE_PR_NUMBER
OLD_CIRCLE_PULL_REQUEST=$CIRCLE_PULL_REQUEST
OLD_CI_PULL_REQUEST=$CI_PULL_REQUEST
OLD_CIRCLE_BRANCH=$CIRCLE_BRANCH
# Fetch the API URL for usage later.
# 19 comes from the length of https://github.com/
export CIRCLE_PR_API_URL=$(echo "https://api.github.com/repos/${CIRCLE_PULL_REQUEST:19}" | sed "s/\/pull\//\/pulls\//")
# Remove evidence of us being on a PR.
unset CIRCLE_PR_NUMBER
unset CIRCLE_PULL_REQUEST
unset CI_PULL_REQUEST
# Fetch the base branch from the API, since CircleCI doesn't expose it.
export CIRCLE_BRANCH=$(curl -s -H "Authorization: token ${OUTREACH_GITHUB_TOKEN}" "$CIRCLE_PR_API_URL" | jq -r '.base.ref')
# Act like we're on the base branch.
git branch -D "$CIRCLE_BRANCH" || true
git checkout -b "$CIRCLE_BRANCH" || true
# Run the releaser now.
GH_TOKEN=$OUTREACH_GITHUB_TOKEN yarn --frozen-lockfile semantic-release --dry-run
export CIRCLE_PR_NUMBER=$OLD_CIRCLE_PR_NUMBER
export CIRCLE_PULL_REQUEST=$OLD_CIRCLE_PULL_REQUEST
export CI_PULL_REQUEST=$OLD_CI_PULL_REQUEST
export CIRCLE_BRANCH=$OLD_CIRCLE_BRANCH
release:
docker:
- image: gcr.io/outreach-docker/bootstrap/testbed:1.16.2
auth:
username: _json_key
password: $GCLOUD_SERVICE_ACCOUNT
environment:
GOPRIVATE: github.com/getoutreach/*
GOPROXY: https://proxy.golang.org
steps:
- with_job_span:
steps:
- setup_remote_docker:
docker_layer_caching: true
version: 19.03.13
- checkout
- add_ssh_keys
- run:
name: Setup npm Authentication
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Configuring Golang SSH
command: |-
git config --global url."[email protected]:".insteadOf "https://github.com/"
- restore_cache:
keys:
- v1-release-node-cache-{{ checksum "package.json" }}
- v1-release-node-cache-
- run:
name: Install semantic-release Dependencies
command: buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID install-sem-release-dependencies -- yarn --frozen-lockfile
- save_cache:
key: v1-release-node-cache-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Release
command: |
export GH_TOKEN=$OUTREACH_GITHUB_TOKEN
buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID semantic-release -- yarn --frozen-lockfile semantic-release
trigger_documentation:
docker:
- image: gcr.io/outreach-docker/bootstrap/testbed:1.16.2
auth:
username: _json_key
password: $GCLOUD_SERVICE_ACCOUNT
steps:
- with_job_span:
steps:
- add_ssh_keys
- checkout

# This is needed to download dependencies, which go list needs for some reason.
- restore_cache:
keys:
- v2-pkg-cache-{{ checksum "go.sum" }}
- v2-pkg-cache-
- run:
name: Install Dependencies
command: buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID install-go-dependencies -- make dep
- save_cache:
key: v2-pkg-cache-{{ checksum "go.sum" }}
paths:
- "~/go/pkg"

- run:
name: Trigger Documentation Update
command: |-
TAG="$CIRCLE_TAG"
if [[ -z "$TAG" ]]; then
# Calculate the psuedo-semver tag, this is used for non-v2 services
# (things without semantic-release, generally)
TAG="v0.0.0-$(TZ=UTC git --no-pager show --quiet --abbrev=12 --date='format-local:%Y%m%d%H%M%S' --format='%cd-%h')"
fi
# We need to use the module path to support major versions properly
MODULE_PATH="$(go list -f '{{ .Path }}' -m)"
URL="https://engdocs.outreach.cloud/fetch/$MODULE_PATH@$TAG"
buildevents cmd $CIRCLE_WORKFLOW_ID $STEP_SPAN_ID deploy-docs -- curl -X POST "$URL"
workflows:
version: 2
###Block(circleWorkflows)
###EndBlock(circleWorkflows)
build_and_test:
jobs:
- send_traces:
context:
- docker-registry
- buildevents
###Block(circleWorkflowJobs)
###EndBlock(circleWorkflowJobs)
- release:
context:
- docker-registry
- buildevents
- npm-credentials
requires:
- test
filters:
branches:
only:
- master
- main
- release-dryrun:
context:
- docker-registry
- buildevents
- npm-credentials
filters:
branches:
ignore:
- master
- main
- test:
context:
- docker-registry
- buildevents
filters:
# This enables running test when a tag is created.
# This still runs on each branch.
tags:
only: /v\d+(\.\d+)*(-.*)*/
- trigger_documentation:
context:
- docker-registry
- buildevents
filters:
branches:
ignore: /.*/
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
Language: Proto
BasedOnStyle: google
PenaltyBreakAssignment: 10000
PenaltyBreakComment: 0
ColumnLimit: 140
AlignConsecutiveAssignments: true
ReflowComments: true
BreakBeforeBinaryOperators: None
---

10 changes: 6 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ insert_final_newline = true
[Makefile]
indent_style = tab

[*.{yml,yaml}]
indent_style = space
[*.go]
indent_style = tab
indent_size = 2

[*.{sh,bash}]
[*.{bash,rb,sh,slim,yml,yaml}]
indent_style = space
indent_size = 2
Terms

###Block(editorconfig)
###EndBlock(editorconfig)
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
go.sum linguist-generated
*_pb.d.ts linguist-generated
*.pb.go linguist-generated
*_pb.js linguist-generated
*_pb.rb linguist-generated
internal/ent linguist-generated
internal/ent/schema/*.go -text diff=golang
bootstrap.lock linguist-generated
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- !!!! README !!!! Please fill this out. -->


<!-- A short description of what your PR does and what it solves. -->
**What this PR does / why we need it**:

**JIRA ID**: XX-XX

<!-- Notes that may be helpful for anyone reviewing this PR -->
**Notes for your reviewer**:
27 changes: 0 additions & 27 deletions .github/workflows/build.yaml

This file was deleted.

Loading

0 comments on commit 1d3d975

Please sign in to comment.