From 14280efddce869564536c8fac21aa32f50891d1b Mon Sep 17 00:00:00 2001 From: Daniil Samoylov Date: Wed, 3 May 2023 11:13:49 +1200 Subject: [PATCH] Describe a way of debugging this action --- .github/workflows/test.yml | 71 +++++++++++--------- README.md | 133 ++++++++++++++++++++----------------- src/getRunContext.ts | 17 +++-- src/main.ts | 1 + 4 files changed, 124 insertions(+), 98 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13c2104..f2f5c08 100644 --- a/.github/workflows/test.yml +++ b/.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: ./ diff --git a/README.md b/README.md index 2d6cca1..762b7ca 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,73 @@ -

- report-updated-dependencies status -

- -# 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) +

+ report-updated-dependencies status +

+ +# 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= + ``` +- Hit F5 in VSCode to start debugging \ No newline at end of file diff --git a/src/getRunContext.ts b/src/getRunContext.ts index 48c0c31..f6564f0 100644 --- a/src/getRunContext.ts +++ b/src/getRunContext.ts @@ -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 } @@ -35,7 +40,7 @@ export function getRunContext(): RunContext { return { baseRef: pushPayload.before, - headRef: context.sha, + headRef: pushPayload.after, repo } } diff --git a/src/main.ts b/src/main.ts index 22fb3b7..19892d7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -84,6 +84,7 @@ async function run(): Promise { const commentBody = getPrCommentBody(updatedDependencies) + core.info(`Ensuring the PR comment is up to date`) await upsertPrComment( github, repo,