Skip to content

Commit 8b116da

Browse files
authored
fix!: always resolve SHA against provided main branch (#64)
1 parent 5a9542b commit 8b116da

8 files changed

Lines changed: 2141 additions & 24 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Integration test workflow"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
main-branch-name:
7+
required: false
8+
type: string
9+
default: main
10+
runs-on:
11+
required: false
12+
type: string
13+
default: ubuntu-latest
14+
working-directory:
15+
required: false
16+
type: string
17+
18+
jobs:
19+
main:
20+
runs-on: ${{ inputs.runs-on }}
21+
name: Run
22+
defaults:
23+
run:
24+
shell: bash
25+
steps:
26+
- uses: actions/checkout@v2
27+
name: Checkout [Pull Request]
28+
if: ${{ github.event_name == 'pull_request' }}
29+
with:
30+
# By default, PRs will be checked-out based on the Merge Commit, but we want the actual branch HEAD.
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
33+
fetch-depth: 0
34+
35+
- uses: actions/checkout@v2
36+
name: Checkout [Default Branch]
37+
if: ${{ github.event_name != 'pull_request' }}
38+
with:
39+
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
40+
fetch-depth: 0
41+
42+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
43+
uses: ./
44+
with:
45+
main-branch-name: ${{ inputs.main-branch-name }}
46+
47+
- name: Verify default PR Workflow
48+
if: ${{ github.event_name == 'pull_request' }}
49+
run: |
50+
BASE_SHA=$(echo $(git merge-base origin/${{github.base_ref}} HEAD))
51+
HEAD_SHA=$(git rev-parse HEAD)
52+
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
53+
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
54+
55+
- name: Verify default Push Workflow
56+
if: ${{ github.event_name != 'pull_request' }}
57+
run: |
58+
BASE_SHA=$(echo $(git rev-parse HEAD~1))
59+
HEAD_SHA=$(echo $(git rev-parse HEAD))
60+
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
61+
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Test Integration"
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
pull_request:
8+
paths-ignore:
9+
- "**.md"
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
name: Test workflow integration
18+
strategy:
19+
matrix:
20+
runs-on: [ubuntu-latest, macos-latest, windows-latest]
21+
fail-fast: false
22+
uses: ./.github/workflows/integration-test-workflow.yml
23+
with:
24+
working-directory: integration-test
25+
main-branch-name: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
26+
runs-on: ${{ matrix.runs-on }}

.github/workflows/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "Test"
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
pull_request:
8+
paths-ignore:
9+
- "**.md"
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
name: Test
18+
strategy:
19+
matrix:
20+
runs-on: [ubuntu-latest, macos-latest, windows-latest]
21+
fail-fast: false
22+
runs-on: ${{ matrix.runs-on }}
23+
steps:
24+
- uses: actions/checkout@v2
25+
name: Checkout [Pull Request]
26+
if: ${{ github.event_name == 'pull_request' }}
27+
with:
28+
ref: ${{ github.event.pull_request.head.sha }}
29+
fetch-depth: 0
30+
31+
- uses: actions/checkout@v2
32+
name: Checkout [Push]
33+
if: ${{ github.event_name != 'pull_request' }}
34+
with:
35+
fetch-depth: 0
36+
37+
- name: Set Node.js 16.x
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version: 16
41+
42+
- name: Install
43+
run: npm ci
44+
45+
- name: Compile
46+
run: npm run build
47+
48+
- name: Test default PR Workflow
49+
if: github.event_name == 'pull_request'
50+
uses: ./
51+
with:
52+
main-branch-name: ${{ github.base_ref }}
53+
- name: Verify default PR Workflow
54+
if: github.event_name == 'pull_request'
55+
shell: bash
56+
run: |
57+
BASE_SHA=$(echo $(git merge-base origin/${{github.base_ref}} HEAD))
58+
HEAD_SHA=$(git rev-parse HEAD)
59+
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
60+
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
61+
62+
- name: Test default Push Workflow
63+
if: github.event_name != 'pull_request'
64+
uses: ./
65+
with:
66+
main-branch-name: ${{ github.ref_name }}
67+
- name: Verify default Push Workflow
68+
if: github.event_name != 'pull_request'
69+
shell: bash
70+
run: |
71+
BASE_SHA=$(echo $(git rev-parse HEAD~1))
72+
HEAD_SHA=$(echo $(git rev-parse HEAD))
73+
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
74+
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ width="100%" alt="Nx - Smart, Extensible Build Framework"></p>
1010
- [Background](#background)
1111
- [License](#license)
1212

13-
**NOTE:** This documentation is for version `2.x.x` which now uses the GitHub API to track successful workflows. You can find documentation for version `1.x.x` which used GIT tags [here](https://github.com/nrwl/nx-set-shas/blob/v1/README.md).
13+
**NOTE:** This documentation is for version `2.x.x+` which now uses the GitHub API to track successful workflows. You can find documentation for version `1.x.x` which used GIT tags [here](https://github.com/nrwl/nx-set-shas/blob/v1/README.md).
1414

1515
## Example Usage
1616

@@ -37,7 +37,7 @@ jobs:
3737
# OPTION 1) Environment variables
3838
# ===========================================================================
3939
- name: Derive appropriate SHAs for base and head for `nx affected` commands
40-
uses: nrwl/nx-set-shas@v2
40+
uses: nrwl/nx-set-shas@v3
4141

4242
- run: |
4343
echo "BASE: ${{ env.NX_BASE }}"
@@ -48,7 +48,7 @@ jobs:
4848
# ===========================================================================
4949
- name: Derive appropriate SHAs for base and head for `nx affected` commands
5050
id: setSHAs
51-
uses: nrwl/nx-set-shas@v2
51+
uses: nrwl/nx-set-shas@v3
5252

5353
- run: |
5454
echo "BASE: ${{ steps.setSHAs.outputs.base }}"
@@ -62,7 +62,7 @@ jobs:
6262

6363
<!-- start configuration-options -->
6464
```yaml
65-
- uses: nrwl/nx-set-shas@v2
65+
- uses: nrwl/nx-set-shas@v3
6666
with:
6767
# The "main" branch of your repository (the base branch which you target with PRs).
6868
# Common names for this branch include main and master.
@@ -97,7 +97,7 @@ jobs:
9797
```
9898
<!-- end configuration-options -->
9999
100-
## Permissions in v2
100+
## Permissions in v2+
101101
102102
This Action uses Github API to find the last successful workflow run. If your `GITHUB_TOKEN` has restrictions set please ensure you override them for the workflow to enable read access to `actions` and `contents`:
103103

0 commit comments

Comments
 (0)