Skip to content

Commit 14280ef

Browse files
committed
Describe a way of debugging this action
1 parent 4b9348d commit 14280ef

File tree

4 files changed

+124
-98
lines changed

4 files changed

+124
-98
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
name: 'build-test'
2-
on: # rebuild any PRs and main branch changes
3-
pull_request:
4-
push:
5-
branches:
6-
- main
7-
- 'releases/*'
8-
9-
jobs:
10-
build: # make sure build/ci work properly
11-
runs-on: ubuntu-latest
12-
steps:
1+
name: 'build-test'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/*'
8+
9+
jobs:
10+
build: # make sure build/ci work properly
11+
runs-on: ubuntu-latest
12+
steps:
1313
- uses: actions/checkout@v3
14-
- run: |
15-
npm ci
16-
- run: |
17-
npm run all
18-
- name: Verify no unstaged changes
19-
run: __test__/verify-no-unstaged-changes.sh
14+
- run: |
15+
npm ci
16+
- run: |
17+
npm run all
18+
- name: Verify no unstaged changes
19+
run: __test__/verify-no-unstaged-changes.sh
2020

21-
test: # make sure the action works on a clean machine without building
22-
runs-on: ubuntu-latest
23-
steps:
21+
test: # make sure the action works on a clean machine without building
22+
runs-on: ubuntu-latest
23+
steps:
2424
- uses: actions/checkout@v3
25-
- uses: ./
25+
- uses: ./
2626

27+
dump-event:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/upload-artifact@v3
31+
with:
32+
name: github-context
33+
path: ${{github.event_path}}
2734

28-
pr-build-test:
29-
runs-on: ubuntu-latest
30-
if: ${{ github.event_name == 'pull_request' }}
31-
steps:
35+
pr-build-test:
36+
runs-on: ubuntu-latest
37+
if: ${{ github.event_name == 'pull_request' }}
38+
steps:
3239
- uses: actions/checkout@v3
3340
- uses: actions/setup-node@v3
34-
with:
41+
with:
3542
node-version: '16'
36-
- run: |
37-
npm ci
38-
- run: |
39-
npm run build
40-
- uses: ./
43+
- run: |
44+
npm ci
45+
- run: |
46+
npm run build
47+
- uses: ./

README.md

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,73 @@
1-
<p align="center">
2-
<a href="https://github.com/AurorNZ/report-updated-dependencies/actions"><img alt="report-updated-dependencies status" src="https://github.com/AurorNZ/report-updated-dependencies/workflows/build-test/badge.svg"></a>
3-
</p>
4-
5-
# Report updated dependencies
6-
7-
This Github Actions runs on changes to PR requests to detect and report changes made to dependencies.
8-
Dependency lookups, change detections and fetching of release notes are all done by [Renovate Bot](https://github.com/renovatebot/renovate)
9-
10-
```yml
11-
name: 'build-test'
12-
on:
13-
pull_request:
14-
15-
jobs:
16-
report-updated-dependencies:
17-
runs-on: ubuntu-latest
18-
steps:
19-
- uses: actions/checkout@v2
20-
- uses: AurorNZ/report-updated-dependencies@v1
21-
```
22-
23-
or run conditionally
24-
25-
```yml
26-
name: 'build-test'
27-
on: # rebuild any PRs and main branch changes
28-
pull_request:
29-
push:
30-
branches:
31-
- main
32-
- 'releases/*'
33-
34-
jobs:
35-
report-updated-dependencies:
36-
if: ${{ github.event_name == 'pull_request' }}
37-
runs-on: ubuntu-latest
38-
steps:
39-
- uses: actions/checkout@v2
40-
- uses: AurorNZ/report-updated-dependencies@v1
41-
```
42-
43-
## Publish to a distribution branch
44-
45-
Actions are run from GitHub repos so we will checkin the packed dist folder.
46-
47-
Then run [ncc](https://github.com/zeit/ncc) and push the results:
48-
49-
```bash
50-
$ npm run package
51-
$ git add dist
52-
$ git commit -a -m "prod dependencies"
53-
$ git push origin releases/v1
54-
```
55-
56-
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
57-
58-
Your action is now published! :rocket:
59-
60-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
1+
<p align="center">
2+
<a href="https://github.com/AurorNZ/report-updated-dependencies/actions"><img alt="report-updated-dependencies status" src="https://github.com/AurorNZ/report-updated-dependencies/workflows/build-test/badge.svg"></a>
3+
</p>
4+
5+
# Report updated dependencies
6+
7+
This Github Actions runs on changes to PR requests to detect and report changes made to dependencies.
8+
Dependency lookups, change detections and fetching of release notes are all done by [Renovate Bot](https://github.com/renovatebot/renovate)
9+
10+
```yml
11+
name: 'build-test'
12+
on:
13+
pull_request:
14+
15+
jobs:
16+
report-updated-dependencies:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: AurorNZ/report-updated-dependencies@v1
21+
```
22+
23+
or run conditionally
24+
25+
```yml
26+
name: 'build-test'
27+
on: # rebuild any PRs and main branch changes
28+
pull_request:
29+
push:
30+
branches:
31+
- main
32+
- 'releases/*'
33+
34+
jobs:
35+
report-updated-dependencies:
36+
if: ${{ github.event_name == 'pull_request' }}
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: AurorNZ/report-updated-dependencies@v1
41+
```
42+
43+
## Publish to a distribution branch
44+
45+
Actions are run from GitHub repos so we will checkin the packed dist folder.
46+
47+
Then run [ncc](https://github.com/zeit/ncc) and push the results:
48+
49+
```bash
50+
$ npm run package
51+
$ git add dist
52+
$ git commit -a -m "prod dependencies"
53+
$ git push origin releases/v1
54+
```
55+
56+
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
57+
58+
Your action is now published! :rocket:
59+
60+
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
61+
62+
63+
## Debugging
64+
- Create a pull request, ideally with commits that update dependencies
65+
- Download the `github-context` artifact from Github Actions run for the PR. That artifact should have the JSON file with the context of the Github event.
66+
- Put the `event.json` file into the root of this repository
67+
- Add the following code to `.env` file
68+
```
69+
GITHUB_EVENT_NAME=pull_request
70+
GITHUB_EVENT_PATH=event.json
71+
INPUT_TOKEN=<YOUR_GITHUB_TOKEN>
72+
```
73+
- Hit F5 in VSCode to start debugging

src/getRunContext.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ export function getRunContext(): RunContext {
1616
case 'pull_request': {
1717
const pullRequestPayload = context.payload
1818

19-
const {
20-
pull_request: {number: pullRequestNumber} = {}
21-
} = pullRequestPayload
19+
const {pull_request} = pullRequestPayload
20+
if (!pull_request) {
21+
throw new Error(
22+
'Github event is malformed, expected pull_request context on pull_request event'
23+
)
24+
}
25+
26+
const {number: pullRequestNumber, merge_commit_sha} = pull_request
2227

2328
return {
2429
// github actions usually checkout merge commits when PR is merge into the target branch
2530
// `${context.sha}^` will get the first parent commit ßwhich will me the head of target branch for this PR
26-
baseRef: `${context.sha}^`,
27-
headRef: context.sha,
31+
baseRef: `${merge_commit_sha}^`,
32+
headRef: merge_commit_sha,
2833
pullRequestNumber,
2934
repo
3035
}
@@ -35,7 +40,7 @@ export function getRunContext(): RunContext {
3540

3641
return {
3742
baseRef: pushPayload.before,
38-
headRef: context.sha,
43+
headRef: pushPayload.after,
3944
repo
4045
}
4146
}

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async function run(): Promise<void> {
8484

8585
const commentBody = getPrCommentBody(updatedDependencies)
8686

87+
core.info(`Ensuring the PR comment is up to date`)
8788
await upsertPrComment(
8889
github,
8990
repo,

0 commit comments

Comments
 (0)