Skip to content

Commit

Permalink
[semver:major] feat: add set-shas command (#1)
Browse files Browse the repository at this point in the history
* feat: set-sha-command

* [semver: major]: feat: add set-shas command

* [semver: skip]: docs: update readme

* feat(set-shas): move all logic to node script

* feat(set-shas): add sha information to output

* feat(set-shas): update examples

* docs(set-shas): add usage to README.md

* fix(set-shas): remove bats reference

* fix(set-shas): remove shellcheck

* fix: command structure

* feat(circleci): extract project slug from build url

* chore(circleci): update path

* chore(circleci): include script

* chore(circleci): inject script
  • Loading branch information
meeroslav authored Jul 23, 2021
1 parent 0e8ac46 commit dc3ca82
Show file tree
Hide file tree
Showing 24 changed files with 322 additions and 415 deletions.
33 changes: 0 additions & 33 deletions .circleci/README.md

This file was deleted.

44 changes: 12 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,43 @@
version: 2.1

orbs:
# Replace this with your own!
nx: nrwl/nx@<<pipeline.parameters.dev-orb-version>>
orb-tools: circleci/orb-tools@10.0
bats: circleci/bats@1.0
shellcheck: circleci/shellcheck@2.0

# Pipeline Parameters
## These parameters are used internally by orb-tools. Skip to the Jobs section.
parameters:
# These pipeline parameters are required by the "trigger-integration-tests-workflow"
# job, by default.
run-integration-tests:
description: An internal flag to prevent integration test from running before a development version has been created.
type: boolean
default: false
dev-orb-version:
description: >
The development version of the orb to test.
This value is automatically adjusted by the "trigger-integration-tests-workflow" job to correspond with the specific version created by the commit and should not be edited.
A "dev:alpha" version must exist for the initial pipeline run.
type: string
default: "dev:alpha"

jobs:
# Define one or more jobs which will utilize your orb's commands and parameters to validate your changes.
integration-test-1:
set-shas-integration-test:
docker:
- image: cimg/base:stable
- image: cimg/node:14.17
steps:
- checkout
# "greet" is a sample command packaged with this orb config.
# This sample integration test will run as long as the greet command exists. Once you remove the greet command you should remove this line.
# Push new changes first, before adding new tests to your config.
- nx/greet
- nx/set-shas

workflows:
# Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
# This workflow will run on every commit
test-pack:
unless: << pipeline.parameters.run-integration-tests >>
jobs:
- orb-tools/lint # Lint Yaml files
- orb-tools/pack # Pack orb source
- shellcheck/check:
dir: ./src/scripts
exclude: SC2148
# optional: Run BATS tests against your scripts
- bats/run:
path: ./src/tests
- orb-tools/lint
- orb-tools/pack:
use-orb-pack: true
# Publish development version(s) of the orb.
- orb-tools/publish-dev:
orb-name: nrwl/nx
context: orb-publishing # A restricted context containing your private publishing credentials. Will only execute if approved by an authorized user.
requires:
- orb-tools/lint
- orb-tools/pack
- bats/run
- shellcheck/check
# Trigger an integration workflow to test the
# dev:${CIRCLE_SHA1:0:7} version of your orb
- orb-tools/trigger-integration-tests-workflow:
Expand All @@ -73,7 +54,7 @@ workflows:
when: << pipeline.parameters.run-integration-tests >>
jobs:
# Run any integration tests defined within the `jobs` key.
- integration-test-1
- set-shas-integration-test
# Publish a semver version of the orb. relies on
# the commit subject containing the text "[semver:patch|minor|major|skip]"
# as that will determine whether a patch, minor or major
Expand All @@ -83,13 +64,12 @@ workflows:
- orb-tools/dev-promote-prod-from-commit-subject:
orb-name: nrwl/nx
context: orb-publishing
add-pr-comment: false
add-pr-comment: true
fail-if-semver-not-indicated: true
publish-version-tag: false
publish-version-tag: true
requires:
- integration-test-1
- set-shas-integration-test
filters:
branches:
only:
- master
- main
Binary file added .github/assets/nx-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/assets/nx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Contributing to nx-orb

We welcome [issues](https://github.com/nrwl/nx-orb/issues) to and [pull requests](https://github.com/nrwl/nx-orb/pulls) against this repository! Read this document to see how to do it.

## How to Contribute
* Create and push a branch with your new features.
* When ready to publish a new production version, create a Pull Request from _feature branch_ to `master`.
* The title of the pull request should follow [commit message guideline](#commit-message-guideline)
* Squash and merge. Ensure the semver tag is preserved and entered as a part of the commit message.
* On merge, after manual approval, the orb will automatically be published to the Orb Registry.

#### Commit Message Guidelines

The commit message should follow the following format:

```
[semver:<segment>] type: subject
BLANK LINE
body
```

##### Semver tag

The title of the pull request must contain a special semver tag: `[semver:<segment>]` where `<segment>` is replaced by one of the following values.

| Increment | Description|
| ----------| -----------|
| major | Issue a 1.0.0 incremented release|
| minor | Issue a x.1.0 incremented release|
| patch | Issue a x.x.1 incremented release|
| skip | Do not issue a release|

Example: `[semver:major]`

##### Type

The type must be one of the following:

- feat - New or improved behavior being introduced (e.g. adding new command)
- fix - Fixes the current unexpected behavior to match expected behavior (e.g. fixing the wrong commit search logic)
- cleanup - Code Style changes that have little to no effect on the user (e.g. Refactoring some function)
- docs - Changes to the documentation (e.g. Adding more details into the examples)
- chore - Changes that have absolutely no effect on users (e.g. Renaming files)

Optionally, type can have a scope (e.g. `feat(set-shas)`)

##### Subject and Body

The subject must contain a description of the change, and the body of the message contains any additional details to provide more context about the change.

Including the issue number that the PR relates to also helps with tracking.

##### Example

```
[semver:minor] feat(set-shas): add optinal workflow-id
Add workflow-id to filter successful workflows
Closes #157
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 <organization>
Copyright (c) 2021 Narwhal Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
72 changes: 50 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
# Orb Project Template
<p style="text-align: center;"><img src=".github/assets/nx.png"
width="100%" alt="Nx - Smart, Extensible Build Framework"></p>

<h1 align="center">NX Orb</h2>

[![CircleCI Build Status](https://circleci.com/gh/nrwl/nx-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/nrwl/nx-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/nrwl/nx.svg)](https://circleci.com/orbs/registry/orb/nrwl/nx) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/nrwl/nx-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)


> ✨ A CircleCI Orb which includes helpful commands for running Nx commands in the CI
## Usage

```yaml
version: 2.1

orbs:
nx: nrwl/nx@1.0.0

A starter template for orb projects. Build, test, and publish orbs automatically on CircleCI with [Orb-Tools](https://circleci.com/orbs/registry/orb/circleci/orb-tools).
jobs:
checks:
docker:
- image: cimg/node:14.17-browsers
steps:
- checkout
- run:
name: Install dependencies
command: yarn install --frozen-lockfile
- nx/set-shas
- run:
name: Run Builds
command: yarn nx affected --target=build --base=$NX_BASE --parallel
- run:
name: Run Unit Tests
command: yarn nx affected --target=test --base=$NX_BASE --parallel
```
Additional READMEs are available in each directory.
## Background
When we run `affected` command on [Nx](https://nx.dev/), we can specify 2 git history positions - base and head, and it calculates [which projects in your repository changed
between those 2 commits](https://nx.dev/latest/angular/tutorial/11-test-affected-projects#step-11-test-affected-projects
). We can then run a set of tasks (like building or linting) only on those **affected** projects.

This makes it easy to set-up a CI system that scales well with the continous growth of your repository, as you add more and more projects.

## Resources
### Problem

[CircleCI Orb Registry Page](https://circleci.com/orbs/registry/orb/nrwl/nx-orb) - The official registry page of this orb for all versions, executors, commands, and jobs described.
[CircleCI Orb Docs](https://circleci.com/docs/2.0/orb-intro/#section=configuration) - Docs for using and creating CircleCI Orbs.
Figuring out what these two git commits are might not be as simple as it seems.

### How to Contribute
On a CI system that runs on submitted PRs, we determine what commits to include in the **affected** calculation by comparing our `HEAD-commit-of-PR-branch` to the commit in main branch (`master` or `main` usually) from which the PR branch originated. This will ensure the entirety of our PR is always being tested.

We welcome [issues](https://github.com/nrwl/nx-orb/issues) to and [pull requests](https://github.com/nrwl/nx-orb/pulls) against this repository!
But what if we want to set up a continuous deployment system
that, as changes get pushed to `master`, it builds and deploys
only the affected projects?

### How to Publish
* Create and push a branch with your new features.
* When ready to publish a new production version, create a Pull Request from _feature branch_ to `master`.
* The title of the pull request must contain a special semver tag: `[semver:<segment>]` where `<segment>` is replaced by one of the following values.
What are the `FROM` and `TO` commits in that case?

| Increment | Description|
| ----------| -----------|
| major | Issue a 1.0.0 incremented release|
| minor | Issue a x.1.0 incremented release|
| patch | Issue a x.x.1 incremented release|
| skip | Do not issue a release|
Conceptually, what we want is to use the absolute latest commit on the `master` branch as the HEAD, and the previous _successful_ commit on `master` as the BASE. Note, we want the previous _successful_ one because it is still possible for commits on the `master` branch to fail for a variety of reasons.

Example: `[semver:major]`
The commits therefore can't just be `HEAD` and `HEAD~1`. If a few deployments fail one after another, that means that we're accumulating a list of affected projects that are not getting deployed. Anytime we retry the deployment, we want to include **every commit since the last time we deployed successfully**. That way we ensure we don't accidentally skip deploying a project that has changed.

* Squash and merge. Ensure the semver tag is preserved and entered as a part of the commit message.
* On merge, after manual approval, the orb will automatically be published to the Orb Registry.
This action enables you to find:
* Commit SHA from which PR originated (in the case of `pull_request`)
* Commit SHA of the last successful CI run

## License

For further questions/comments about this or other orbs, visit the Orb Category of [CircleCI Discuss](https://discuss.circleci.com/c/orbs).
[MIT](http://opensource.org/licenses/MIT)

Copyright (c) 2021-present Narwhal Technologies Inc.
13 changes: 3 additions & 10 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
version: 2.1

description: >
Sample orb description
# What will your orb allow users to accomplish?
# Descriptions should be short, simple, and informative.
A Orb which includes helpful commands for running Nx commands in the CI
# This information will be displayed in the orb registry and is not mandatory.
display:
home_url: "https://www.website.com/docs"
source_url: "https://www.github.com/EXAMPLE_ORG/EXAMPLE_PROJECT"

# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
# orbs:
# hello: circleci/hello-build@0.0.5
home_url: "https://nx.dev/"
source_url: "https://github.com/nrwl/nx-orb"
27 changes: 0 additions & 27 deletions src/commands/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions src/commands/greet.yml

This file was deleted.

Loading

0 comments on commit dc3ca82

Please sign in to comment.