-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathorb.yaml
78 lines (66 loc) · 2.79 KB
/
orb.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
version: 2.1
description: |
Multirepo and monorepo support for CircleCI.
Source: https://github.com/dnephin/multirepo-orb
Use the `multiorb/run-job-for-paths` command in each job that should be
run when the paths change. Only the job itself will be halted, so all
subsequent jobs in the workflow must call the same command.
commands:
run-job-for-paths:
description: |
Continue running the job if any file in paths has been modified since
the last commit shared with the upstream git branch (default: origin/master).
This command must be run after `checkout`.
This command allows you to skip all of the subsequent steps in a job so that any
repository with multiple workflows, or multiple flows within a single
workflow, will only run CI jobs relevant to the files that changed.
If you have a multipurpose git repository with independent directory trees
this command allows you to run the tests for only the services which have been
modified relative to the upstream branch.
parameters:
paths:
type: string
description: |
A list of file paths used with 'git diff' to check for modification.
upstream_branch:
type: string
description: |
The upstream branch used with 'git merge-base' to find the most recent
commit shared by HEAD and the upstream branch.
default: origin/master
working_directory:
type: string
description: |
Directory to change to before executing the command.
default: "$PWD"
run_on_upstream:
type: boolean
description: |
When run_on_upstream is true, and HEAD matches the upstream_branch the
job always run. When false the job will not run when HEAD matches
the upstream_branch.
default: true
steps:
- run:
name: Check if job should run
command: |
cd << parameters.working_directory >>
upstream="$(git merge-base HEAD << parameters.upstream_branch >>)"
echo "Comparing to upstream commit $upstream"
<<# parameters.run_on_upstream >>
if [[ "$(git rev-parse HEAD)" == "$upstream" ]]; then
echo "HEAD matches upstream, running with no diff"
exit 0
fi
<</ parameters.run_on_upstream >>
if [[ -z "$upstream" ]]; then
echo "git merge-base failed"
exit 1
fi
# Print the diff
PAGER=cat git diff --stat=80 $upstream -- << parameters.paths >>
# Halt if no diff
if git diff --quiet $upstream -- << parameters.paths >>; then
echo "Skipping job, no files modified"
circleci-agent step halt
fi