Skip to content

Commit

Permalink
Describe a way of debugging this action
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Dann committed May 2, 2023
1 parent 4b9348d commit 14280ef
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 98 deletions.
71 changes: 39 additions & 32 deletions .github/workflows/test.yml
@@ -1,40 +1,47 @@
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
npm ci
- run: |
npm run all
- name: Verify no unstaged changes
run: __test__/verify-no-unstaged-changes.sh
- run: |
npm ci
- run: |
npm run all
- name: Verify no unstaged changes
run: __test__/verify-no-unstaged-changes.sh

test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
- uses: ./

dump-event:
runs-on: ubuntu-latest
steps:
- uses: actions/upload-artifact@v3
with:
name: github-context
path: ${{github.event_path}}

pr-build-test:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
pr-build-test:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
with:
node-version: '16'
- run: |
npm ci
- run: |
npm run build
- uses: ./
- run: |
npm ci
- run: |
npm run build
- uses: ./
133 changes: 73 additions & 60 deletions README.md
@@ -1,60 +1,73 @@
<p align="center">
<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>
</p>

# Report updated dependencies

This Github Actions runs on changes to PR requests to detect and report changes made to dependencies.
Dependency lookups, change detections and fetching of release notes are all done by [Renovate Bot](https://github.com/renovatebot/renovate)

```yml
name: 'build-test'
on:
pull_request:

jobs:
report-updated-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: AurorNZ/report-updated-dependencies@v1
```

or run conditionally

```yml
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
report-updated-dependencies:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: AurorNZ/report-updated-dependencies@v1
```

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:

```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

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.

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
<p align="center">
<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>
</p>

# Report updated dependencies

This Github Actions runs on changes to PR requests to detect and report changes made to dependencies.
Dependency lookups, change detections and fetching of release notes are all done by [Renovate Bot](https://github.com/renovatebot/renovate)

```yml
name: 'build-test'
on:
pull_request:

jobs:
report-updated-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: AurorNZ/report-updated-dependencies@v1
```

or run conditionally

```yml
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
report-updated-dependencies:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: AurorNZ/report-updated-dependencies@v1
```

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:

```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

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.

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)


## Debugging
- Create a pull request, ideally with commits that update dependencies
- 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.
- Put the `event.json` file into the root of this repository
- Add the following code to `.env` file
```
GITHUB_EVENT_NAME=pull_request
GITHUB_EVENT_PATH=event.json
INPUT_TOKEN=<YOUR_GITHUB_TOKEN>
```
- Hit F5 in VSCode to start debugging
17 changes: 11 additions & 6 deletions src/getRunContext.ts
Expand Up @@ -16,15 +16,20 @@ export function getRunContext(): RunContext {
case 'pull_request': {
const pullRequestPayload = context.payload

const {
pull_request: {number: pullRequestNumber} = {}
} = pullRequestPayload
const {pull_request} = pullRequestPayload
if (!pull_request) {
throw new Error(
'Github event is malformed, expected pull_request context on pull_request event'
)
}

const {number: pullRequestNumber, merge_commit_sha} = pull_request

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

return {
baseRef: pushPayload.before,
headRef: context.sha,
headRef: pushPayload.after,
repo
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Expand Up @@ -84,6 +84,7 @@ async function run(): Promise<void> {

const commentBody = getPrCommentBody(updatedDependencies)

core.info(`Ensuring the PR comment is up to date`)
await upsertPrComment(
github,
repo,
Expand Down

0 comments on commit 14280ef

Please sign in to comment.