You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> ✨ A Github Action which sets the base and head SHAs required for `nx affected` commands in CI
7
+
8
+
-[Example Usage](#example-usage)
9
+
-[Configuration Options](#configuration-options)
10
+
-[Background](#background)
11
+
-[License](#license)
12
+
13
+
> This documentation is for version 2.x.x. You can find documentation for version 1.x.x [here](https://github.com/nrwl/nx-set-shas/blob/c8f5a54f6ee7f2127f3df063f36a0242faee4cb7/README.md).
- name: Derive appropriate SHAs for base and head for `nx affected` commands
38
50
id: setSHAs
39
-
uses: nrwl/nx-set-shas@v1
51
+
uses: nrwl/nx-set-shas@v2
52
+
with:
53
+
set-environment-variables-for-job: 'false'
40
54
41
55
- run: |
42
56
echo "BASE: ${{ steps.setSHAs.outputs.base }}"
@@ -58,22 +72,54 @@ jobs:
58
72
# Default: main
59
73
main-branch-name: ''
60
74
61
-
# The glob(7) pattern to be provided to `git describe --match` in order to match against
62
-
# the latest relevant tag on the specified "main" branch.
63
-
#
64
-
# The default pattern aligns with the default behavior of the complementary `nrwl/nx-tag-successful-ci-run` action.
65
-
#
66
-
# Default: nx_successful_ci_run*
67
-
tag-match-pattern: ''
68
-
69
75
# Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job.
70
76
#
71
77
# Default: true
72
78
set-environment-variables-for-job: ''
73
79
74
-
# By default, if no matching tags are found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead.
80
+
# By default, if no successful workflow run is found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead.
75
81
#
76
82
# Default: false
77
-
error-on-no-matching-tags: ''
83
+
error-on-no-successful-workflow: ''
84
+
85
+
# The ID of the github action workflow to check for successful run or the name of the file name containing the workflow.
86
+
# E.g. 'ci.yml'. If not provided, current workflow id will be used
87
+
#
88
+
workflow-id: ''
78
89
```
79
-
<!-- end configuration-options -->
90
+
<!-- end configuration-options -->
91
+
92
+
## Background
93
+
94
+
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
95
+
between those 2 commits](https://nx.dev/latest/angular/tutorial/11-test-affected-projects#step-11-test-affected-projects
96
+
). We can then run a set of tasks (like building or linting) only on those **affected** projects.
97
+
98
+
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.
99
+
100
+
101
+
### Problem
102
+
103
+
Figuring out what these two git commits are might not be as simple as it seems.
104
+
105
+
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.
106
+
107
+
But what if we want to set up a continuous deployment system
108
+
that, as changes get pushed to `master`, it builds and deploys
109
+
only the affected projects?
110
+
111
+
What are the `FROM` and `TO` commits in that case?
112
+
113
+
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.
114
+
115
+
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.
116
+
117
+
This action enables you to find:
118
+
* Commit SHA from which PR originated (in the case of `pull_request`)
119
+
* Commit SHA of the last successful CI run
120
+
121
+
## License
122
+
123
+
[MIT](http://opensource.org/licenses/MIT)
124
+
125
+
Copyright (c) 2021-present Narwhal Technologies Inc.
Copy file name to clipboardExpand all lines: action.yml
+12-13Lines changed: 12 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,17 @@
1
-
name: 'Nx set SHAs'
2
-
description: 'Derives appropriate SHAs for base and head for use in `nx affected` commands, optionally setting them as environment variables for the current job'
1
+
name: "Nx set SHAs"
2
+
description: "Derives appropriate SHAs for base and head for use in `nx affected` commands, optionally setting them as environment variables for the current job"
3
3
4
4
inputs:
5
5
main-branch-name:
6
-
description: 'The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc'
7
-
default: 'main'
8
-
tag-match-pattern:
9
-
description: 'The glob(7) pattern to be provided to `git describe --match` in order to match against the latest relevant tag on the specified main branch'
10
-
default: 'nx_successful_ci_run*'
6
+
description: "The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc"
7
+
default: "main"
11
8
set-environment-variables-for-job:
12
-
description: 'Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job'
13
-
default: 'true'
14
-
error-on-no-matching-tags:
15
-
description: 'By default, if no matching tags are found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead.'
9
+
description: "Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job"
10
+
default: "true"
11
+
error-on-no-successful-workflow:
12
+
description: "By default, if no successful workflow is found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead."
13
+
workflow-id:
14
+
description: "The ID of the workflow to track or name of the file name. E.g. ci.yml. Defaults to current workflow"
16
15
17
16
outputs:
18
17
base:
@@ -23,12 +22,12 @@ outputs:
23
22
value: ${{ steps.setSHAs.outputs.head }}
24
23
25
24
runs:
26
-
using: 'composite'
25
+
using: "composite"
27
26
steps:
28
27
- name: Set base and head SHAs used for nx affected
0 commit comments