BCDevOps / nrdk

Natural Resource Ministries Developer/Deployment Kit
3 stars 4 forks source link

github actions/checks failing when building from PR #31

Closed cvarjao closed 3 years ago

cvarjao commented 3 years ago

By default pull request checkouts will checkout the merge ref (no the head ref) which means it creates a detached branch that may be conflicting with the test cases.

Examples: From push event:

Checking out the ref
  /usr/bin/git checkout --progress --force -B ONETEAM-737-0 refs/remotes/origin/ONETEAM-737-0
  Switched to a new branch 'ONETEAM-737-0'
  Branch 'ONETEAM-737-0' set up to track remote branch 'ONETEAM-737-0' from 'origin'.
/usr/bin/git log -1 --format='%H'
'2e618b250ff81f2b011efb953a11457656df5836'

from pull_request event:

Checking out the ref
  /usr/bin/git checkout --progress --force refs/remotes/pull/28/merge
  Note: switching to 'refs/remotes/pull/28/merge'.

  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by switching back to a branch.

  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -c with the switch command. Example:

    git switch -c <new-branch-name>

  Or undo this operation with:

    git switch -

  Turn off this advice by setting config variable advice.detachedHead to false

  HEAD is now at 1439e2e Merge 2e618b250ff81f2b011efb953a11457656df5836 into 3aa9fb8db516d5924b96c13907a4d77b6506f205
/usr/bin/git log -1 --format='%H'
'1439e2e1cc69838e608523ab91cc10b9d270073c'
DerekRoberts commented 3 years ago

GitHub Actions from outside forks are still failing. Issue reopened.

DerekRoberts commented 3 years ago

npm run test passes, but excludes all *.test.ts. Including those we have the following.

Failing on detached head only:

Failing on branch and detached head:

Passing:

for i in `find test/ -type f -iname *.js -o -iname *.ts ! -name build.* ! -name on-jira-event.* ! -name jira-rfd.* ! -name rfd-helper.*`; do npm run mocha -- $i; done
DerekRoberts commented 3 years ago

build.test.js testing command:

nrdk build --config-script test/commands/build.config.js --build-script test/commands/build.build.js

Detached head:

Starting @bcgov/nrdk/0.1.0-rc.91 linux-x64 node-v14.15.4
info: Applying default value for git.url {"category":"OnJiraIssue","timestamp":"2021-02-23T20:27:07.135Z"}
info: Applying default value for git.remote.url {"category":"OnJiraIssue","timestamp":"2021-02-23T20:27:07.192Z"}
info: Applying default value for git.branch.name {"category":"OnJiraIssue","timestamp":"2021-02-23T20:27:07.193Z"}
info: Applying default value for git.branch.merge {"category":"OnJiraIssue","timestamp":"2021-02-23T20:27:07.195Z"}
info: Applying default value for git.change.target {"category":"OnJiraIssue","timestamp":"2021-02-23T20:27:07.196Z"}

Branch:

Starting @bcgov/nrdk/0.1.0-rc.91 linux-x64 node-v14.15.4
info: Applying default value for git.url {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.289Z"}
info: Applying default value for git.remote.url {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.339Z"}
info: Applying default value for git.branch.name {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.341Z"}
info: Applying default value for git.branch.merge {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.343Z"}
info: Applying default value for git.change.target {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.344Z"}
info: Applying default value for build-script {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.351Z"}
info: Applying default value for deploy-script {"category":"OnJiraIssue","timestamp":"2021-02-23T20:30:30.352Z"}
--config-script=test/commands/build.config.js --build-script=test/commands/build.build.js --git.remote.name=origin --dev-mode=false --rfc-validation=true --git.url=git@github.com:bcdevops/nrdk.git --git.remote.url=git@github.com:bcdevops/nrdk.git --git.branch.name=master --git.branch.merge=master --git.change.target=master --deploy-script=.pipeline/lib/deploy
Build started
Build finished

The missing output, triggering the failure, looks to be in test/commands/build.build.js:

const MyBuilder = class {
  build() {
    console.log('Build started')
    console.log('Build finished')
  }
}
module.exports = async settings => {
  await new MyBuilder(settings).build()
}